git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tree_entry_interesting: Only recurse when the pathspec is a leading path component

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2009, 04:32 UTC
Message-ID
<7vbprfn0ai.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090331150501.GA11446@atjola.homenet>
Björn Steinbrink <B.Steinbrink@gmx.de> writes:
Show 9 quoted lines
> Previously the code did a simple prefix match, which means that it
> treated for example "foo/" as a subdirectory of "f".
>
> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
> ---
> I'm not exactly happy with the commit message, but that's the best I
> could come up with. Probably shows how little I know about that code :-/
> The test suite still passes and I'll try to provide a new testcase
> tonight or tommorow.
I'm planning to queue this.
From: Björn Steinbrink <B.Steinbrink@gmx.de>
Date: Tue, 31 Mar 2009 17:05:01 +0200
Subject: [PATCH] tree_entry_interesting: a pathspec only matches at directory boundary

Previously the code did a simple prefix match, which means that a path in a directory "frotz/" would have matched with pathspec "f".

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t4010-diff-pathspec.sh |    8 ++++++++
 tree-diff.c              |   12 +++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh
index ad3d9e4..4c4c8b1 100755
--- a/t/t4010-diff-pathspec.sh
+++ b/t/t4010-diff-pathspec.sh
@@ -62,4 +62,12 @@ test_expect_success \
     'git diff-index --cached $tree -- file0/ >current &&
      compare_diff_raw current expected'
 
+test_expect_success 'diff-tree pathspec' '
+	tree2=$(git write-tree) &&
+	echo "$tree2" &&
+	git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
+	>expected &&
+	test_cmp expected current
+'
+
 test_done
diff --git a/tree-diff.c b/tree-diff.c
index 9f67af6..b05d0f4 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -118,10 +118,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 				continue;
 
 			/*
-			 * The base is a subdirectory of a path which
-			 * was specified, so all of them are interesting.
+			 * If the base is a subdirectory of a path which
+			 * was specified, all of them are interesting.
 			 */
-			return 2;
+			if (!matchlen ||
+			    base[matchlen] == '/' ||
+			    match[matchlen - 1] == '/')
+				return 2;
+
+			/* Just a random prefix match */
+			continue;
 		}
 
 		/* Does the base match? */
Previous: Björn SteinbrinkNext: Junio C Hamano
Message 21 of 28 in “svn clone Checksum mismatch question”
  1. Gilbert LiddellMar 26, 2009
  2. Björn SteinbrinkMar 26, 2009
  3. Gilbert LiddellMar 26, 2009
  4. Sverre RabbelierMar 26, 2009
  5. Gilbert LiddellMar 26, 2009
  6. Johannes SchindelinMar 26, 2009
  7. Anton GyllenbergMar 26, 2009
  8. Anton GyllenbergMar 27, 2009
  9. Eric WongMar 29, 2009
  10. git-svn: fix ls-tree usage with dash-prefixed pathsEric Wong, Mar 29, 2009
  11. Junio C HamanoMar 29, 2009
  12. Eric WongMar 29, 2009
  13. Junio C HamanoMar 30, 2009
  14. Eric WongMar 30, 2009
  15. Junio C HamanoMar 30, 2009
  16. Eric WongMar 30, 2009
  17. Björn SteinbrinkMar 31, 2009
  18. Björn SteinbrinkMar 31, 2009
  19. Björn SteinbrinkMar 31, 2009
  20. tree_entry_interesting: Only recurse when the pathspec is a leading path componentBjörn Steinbrink, Mar 31, 2009
  21. Junio C HamanoApr 2, 2009
  22. match_tree_entry(): a pathspec only matches at directory boundariesJunio C Hamano, Apr 2, 2009
  23. Linus TorvaldsApr 2, 2009
  24. Björn SteinbrinkApr 2, 2009
  25. Junio C HamanoApr 3, 2009
  26. Björn SteinbrinkMar 30, 2009
  27. Anton GyllenbergMar 30, 2009
  28. Peter HarrisMar 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.