{"thread":{"id":"41360","subject":"git diff HEAD^(255) fails","startedAt":"2016-02-06T21:56:46Z","lastAt":"2016-02-23T20:58:07Z","messageCount":6,"participants":["Ole Tange","Nguyễn Thái Ngọc Duy","Johannes Schindelin","Junio C Hamano","Kevin Daudt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"277668","messageId":"CA+4vN7w2=JWusWDhhGNzAkJbE-s44G4WoXdvf26yzvtYfpktfQ@mail.gmail.com","threadId":"41360","inReplyTo":null,"subject":"git diff HEAD^(255) fails","fromName":"Ole Tange","fromEmail":"ole@tange.dk","sentAt":"2016-02-06T21:56:46Z","receivedAt":"2016-02-06T21:56:46Z","isPatch":false,"sender":{"key":"ole@tange.dk","avatar":null},"body":"git diff first looks for a file, then looks if it is a reference to a\nrevision. If the file fails due to being too long, the diff fails:\n\n$ git init\n$ git diff 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'\nHEAD\nfatal: failed to stat\n'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^':\nFile name too long\n\nIf file name too long it should just try to see if it is a reference\nto a revision.\n\n\n/Ole\n"},{"id":"277670","messageId":"1454800992-15953-1-git-send-email-pclouds@gmail.com","threadId":"41360","inReplyTo":"CA+4vN7w2=JWusWDhhGNzAkJbE-s44G4WoXdvf26yzvtYfpktfQ@mail.gmail.com","subject":"[PATCH] setup.c: make check_filename() return 0 on ENAMETOOLONG","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2016-02-06T23:23:12Z","receivedAt":"2016-02-06T23:23:12Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Noticed-by: Ole Tange <ole@tange.dk>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n On Sun, Feb 7, 2016 at 4:56 AM, Ole Tange <ole@tange.dk> wrote:\n > If file name too long it should just try to see if it is a reference\n > to a revision.\n\n Looks easy enough to fix.\n\n setup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 2c4b22c..ab8f85d 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg)\n \t\tname = arg;\n \tif (!lstat(name, &st))\n \t\treturn 1; /* file exists */\n-\tif (errno == ENOENT || errno == ENOTDIR)\n+\tif (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG)\n \t\treturn 0; /* file does not exist */\n \tdie_errno(\"failed to stat '%s'\", arg);\n }\n-- \n2.7.0.377.g4cd97dd\n"},{"id":"277690","messageId":"alpine.DEB.2.20.1602071317330.2964@virtualbox","threadId":"41360","inReplyTo":"1454800992-15953-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] setup.c: make check_filename() return 0 on ENAMETOOLONG","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-02-07T12:23:49Z","receivedAt":"2016-02-07T12:23:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Sun, 7 Feb 2016, Nguyễn Thái Ngọc Duy wrote:\n\n> Noticed-by: Ole Tange <ole@tange.dk>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  On Sun, Feb 7, 2016 at 4:56 AM, Ole Tange <ole@tange.dk> wrote:\n>  > If file name too long it should just try to see if it is a reference\n>  > to a revision.\n> \n>  Looks easy enough to fix.\n\nMaybe with a little bit more informative commit message? ;-)\n\nSomething like\n\n\tAvoid interpreting too-long parameter as file name\n\n\tEven if it is easier to write HEAD~2000, it is legal to write\n\tHEAD^^^... (repeats \"^\" 2000 times in total). However, such a\n\tstring is too long to be a legal filename (and on Windows, by\n\tdefault even much, much shorter strings are still illegal\n\tbecause they exceed MAX_PATH).\n\n\tTherefore, if the check_filename() function encounters too long\n\ta command-line parameter, it should interpet the error code\n\tENAMETOOLONG as a strong hint that this is not a file name\n\tinstead of dying with an error message.\n\n\tNoticed-by: ...\n\nWhat do you think?\nDscho"},{"id":"277712","messageId":"1454908588-22475-1-git-send-email-pclouds@gmail.com","threadId":"41360","inReplyTo":"alpine.DEB.2.20.1602071317330.2964@virtualbox","subject":"[PATCH] Avoid interpreting too-long parameter as file name","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2016-02-08T05:16:28Z","receivedAt":"2016-02-08T05:16:28Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Even if it is easier to write HEAD~2000, it is legal to write\nHEAD^^^... (repeats \"^\" 2000 times in total). However, such a string is\ntoo long to be a legal filename (and on Windows, by default even much,\nmuch shorter strings are still illegal because they exceed MAX_PATH).\n\nTherefore, if the check_filename() function encounters too long a\ncommand-line parameter, it should interpet the error code ENAMETOOLONG\nas a strong hint that this is not a file name instead of dying with an\nerror message.\n\nNoticed-by: Ole Tange <ole@tange.dk>\nHelped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Note, git grep ENOENT.*ENOTDIR reveals a couple more matches, but I\n didn't check if they should receive the same treatment.\n\n Another option is just use file_exists() here instead, but I guess\n that's too relaxing.\n\n setup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 2c4b22c..ab8f85d 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg)\n \t\tname = arg;\n \tif (!lstat(name, &st))\n \t\treturn 1; /* file exists */\n-\tif (errno == ENOENT || errno == ENOTDIR)\n+\tif (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG)\n \t\treturn 0; /* file does not exist */\n \tdie_errno(\"failed to stat '%s'\", arg);\n }\n-- \n2.7.0.377.g4cd97dd\n"},{"id":"277766","messageId":"xmqq4mdj7ww4.fsf@gitster.mtv.corp.google.com","threadId":"41360","inReplyTo":"1454908588-22475-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] Avoid interpreting too-long parameter as file name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-08T20:46:51Z","receivedAt":"2016-02-08T20:46:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Even if it is easier to write HEAD~2000, it is legal to write\n> HEAD^^^... (repeats \"^\" 2000 times in total). However, such a string is\n> too long to be a legal filename (and on Windows, by default even much,\n> much shorter strings are still illegal because they exceed MAX_PATH).\n>\n> Therefore, if the check_filename() function encounters too long a\n> command-line parameter, it should interpet the error code ENAMETOOLONG\n> as a strong hint that this is not a file name instead of dying with an\n> error message.\n>\n> Noticed-by: Ole Tange <ole@tange.dk>\n> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n\nWhile I think it is a good thing to try solving, i.e. it would be\nnicer to the user if \"git foo HEAD^^^^...\" can be spelled without\nneeding a \"--\" disambiguation, I am not sure this patch solves it at\nthe right level.  The log message is unclear if the patch author\neven thought about ramifications of the callers not involved in the\ncase written in it.\n\nFor example, verify_filename() calls this function, saying \"This\nstring must name a file and otherwise I want you to die\".\n\nThere is a direct call to check_filename() in builtin/checkout.c; it\nis unclear how it would interact with this change, either.\n"},{"id":"279067","messageId":"20160223205807.GA15324@ikke.info","threadId":"41360","inReplyTo":"CA+4vN7w2=JWusWDhhGNzAkJbE-s44G4WoXdvf26yzvtYfpktfQ@mail.gmail.com","subject":"Re: git diff HEAD^(255) fails","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2016-02-23T20:58:07Z","receivedAt":"2016-02-23T20:58:07Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Sat, Feb 06, 2016 at 10:56:46PM +0100, Ole Tange wrote:\n> git diff first looks for a file, then looks if it is a reference to a\n> revision. If the file fails due to being too long, the diff fails:\n> \n> $ git init\n> $ git diff 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'\n> HEAD\n> fatal: failed to stat\n> 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^':\n> File name too long\n> \n> If file name too long it should just try to see if it is a reference\n> to a revision.\n> \n\nIs there a reason you are repeating 255 \"^\" instead of using HEAD~255?\n"}]}