git diff HEAD^(255) fails
git diff first looks for a file, then looks if it is a reference to a revision. If the file fails due to being too long, the diff fails:
$ git init $ git diff 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^' HEAD fatal: failed to stat 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^': File name too long
If file name too long it should just try to see if it is a reference to a revision.
/Ole
PATCH 1/1 setup.c: make check_filename() return 0 on ENAMETOOLONG
---
Quoted 2 lines · Ole Tange
If file name too long it should just try to see if it is a reference to a revision.
Looks easy enough to fix.
setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
setup.c +1 -1
@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg) name = arg;if (!lstat (name, &st))return 1 ;/* file exists */ -if (errno ==ENOENT || errno ==ENOTDIR ) +if (errno ==ENOENT || errno ==ENOTDIR || errno ==ENAMETOOLONG )return 0 ;/* file does not exist */ die_errno ("failed to stat '%s'" , arg); }
Signature · 1 line
2.7.0.377.g4cd97dd
Re: [PATCH] setup.c: make check_filename() return 0 on ENAMETOOLONG
Hi Duy,
Quoted 8 lines · Nguyễn Thái Ngọc Duy
Noticed-by Ole Tange <[email protected]>Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
Quoted 2 lines · Ole Tange
If file name too long it should just try to see if it is a reference to a revision.
Looks easy enough to fix.
Maybe with a little bit more informative commit message? ;-)
Something like
Avoid interpreting too-long parameter as file name
Even if it is easier to write HEAD~2000, it is legal to write HEAD^^^... (repeats "^" 2000 times in total). However, such a string is too long to be a legal filename (and on Windows, by default even much, much shorter strings are still illegal because they exceed MAX_PATH).
Therefore, if the check_filename() function encounters too long a command-line parameter, it should interpet the error code ENAMETOOLONG as a strong hint that this is not a file name instead of dying with an error message.
Noticed-by: ...
What do you think?
Dscho
PATCH 1/1 Avoid interpreting too-long parameter as file name
Even if it is easier to write HEAD~2000, it is legal to write HEAD^^^... (repeats "^" 2000 times in total). However, such a string is too long to be a legal filename (and on Windows, by default even much, much shorter strings are still illegal because they exceed MAX_PATH).
Therefore, if the check_filename() function encounters too long a command-line parameter, it should interpet the error code ENAMETOOLONG as a strong hint that this is not a file name instead of dying with an error message.
---
Note, git grep ENOENT.*ENOTDIR reveals a couple more matches, but I didn't check if they should receive the same treatment.
Another option is just use file_exists() here instead, but I guess that's too relaxing.
setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
setup.c +1 -1
@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg) name = arg;if (!lstat (name, &st))return 1 ;/* file exists */ -if (errno ==ENOENT || errno ==ENOTDIR ) +if (errno ==ENOENT || errno ==ENOTDIR || errno ==ENAMETOOLONG )return 0 ;/* file does not exist */ die_errno ("failed to stat '%s'" , arg); }
Signature · 1 line
2.7.0.377.g4cd97dd
Re: [PATCH] Avoid interpreting too-long parameter as file name
Quoted 10 lines · Nguyễn Thái Ngọc Duy
Even if it is easier to write HEAD~2000, it is legal to write HEAD^^^... (repeats "^" 2000 times in total). However, such a string is too long to be a legal filename (and on Windows, by default even much, much shorter strings are still illegal because they exceed
MAX_PATH).Therefore, if the
check_filename()function encounters too long a command-line parameter, it should interpet the error code ENAMETOOLONG as a strong hint that this is not a file name instead of dying with an error message.
Quoted 4 lines
Noticed-by Ole Tange <[email protected]>Helped-by Johannes Schindelin <[email protected]>Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
While I think it is a good thing to try solving, i.e. it would be nicer to the user if "git foo HEAD^^^^..." can be spelled without needing a "--" disambiguation, I am not sure this patch solves it at the right level. The log message is unclear if the patch author even thought about ramifications of the callers not involved in the case written in it.
For example, verify_filename() calls this function, saying "This string must name a file and otherwise I want you to die".
There is a direct call to check_filename() in builtin/checkout.c; it is unclear how it would interact with this change, either.
Quoted 10 lines · Ole Tange
git diff first looks for a file, then looks if it is a reference to a revision. If the file fails due to being too long, the diff fails:
$ git init $ git diff 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^' HEAD fatal: failed to stat 'HEAD^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^': File name too long
Quoted 3 lines
If file name too long it should just try to see if it is a reference to a revision.
Is there a reason you are repeating 255 "^" instead of using HEAD~255?