All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: davi.reis@gmail.com, git@vger.kernel.org
Subject: [PATCH 2/2] ls-tree $di $dir: do not mistakenly recurse into directories
Date: Sat, 11 Sep 2010 12:00:19 -0700	[thread overview]
Message-ID: <7vd3skf6m4.fsf_-_@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vhbhwf6q5.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Sat\, 11 Sep 2010 11\:57\:54 -0700")

When applying two pathspecs, one of which is named as a prefix to the
other, we mistakenly recursed into the shorter one.

Noticed and fixed by David Reis.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

  Junio C Hamano <gitster@pobox.com> writes:

  > Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
  >
  >> That's so close to a real test-case...
  >
  > Let's do this.
  >
  >  * t3101 seems somewhat stale; fix the style and add a few missing " &&"
  >    cascades as a preparatory patch.
  >
  >  * Add the "mistaken prefix computation causes unwarranted recursion" fix
  >    with a test.
  >
  > Here is the first one in such a series.

  and here is the second one.

 builtin/ls-tree.c          |    2 ++
 t/t3101-ls-tree-dirname.sh |   20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index dc86b0d..a818756 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] && spec[len] != '/')
+			continue;
 		if (memcmp(pathname, spec, len))
 			continue;
 		return 1;
diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 026f9f8..ed8160c 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -15,6 +15,7 @@ This test runs git ls-tree with the following in a tree.
     path2/1.txt        - a file in a directory
     path3/1.txt        - a file in a directory
     path3/2.txt        - a file in a directory
+    path30/3.txt       - a file in a directory
 
 Test the handling of mulitple directories which have matching file
 entries.  Also test odd filename and missing entries handling.
@@ -24,7 +25,7 @@ entries.  Also test odd filename and missing entries handling.
 test_expect_success 'setup' '
 	echo 111 >1.txt &&
 	echo 222 >2.txt &&
-	mkdir path0 path0/a path0/a/b path0/a/b/c &&
+	mkdir path0 path0/a path0/a/b path0/a/b/c path30 &&
 	echo 111 >path0/a/b/c/1.txt &&
 	mkdir path1 path1/b path1/b/c &&
 	echo 111 >path1/b/c/1.txt &&
@@ -33,6 +34,7 @@ test_expect_success 'setup' '
 	mkdir path3 &&
 	echo 111 >path3/1.txt &&
 	echo 222 >path3/2.txt &&
+	echo 333 >path30/3.txt &&
 	find *.txt path* \( -type f -o -type l \) -print |
 	xargs git update-index --add &&
 	tree=`git write-tree` &&
@@ -53,6 +55,7 @@ test_expect_success 'ls-tree plain' '
 040000 tree X	path1
 040000 tree X	path2
 040000 tree X	path3
+040000 tree X	path30
 EOF
 	test_output
 '
@@ -68,6 +71,7 @@ test_expect_success 'ls-tree recursive' '
 100644 blob X	path2/1.txt
 100644 blob X	path3/1.txt
 100644 blob X	path3/2.txt
+100644 blob X	path30/3.txt
 EOF
 	test_output
 '
@@ -164,6 +168,7 @@ test_expect_success 'ls-tree --full-tree' '
 040000 tree X	path1
 040000 tree X	path2
 040000 tree X	path3
+040000 tree X	path30
 EOF
 	test_output
 '
@@ -181,6 +186,7 @@ test_expect_success 'ls-tree --full-tree -r' '
 100644 blob X	path2/1.txt
 100644 blob X	path3/1.txt
 100644 blob X	path3/2.txt
+100644 blob X	path30/3.txt
 EOF
 	test_output
 '
@@ -195,6 +201,7 @@ test_expect_success 'ls-tree --abbrev=5' '
 040000 tree X	path1
 040000 tree X	path2
 040000 tree X	path3
+040000 tree X	path30
 EOF
 	test_cmp expected check
 '
@@ -208,6 +215,7 @@ path0
 path1
 path2
 path3
+path30
 EOF
 	test_output
 '
@@ -222,6 +230,16 @@ path1/b/c/1.txt
 path2/1.txt
 path3/1.txt
 path3/2.txt
+path30/3.txt
+EOF
+	test_output
+'
+
+test_expect_success 'ls-tree with two dirnames' '
+	git ls-tree --name-only $tree path3 path30 >current &&
+	cat >expected <<\EOF &&
+path3
+path30
 EOF
 	test_output
 '
-- 
1.7.3.rc1.215.g6997c

  reply	other threads:[~2010-09-11 19:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-09  5:40 Do not let lstree output recursively when a directory whose name is a prefix of the others is given in the path list davi.reis
2010-09-09  5:40 ` [PATCH] " davi.reis
2010-09-09  6:04 ` Matthieu Moy
2010-09-09 18:26   ` Davi Reis
2010-09-09 21:22     ` Matthieu Moy
2010-09-11 18:57   ` Junio C Hamano
2010-09-11 19:00     ` Junio C Hamano [this message]
2010-09-14 21:22     ` Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vd3skf6m4.fsf_-_@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=davi.reis@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.