Do not let lstree output recursively when a directory whose name is a prefix of the others is given in the path list.

2 messages, 1 author, 2016-06-15 · open the first message on its own page

Do not let lstree output recursively when a directory whose name is a prefix of the others is given in the path list.

From: <hidden>
Date: 2016-06-15 22:49:31

Here is how to reproduce the bug:

git init
mkdir prefix && touch prefix/a && git add prefix/a
mkdir prefixdir && touch prefixdir/b && git add prefixdir/b
git commit -a -m "If -r is not given, ls-tree should not show files in subdirs."
git ls-tree --name-only HEAD prefix  # works as expected
git ls-tree --name-only HEAD prefixdir  # works as expected
git ls-tree --name-only HEAD prefix prefixdir  # shows file, not dir

The output of the last command is 

prefix/a
prefixdir

But it should be

prefix
prefixdir

The patch fixes the problem.

[PATCH] Do not let lstree output recursively when a directory whose name is a prefix of the others is given in the path list.

From: <hidden>
Date: 2016-06-15 22:49:31

From: Davi Reis <redacted>

---
 builtin/ls-tree.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index dc86b0d..fa427e2 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -52,6 +52,8 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
 		speclen = strlen(spec);
 		if (speclen <= len)
 			continue;
+		if (spec[len] != 0 && spec[len] != '/')
+			continue;
 		if (memcmp(pathname, spec, len))
 			continue;
 		return 1;
-- 
1.7.2.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help