Skip to contentSkip to conversation

Incorrect git-blame result if I use full path to file

PATCH In review Anatol Pomozov 7 participants 21 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi, all.

I just start learning git and I found a bug (but sorry if the functionality I am trying to blame as a bug not actually bug and it was made by intention)

The problem is that git-blame returns incorrect result if you use full path for files.

Here is an example script that generates repo.

#go to empty dir
git init
echo "On master" >> master.txt
git add master.txt
git commit -m "First commit"
echo "On master" >> master.txt
git commit -a -m "Second commit"
echo "On master" >> master.txt

Now lets do blame for master.txt
anatol:repo $ git blame master.txt
^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 1) On master
4e2bbde4 (Anatol Pomozov 2007-12-02 16:44:15 -0800 2) On master
00000000 (Not Committed Yet 2007-12-02 16:44:27 -0800 3) On master

It is exaclty what we expect. But lets try full path for master.txt $pwd
/personal/sources/learn/gitea/repo
$git blame /personal/sources/learn/gitea/repo/master.txt ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 1) On master ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 2) On master ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 3) On master

Now git shows that all lines in the file were changed by the first commit and that it does not true.

Signature · 1 line
anatol
#1 lore raw
Quoted 3 lines · Anatol Pomozov

I just start learning git and I found a bug (but sorry if the functionality I am trying to blame as a bug not actually bug and it was made by intention)

Some of both, I think. :)

Quoted 7 lines

It is exaclty what we expect. But lets try full path for master.txt $pwd
/personal/sources/learn/gitea/repo
$git blame /personal/sources/learn/gitea/repo/master.txt ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 1) On master ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 2) On master ^69bce74 (Anatol Pomozov 2007-12-02 16:44:07 -0800 3) On master

We talk about many git commands taking "files" or "paths" but really they are git "pathspecs", meaning a path specifier that is relative to the repository root, and which is generally used for limiting the parts of the history we are looking at.

So I think what is happening is that git-blame is looking for content from /personal/sources/..., which of course as a git pathspec doesn't match any of the files. So everything ends up being blamed on '^69bce74' (which really means "beyond where we started looking"). But of course it still finds the content to try blaming in the first place, because in that instance it treats /personal/sources/... as a file to be opened.

IOW, it's not intended for users to use absolute paths in this way. However, the results for git-blame are obviously quite confusing. It might be worth fixing, but I suspect there are many more such traps waiting in other commands. I wonder if it would make sense to reject pathspecs starting with '/' entirely, which would at least give us a saner error message (and I can't think of a time when such a pathspec would be useful)? Even more useful would be to convert /path/to/repo/file to 'file' internally.

-Peff

#2 lore raw
Quoted 7 lines · Jeff King

IOW, it's not intended for users to use absolute paths in this way. However, the results for git-blame are obviously quite confusing. It might be worth fixing, but I suspect there are many more such traps waiting in other commands. I wonder if it would make sense to reject pathspecs starting with '/' entirely, which would at least give us a saner error message (and I can't think of a time when such a pathspec would be useful)?

All correct, except...

Quoted 2 lines

Even more useful would be to convert
/path/to/repo/file to 'file' internally.

... that might help "cut & paste from file manager" people, and I think we had comment session for such a patch recently on the list.

Sorry, but I lost track of that the current status of that patch. Did it die?

#3 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 2 lines

Even more useful would be to convert
/path/to/repo/file to 'file' internally.

... that might help "cut & paste from file manager" people, and I think we had comment session for such a patch recently on the list.

Sorry, but I lost track of that the current status of that patch. Did it die?

I didn't pay attention to it originally, but I assume you mean the recent patch from Robin Rosenberg (cc'd). Looking it over, I see one obvious omission: there is no canonicalization of the paths. IOW, I think it will break in the presence of symlinks (if I specify /path/to/repo/file, /path/to is a symlink to /other/path, I think the worktree will end up as /other/path/repo, and fail a string comparison with /path/to/repo).

-Peff

#4 lore raw

måndag 03 december 2007 skrev Jeff King:

Quoted 11 lines · Junio C Hamano
Quoted 9 lines
Quoted 3 lines

Even more useful would be to convert
/path/to/repo/file to 'file' internally.

... that might help "cut & paste from file manager" people, and I think we had comment session for such a patch recently on the list.

Sorry, but I lost track of that the current status of that patch. Did it die?

Quoted 7 lines

I didn't pay attention to it originally, but I assume you mean the recent patch from Robin Rosenberg (cc'd). Looking it over, I see one obvious omission: there is no canonicalization of the paths. IOW, I think it will break in the presence of symlinks (if I specify /path/to/repo/file, /path/to is a symlink to /other/path, I think the worktree will end up as /other/path/repo, and fail a string comparison with /path/to/repo).

No it didn't die, it's just not worked on too often. I notes, among, other things that it's test cases were not correct, besides needing more tests.

Symlinks were not covered.

-- robin

#5 lore raw

PATCH 1/1 Make Git accept absolute path names for files within the work tree

This patch makes it possible to drag files and directories from a graphical browser and drop them onto a shell and feed them to common git operations without editing away the path to the root of the work tree.

---

I will not surrender to the fierce competion on this subject. Here is an update with hopefully correct test cases this time. (Linus. your code did not pass). Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design. It solves my problem and happens to solve Anatols problem (actually the same since passing absolute file names to blame is my most important use case).

-- robin

 builtin-blame.c       |    4 +-
 setup.c               |   53 +++++++++++++++++++++++
 t/t3904-abspatharg.sh |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 3 deletions(-)
 create mode 100755 t/t3904-abspatharg.sh
builtin-blame.c +1 -3
index c158d31..b905dcf 100644
@@ -1880,9 +1880,7 @@ static unsigned parse_score(const char *arg)
 
 static const char *add_prefix(const char *prefix, const char *path)
 {
-	if (!prefix || !prefix[0])
-		return path;
-	return prefix_path(prefix, strlen(prefix), path);
+	return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
 }
 
 /*
setup.c +53 -0

62 lines not on this page · raw message

t/t3904-abspatharg.sh new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
1.5.3.5.1.gb2df9
#6 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Quoted 2 lines · Robin Rosenberg

code did not pass). Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design. It solves my problem and

By design meaning "I didn't feel like implemening it because I do not personally care" or "I have some reason not to resolve symlinks"?

-Peff

#7 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Hi,

Quoted 7 lines · Jeff King
Quoted 2 lines · Robin Rosenberg

code did not pass). Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design. It solves my problem and

By design meaning "I didn't feel like implemening it because I do not personally care" or "I have some reason not to resolve symlinks"?

IMHO those symlinks would be a nice thing in some corner cases, but penalise the common case. So I tend to believe the latter. (See also Linus' message why he talks about his preference for the die() code path.)

Ciao,
Dscho

#8 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

tisdag 04 december 2007 skrev Johannes Schindelin:

Quoted 9 lines

Hi,

Quoted 5 lines · Jeff King
Quoted 2 lines · Robin Rosenberg

code did not pass). Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design. It solves my problem and

Quoted 6 lines
Quoted 2 lines

By design meaning "I didn't feel like implemening it because I do not personally care" or "I have some reason not to resolve symlinks"?

IMHO those symlinks would be a nice thing in some corner cases, but penalise the common case. So I tend to believe the latter. (See also Linus' message why he talks about his preference for the die() code path.)

Actually the forme.... I don't mind it being fixed if it doesn't cost too much.

-- robin

#9 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Hi,

Quoted 14 lines · Robin Rosenberg

tisdag 04 december 2007 skrev Johannes Schindelin:

Quoted 12 lines · Jeff King
Quoted 10 lines · Robin Rosenberg
Quoted 4 lines

code did not pass). Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design. It solves my problem and

By design meaning "I didn't feel like implemening it because I do not personally care" or "I have some reason not to resolve symlinks"?

Quoted 7 lines
Quoted 4 lines

IMHO those symlinks would be a nice thing in some corner cases, but penalise the common case. So I tend to believe the latter. (See also Linus' message why he talks about his preference for the die() code path.)

Actually the forme.... I don't mind it being fixed if it doesn't cost too much.

I do remember the hassles I went through with get_relative_cwd() until I broke down and used chdir() two times (ugly). So the latter reason is good enough that you do not even have to admit to the former reason ;-)

Ciao,
Dscho

#10 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Quoted 3 lines · Johannes Schindelin

I do remember the hassles I went through with get_relative_cwd() until I broke down and used chdir() two times (ugly).

It really is a pretty heavy and complex operation in UNIX in general (and open to various races too), which is why I'd generally suggest avoiding it if you at all can.

The sad(?) part is, it's fairly trivial to do inside the Linux kernel (but probably not in other operating systems - it's only because of our superior dcache that we could do it). So a special system call would be no problem at all. But obviously very unportable indeed.

Linus

#11 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Quoted 6 lines · Linus Torvalds
Quoted 2 lines

I do remember the hassles I went through with get_relative_cwd() until I broke down and used chdir() two times (ugly).

It really is a pretty heavy and complex operation in UNIX in general (and open to various races too), which is why I'd generally suggest avoiding it if you at all can.

It is more expensive, though we will be doing it once per user-supplied pathspec, so I don't know that it will actually have an impact.

I am concerned that not supporting symlinks will make this feature unusably annoying for some users. I used to have a home directory that had a symlink in it, and I frequently ran into these sorts of path comparison issues ($HOME was /home/peff, so typing ~/repo/file pointed there, but /home was a symlink to /mnt/data/home, so any routines that normalize the cwd used /mnt/data/home/repo, and the two never matched up).

Hrm. Looks like somebody has already helpfully implemented make_absolute_path, so it would just require calling that on each argument. Something like this on top of Robin's patch:

setup.c +2 -1
index 4ee8024..e76c83c 100644
@@ -58,7 +58,8 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 {
 	const char *orig = path;
 	if (is_absolute_path(path))
-		path = strip_work_tree_path(prefix, len, path);
+		path = strip_work_tree_path(prefix, len,
+				xstrdup(make_absolute_path(path)));
 
 	for (;;) {
 		char c;

-Peff

#12 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Quoted 3 lines · Jeff King

It is more expensive, though we will be doing it once per user-supplied pathspec, so I don't know that it will actually have an impact.

Well, I'm more worried about just bugs, actually.

Doing this right is actually rather hard. For example, our current "make_absolute_path()" is simply not very good, and it's almost impossible to *make* it very good.

Why? It relies on being able to get the current cwd, which isn't always even possible on all systems. What about unreadable directories? What about just so *deep* directories, that the cwd doesn't fit in the 1kB allocated for it? Both do happen (people use executable but non-readable directories for security sometimes). I'm also almost certain that you can confuse it by renaming directories while that thing is running, etc etc.

IOW, that whole thing is simply a bug waiting to happen. The fact that it apparently *always* runs whether needed or not just seems to make it worse (ie if we already know our cwd, and the absolute path we have already has that as a prefix, just strip it off, don't try to do anything complex, and leave the complex and fragile cases for the odd-ball when the simple approach doesn't work)

Linus

#13 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

Quoted 6 lines · Linus Torvalds

IOW, that whole thing is simply a bug waiting to happen. The fact that it apparently *always* runs whether needed or not just seems to make it worse (ie if we already know our cwd, and the absolute path we have already has that as a prefix, just strip it off, don't try to do anything complex, and leave the complex and fragile cases for the odd-ball when the simple approach doesn't work)

Fair enough. Something like this then? It gets called only as a last-ditch (though I think the 'return path' should simply be a die -- what is the point of getting a pathspec that isn't in the repo?).

---

setup.c +7 -3
index 4ee8024..fbb956e 100644
@@ -5,13 +5,17 @@ static int inside_git_dir = -1;
 static int inside_work_tree = -1;
 
 static
-const char *strip_work_tree_path(const char *prefix, int len, const char *path)
+const char *strip_work_tree_path(const char *prefix, int len, const char *path,
+		int canonicalized)
 {
 	const char *work_tree = get_git_work_tree();
 	int n = strlen(work_tree);
 
 	if (strncmp(path, work_tree, n))
-		return path;
+		return canonicalized ?
+			path :
+			strip_work_tree_path(prefix, len,
+					xstrdup(make_absolute_path(path)), 1);
 
 	if (!prefix && !path[n])
 		return path + n;
@@ -58,7 +62,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 {
 	const char *orig = path;
 	if (is_absolute_path(path))
-		path = strip_work_tree_path(prefix, len, path);
+		path = strip_work_tree_path(prefix, len, path, 0);
 
 	for (;;) {
 		char c;
#14 lore raw

Re: [PATCH] Make Git accept absolute path names for files within the work tree

In reply to Robin Rosenberg
Quoted 2 lines · Robin Rosenberg

I will not surrender to the fierce competion on this subject. Here is an update with hopefully correct test cases this time.

Yay, that's the spirit!

Quoted 2 lines

... Like Linus, this code does not resolve symlinks, but I forgot to state that it is by design.

Perhaps state it in the commit log message?

builtin-blame.c static unsigned parse_score(const char *arg) · line 1884

Quoted 4 lines

static const char *add_prefix(const char *prefix, const char *path) {

builtin-blame.c +1 -0
+	return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
 }

Ok; prefix_path can get NULL prefix (not complaining; just a reminder in the following discussion).

setup.c line 8

Quoted 10 lines
setup.c +2 -0
index 2c7b5cb..1f0ec79 100644
@@ -4,9 +4,62 @@
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
 
+static
+const char *strip_work_tree_path(const char *prefix, int len, const char *path)

Style. "static" not on its own line.

setup.c line 11

Quoted 3 lines
setup.c +3 -0
+{
+	const char *work_tree = get_git_work_tree();
+	int n = strlen(work_tree);

Preconditions.

* prefix could be NULL or path to the subdirectory the user's non-absolute path should be relative to, expressed as a relative path to the top of the work tree, including a trailing slash. len is the length of the prefix string.

* path was determined by the caller to be absolute.

* It is assumed that get_git_work_tree() always gives absolute path, and without trailing slash.

* Does prefix always NULL if we are at the top, and never "", I wonder. But lets assume that, too.

setup.c line 13

Quoted 2 lines
setup.c +2 -0
+	if (strncmp(path, work_tree, n))
+		return path;

If the given path is outside the work tree, return absolute as-is. After this point we know path matches the work tree

setup.c line 15

Quoted 2 lines
setup.c +2 -0
+	if (!prefix && !path[n])
+		return path + n;

If we are at the top of the work tree and path names the top of the work tree, then we return "".

setup.c line 21

Quoted 3 lines
setup.c +3 -0
+	if (!prefix) {
+		if (path[n] == '/')
+			return path + n + 1;

If we are at the top of the work tree and the path names the top of the work tree followed by a slash and then something, that is a path inside the work tree. Return relative to the top of the work tree.

setup.c line 27

Quoted 6 lines
setup.c +6 -0
+		else
+			if (path[n])
+				return path;
+			else
+				return path + n;
+	}

Style. "else if" would give you shallower indentation. We know path[n] was not slash, and if it is not NUL then path is not inside the work tree but is a neighbour (e.g. worktree is /a/b and path is /a/bc). Return absolute. Otherwise the path names the top of the work tree itself so we return "".

Now at this point, we know we are in a subdirectory, because the above if (!prefix) part always return. So the test for prefix here is unnecessary.

setup.c line 26

Quoted 2 lines
setup.c +2 -0
+	if (prefix && !path[n])
+		return path;

If we are in a subdirectory, and path names the top of the work tree, we return it as-is (i.e. absolute). This feels a bit inconsistent with the part that follows, which tries to make things relative by using "../", doesn't it?

setup.c line 32

Quoted 1 line
setup.c +1 -0
+	if (strncmp(path + n + 1, prefix, len - 1)) {

For !prefix case we have determined path is not merely a neighbour, but we haven't checked that in this codepath. If the parameters were like this:

path = /axbc/e
work_tree = /a
n = 2
prefix = bc/
len = 3

this check says "fine, path is under prefix and we won't add ../ uplevels". You need to have

	if (path[n] != '/')
        	return path;

before this strncmp() for it to work, don't you?

In addition, by comparing (len - 1) excluding the trailing slash of prefix, I think you would let

path = /a/bcye

slip through as well. That is inside the work_tree but outside of your prefix.

setup.c line 33

Quoted 1 line
setup.c +1 -0
+		fprintf(stderr,"prefix mismatch\n");

Stray debugging fprintf.

setup.c line 36

Quoted 3 lines
setup.c +3 -0
+		char *np;
+		int i;
+		int d=0;

Style "d = 0" (and "decl after statement").

setup.c line 37

Quoted 1 line
setup.c +1 -0
+		for (i = 0; i < len; ++i)

Style. Distracts the reader by forcing him to wonder needlessly if there is a particular reason for pre-increment of i instead of the usual post-increment.

setup.c line 40

Quoted 3 lines
setup.c +3 -0
+			if (prefix[i] == '/')
+				d++;
+		np = xmalloc(strlen(path + n) + d * 3 + 1);

At this point (assuming that the above if (strncmp()) rejected the path outside the prefix correctly), we know that we would need to go d levels up to reach the top of the work tree.

setup.c line 41

Quoted 1 line
setup.c +1 -0
+		for (i=0; i < d * 3; i += 3)

Style. "i = 0".

setup.c line 43

Quoted 2 lines
setup.c +2 -0
+			strcpy(np + i, "../");
+		strcpy(np + i, path + n + 1);

As path+n+1 is relative to the work tree, this will make it relative, which is good.

setup.c line 46

Quoted 3 lines
setup.c +3 -0
+		path = np;
+		return np;
+	}

Assuming the if (strncmp()) above correctly handled the path outside prefix, we are dealing with the path that is inside prefix at this point. (len+n) is the length of the prefix directory expressed as an absolute path.

setup.c line 49

Quoted 2 lines
setup.c +2 -0
+	if (path[len + n] == '/')
+		return path + len + n + 1;

So strip the absolute prefix would make the result relative to the prefix directory. Nice.

setup.c line 52

Quoted 3 lines
setup.c +3 -0
+	else
+		if (path[len + n])
+			return path;

The same comment on "else if" applies. path[len+n] was not slash so path was not inside the prefix after all. Oops? The "if outside prefix we uplevel with ../" logic above should have handled this case and we should not be here.

setup.c line 55

Quoted 3 lines
setup.c +3 -0
+		else
+			return path + len + n;
+}

path[len+n] was NUL, which means taht the user named the prefix directory, and we return "".

Isn't this _overly_ complicated? I think what this function wants to do is:

* See if path is outside the work tree, and return absolute if so.

* Come up with the absolute path for the prefix (if NULL then that is the same as work tree) directory, without a trailing slash, and call it X.

* Is path the same as the X? If so, "" is what you want.

* Is path a prefix of the "X/"? If so strip "X/" and return.

* Find the longuest common leading directory of path and "X/" and call it "C/". Note that this is guaranteed to be inside work tree because we rejected paths outside work tree upfront.

* Count slashes between "C/" and "X/" and come up with necessary uplevel "../". Strip "C/" from path and prepend the uplevel.

#15 lore raw
In reply to Anatol Pomozov
Quoted 3 lines · Anatol Pomozov

I just start learning git and I found a bug (but sorry if the functionality I am trying to blame as a bug not actually bug and it was made by intention)

I think it is rather a sloppy error checking than a bug. It should be throwing a stone back at you when you feed it a full path, or converting it back to work tree relative path before using.

#16 lore raw
Quoted 3 lines · Junio C Hamano

I think it is rather a sloppy error checking than a bug. It should be throwing a stone back at you when you feed it a full path, or converting it back to work tree relative path before using.

I think it's not the only place. Doing "git diff /path/to/repo/file" silently produces an empty diff, even if there are changes in the file.

-Peff

#17 lore raw
In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Anatol Pomozov

I just start learning git and I found a bug (but sorry if the functionality I am trying to blame as a bug not actually bug and it was made by intention)

I think it is rather a sloppy error checking than a bug. It should be throwing a stone back at you when you feed it a full path, or converting it back to work tree relative path before using.

How about this patch?

It makes "get_pathspec()" make all the paths it returns relative, if it can. HOWEVER! I think it should actually die() if it sees an absolute path that it cannot convert (because it really cannot do anything sane about it), but I commented that out for now because that requires some test case
change: right now we actually have a few test cases for insane filename arguments, and they expect the old behaviour.

Comments? This changes behaviour subtly (and if we enable the "die(..)" logic, not-so-subtly), but I think that in any case where it changes behaviour, the new behaviour would be an improvement, and the old one would be nonsensical (ie you get *some* results with an absolute pathname, just not the ones you'd expect!)

Note the die() comment in the bad case in "make_relative()".

Linus

---
 setup.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
setup.c +33 -1
index 2c7b5cb..fadf4ee 100644
@@ -111,11 +111,26 @@ void verify_non_filename(const char *prefix, const char *arg)
 		die("'%s': %s", arg, strerror(errno));
 }
 
+static const char *make_relative(const char *file, const char *pwd, int pwdlen)
+{
+	if (strncmp(file, pwd, pwdlen))
+		goto bad;
+	if (file[pwdlen] != '/')
+		goto bad;
+	return file + pwdlen + 1;
+
+bad:
+	/* Should we die() here or just do a "return file"? */
+	/* die("pathname '%s' is not in the repository", file); */
+	return file;
+}
+
 const char **get_pathspec(const char *prefix, const char **pathspec)
 {
+	const char *pwd;
 	const char *entry = *pathspec;
 	const char **p;
-	int prefixlen;
+	int prefixlen, pwdlen;
 
 	if (!prefix && !entry)
 		return NULL;
@@ -127,9 +142,26 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
 		return spec;
 	}
 
+	pwd = NULL;
+	pwdlen = 0;
+	p = pathspec;
+	do {
+		if (*entry == '/') {
+			if (!pwd) {
+				char buffer[PATH_MAX + 1];
+				if (!getcwd(buffer, sizeof(buffer)))
+					break;
+				pwd = buffer;
+				pwdlen = strlen(buffer);
+			}
+			*p = make_relative(entry, pwd, pwdlen);
+		}
+	} while ((entry = *++p) != NULL);
+
 	/* Otherwise we have to re-write the entries.. */
 	p = pathspec;
 	prefixlen = prefix ? strlen(prefix) : 0;
+	entry = *p;
 	do {
 		*p = prefix_path(prefix, prefixlen, entry);
 	} while ((entry = *++p) != NULL);
#18 lore raw

Hi,

Quoted 7 lines · Linus Torvalds

It [the patch] makes "get_pathspec()" make all the paths it returns relative, if it can. HOWEVER! I think it should actually die() if it sees an absolute path that it cannot convert (because it really cannot do anything sane about it), but I commented that out for now because that requires some test case change: right now we actually have a few test cases for insane filename arguments, and they expect the old behaviour.

I have the slight suspicion that this could break diff --no-index. And it does not contain any symlink resolution, right?

Ciao,
Dscho

#19 lore raw
Quoted 2 lines · Johannes Schindelin

I have the slight suspicion that this could break diff --no-index.

Quite possible.

Quoted 1 line

And it does not contain any symlink resolution, right?

That's correct, and by design. If you give a path where the absolute part of the path contains some symlink that eventually gets you to the right point, you get screwed. That's part of why I'd _prefer_ to do the "die()" part, so that you get screwed with a nice error message, rather than being screwed by getting unexpected results!

Linus

#20 lore raw
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Johannes Schindelin

I have the slight suspicion that this could break diff --no-index.

Quite possible.

Side note: another issue (for the particular case that Anatol hit) is that this patch obviously only helps for commands that actually use "get_pathspec()" (usually through doing all the common argument setup stuff). So "git log" and friends work fine.

HOWEVER. "git blame" has its own argument parsing that doesn't use any of the common routines, and thus the behaviour that Anatol complained about isn't fixed at all by the patch.

I think that should be fixed by just making git blame use the standard arguments (which in turn may involve having to teach the *other* commands about the "-S <revs-file>" and "-L n,m" forms! I think those are why it does its own specialized parsing), but obviously git-blame could also be tought to just do "get_pathspec()" too.

Linus