summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9731706)
raw | patch | inline | side by side (parent: 9731706)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Mon, 23 Apr 2007 08:21:25 +0000 (10:21 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 23 Apr 2007 08:44:00 +0000 (01:44 -0700) |
The function common_prefix() is used to find the common subdirectory of
a couple of pathnames. When checking if the next pathname matches up with
the prefix, it incorrectly checked the whole path, not just the prefix
(including the slash). Thus, the expensive part of the loop was executed
always.
The other bug is more serious: if the first and the last pathname in the
list have a longer common prefix than the common prefix for _all_ pathnames
in the list, the longer one would be chosen. This bug was probably hidden
by the fact that bash's wildcard expansion sorts the results, and the code
just so happens to work with sorted input.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
a couple of pathnames. When checking if the next pathname matches up with
the prefix, it incorrectly checked the whole path, not just the prefix
(including the slash). Thus, the expensive part of the loop was executed
always.
The other bug is more serious: if the first and the last pathname in the
list have a longer common prefix than the common prefix for _all_ pathnames
in the list, the longer one would be chosen. This bug was probably hidden
by the fact that bash's wildcard expansion sorts the results, and the code
just so happens to work with sorted input.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
dir.c | patch | blob | history | |
t/t3700-add.sh | patch | blob | history |
index b48e19dc09fff7d7fb1d5b48673fe4448b69a7c3..602282bd1b198a7a0cef0707c738b4eda0d3ccef 100644 (file)
--- a/dir.c
+++ b/dir.c
prefix = slash - path + 1;
while ((next = *++pathspec) != NULL) {
int len = strlen(next);
- if (len >= prefix && !memcmp(path, next, len))
+ if (len >= prefix && !memcmp(path, next, prefix))
continue;
+ len = prefix - 1;
for (;;) {
if (!len)
return 0;
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 08e035220cfd5c2da0798eba84c779981f185b4a..ad8cc7d4ae88e2066d2f51b6a6a5a192780d5e9a 100755 (executable)
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
git-ls-files --error-unmatch d.ig/d.if d.ig/d.ig
'
+mkdir 1 1/2 1/3
+touch 1/2/a 1/3/b 1/2/c
+test_expect_success 'check correct prefix detection' '
+ git add 1/2/a 1/3/b 1/2/c
+'
+
test_done