From: Junio C Hamano <gitster@pobox.com>
To: "Björn Steinbrink" <B.Steinbrink@gmx.de>
Cc: Eric Wong <normalperson@yhbt.net>,
Anton Gyllenberg <anton@iki.fi>,
git@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH] match_tree_entry(): a pathspec only matches at directory boundaries
Date: Wed, 01 Apr 2009 21:41:31 -0700 [thread overview]
Message-ID: <7vwsa3llac.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vbprfn0ai.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Wed, 01 Apr 2009 21:32:05 -0700")
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: Junio C Hamano <gitster@pobox.com>
---
* And this is a companion patch to fix ls-tree. The test case uses a
tree that has path3/1.txt and path3/2.txt in it.
The bug Eric diagnosed and worked around in git-svn makes the current
code show these two paths when pathspec "pa" and "path3/a" are given.
The presense of "path3/a" makes the tree walker traverse down to path3
subtree (in case something that matches "a" is in there---this is a
correct behaviour), but then in that subtree, "pa" incorrectly matches
"path3/1.txt".
This logic dates back to 0ca14a5 (Start adding interfaces to read in
partial trees, 2005-07-14). I think it is just a simple oversight and
we should fix it.
t/t3101-ls-tree-dirname.sh | 6 ++++++
tree.c | 8 ++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 4dd7d12..51cb4a3 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -135,4 +135,10 @@ test_expect_success \
EOF
test_output'
+test_expect_success 'ls-tree filter is leading path match' '
+ git ls-tree $tree pa path3/a >current &&
+ >expected &&
+ test_output
+'
+
test_done
diff --git a/tree.c b/tree.c
index 03e782a..d82a047 100644
--- a/tree.c
+++ b/tree.c
@@ -60,8 +60,12 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
/* If it doesn't match, move along... */
if (strncmp(base, match, matchlen))
continue;
- /* The base is a subdirectory of a path which was specified. */
- return 1;
+ /* pathspecs match only at the directory boundaries */
+ if (!matchlen ||
+ base[matchlen] == '/' ||
+ match[matchlen - 1] == '/')
+ return 1;
+ continue;
}
/* Does the base match? */
--
1.6.2.1.483.gcc994
next prev parent reply other threads:[~2009-04-02 4:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-26 10:31 svn clone Checksum mismatch question Gilbert Liddell
2009-03-26 13:02 ` Björn Steinbrink
2009-03-26 13:28 ` Gilbert Liddell
2009-03-26 13:54 ` Sverre Rabbelier
2009-03-26 14:18 ` Gilbert Liddell
2009-03-26 14:34 ` Johannes Schindelin
2009-03-26 14:35 ` Anton Gyllenberg
2009-03-27 11:18 ` Anton Gyllenberg
2009-03-29 6:08 ` Eric Wong
2009-03-29 6:10 ` [PATCH] git-svn: fix ls-tree usage with dash-prefixed paths Eric Wong
2009-03-29 20:33 ` Junio C Hamano
2009-03-29 21:56 ` Eric Wong
2009-03-30 6:44 ` Junio C Hamano
2009-03-30 17:41 ` Eric Wong
2009-03-30 18:05 ` Junio C Hamano
2009-03-30 22:58 ` Eric Wong
2009-03-31 7:11 ` Björn Steinbrink
2009-03-31 7:31 ` Björn Steinbrink
2009-03-31 9:41 ` Björn Steinbrink
2009-03-31 15:05 ` [PATCH] tree_entry_interesting: Only recurse when the pathspec is a leading path component Björn Steinbrink
2009-04-02 4:32 ` Junio C Hamano
2009-04-02 4:41 ` Junio C Hamano [this message]
2009-04-02 16:36 ` [PATCH] match_tree_entry(): a pathspec only matches at directory boundaries Linus Torvalds
2009-04-02 11:38 ` [PATCH] tree_entry_interesting: Only recurse when the pathspec is a leading path component Björn Steinbrink
2009-04-03 16:25 ` Junio C Hamano
2009-03-30 5:28 ` [PATCH] git-svn: fix ls-tree usage with dash-prefixed paths Björn Steinbrink
2009-03-30 7:26 ` svn clone Checksum mismatch question Anton Gyllenberg
2009-03-26 14:34 ` Peter Harris
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=7vwsa3llac.fsf_-_@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=B.Steinbrink@gmx.de \
--cc=anton@iki.fi \
--cc=git@vger.kernel.org \
--cc=normalperson@yhbt.net \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).