[PATCH 5/5] ce_path_match: drop prefix matching in favor of match_pathspec
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- Sep 19, 2010, 23:30 UTC
- Message-ID
- <1284939000-16907-6-git-send-email-pclouds@gmail.com>
- 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