@matheusbsbs / matheus-bagliano / commits / f1a2ddbbc2
Fork 0

tree_entry_interesting(): optimize wildcard matching when base is matched

If base is already matched, skip that part when calling fnmatch(). This happens quite often if users start a command from worktree's subdirectory and prefix is usually prepended to all pathspecs. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Dec 15, 2010 at 22:02 UTC f1a2ddbbc2df4e81e005a7e82f9e23fb6a9f95e3
2 files changed +32
t/t4010-diff-pathspec.sh
+18
@@ -84,4 +84,22 @@ test_expect_success 'diff-tree -r with wildcard' '
84 test_cmp expected result
85 '
86
87 +test_expect_success 'diff-tree with wildcard shows dir also matches' '
88 + git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
89 + echo path1 >expected &&
90 + test_cmp expected result
91 +'
92 +
93 +test_expect_success 'diff-tree -r with wildcard from beginning' '
94 + git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
95 + echo path1/file1 >expected &&
96 + test_cmp expected result
97 +'
98 +
99 +test_expect_success 'diff-tree -r with wildcard' '
100 + git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
101 + echo path1/file1 >expected &&
102 + test_cmp expected result
103 +'
104 +
105 test_done
tree-walk.c
+14
@@ -595,6 +595,20 @@ int tree_entry_interesting(const struct name_entry *entry,
595 match + baselen, matchlen - baselen,
596 &never_interesting))
597 return 1;
598 +
599 + if (ps->items[i].has_wildcard) {
600 + if (!fnmatch(match + baselen, entry->path, 0))
601 + return 1;
602 +
603 + /*
604 + * Match all directories. We'll try to
605 + * match files later on.
606 + */
607 + if (ps->recursive && S_ISDIR(entry->mode))
608 + return 1;
609 + }
610 +
611 + continue;
612 }
613
614 match_wildcards: