All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 5/5] ce_path_match: drop prefix matching in favor of match_pathspec
Date: Mon, 20 Sep 2010 09:30:00 +1000	[thread overview]
Message-ID: <1284939000-16907-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1284939000-16907-1-git-send-email-pclouds@gmail.com>

ce_path_match() and tree_entry_interesting() are two functions that do
entry filtering when traversing trees. Now that
tree_entry_interesting() understands wildcard, ce_path_match() can
just use match_pathspec() to also understand wildcard.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 read-cache.c             |   25 +------------------------
 t/t4010-diff-pathspec.sh |    9 +++++++++
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 918a90c..c67d9e0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -685,30 +685,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
 
 int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
 {
-	const char *match, *name;
-	const char **p;
-	int len;
-
-	if (!pathspec || !pathspec->nr)
-		return 1;
-
-	len = ce_namelen(ce);
-	name = ce->name;
-	p = pathspec->raw;
-	while ((match = *p++) != NULL) {
-		int matchlen = strlen(match);
-		if (matchlen > len)
-			continue;
-		if (memcmp(name, match, matchlen))
-			continue;
-		if (matchlen && name[matchlen-1] == '/')
-			return 1;
-		if (name[matchlen] == '/' || !name[matchlen])
-			return 1;
-		if (!matchlen)
-			return 1;
-	}
-	return 0;
+	return match_pathspec(pathspec->raw, ce->name, ce_namelen(ce), 0, NULL) > 0;
 }
 
 /*
diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh
index 4b120f8..d50fd2d 100755
--- a/t/t4010-diff-pathspec.sh
+++ b/t/t4010-diff-pathspec.sh
@@ -55,6 +55,15 @@ test_expect_success \
     'git diff-index --cached $tree -- file0 >current &&
      compare_diff_raw current expected'
 
+cat >expected.template <<\EOF
+:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M	path1/file1
+EOF
+test_expect_success 'diff-index with wildcard' '
+	git diff-index --cached $tree -- "*1" >current &&
+	cp expected.template expected &&
+	compare_diff_raw current expected
+'
+
 cat >expected <<\EOF
 EOF
 test_expect_success \
-- 
1.7.1.rc1.70.g788ca

      parent reply	other threads:[~2010-09-19 23:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-19 23:29 [PATCH 0/5] Globbing support in diff family Nguyễn Thái Ngọc Duy
2010-09-19 23:29 ` [PATCH 1/5] pathspec: mark wildcard pathspecs from the beginning Nguyễn Thái Ngọc Duy
2010-09-19 23:29 ` [PATCH 2/5] pathspec: add tree_recursive_diff parameter Nguyễn Thái Ngọc Duy
2010-09-27 22:20   ` Junio C Hamano
2010-09-28  2:38     ` Nguyen Thai Ngoc Duy
2010-09-28  5:28       ` Junio C Hamano
2010-09-19 23:29 ` [PATCH 3/5] tree_entry_interesting: turn to match_pathspec if wildcard is present Nguyễn Thái Ngọc Duy
2010-09-19 23:29 ` [PATCH 4/5] Convert ce_path_match() to use struct pathspec Nguyễn Thái Ngọc Duy
2010-09-19 23:30 ` Nguyễn Thái Ngọc Duy [this message]

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=1284939000-16907-6-git-send-email-pclouds@gmail.com \
    --to=pclouds@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.