Code

tree_entry_interesting(): optimize wildcard matching when base is matched
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Wed, 15 Dec 2010 15:02:47 +0000 (22:02 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Dec 2010 21:20:23 +0000 (13:20 -0800)
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>
t/t4010-diff-pathspec.sh
tree-walk.c

index 4b120f8e23f92cd51f64d5a2ed8c3f37d31ec421..fbc8cd8f05f4debeb30b935c1b1db86e94e49f0e 100755 (executable)
@@ -84,4 +84,22 @@ test_expect_success 'diff-tree -r with wildcard' '
        test_cmp expected result
 '
 
+test_expect_success 'diff-tree with wildcard shows dir also matches' '
+       git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
+       echo path1 >expected &&
+       test_cmp expected result
+'
+
+test_expect_success 'diff-tree -r with wildcard from beginning' '
+       git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
+       echo path1/file1 >expected &&
+       test_cmp expected result
+'
+
+test_expect_success 'diff-tree -r with wildcard' '
+       git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
+       echo path1/file1 >expected &&
+       test_cmp expected result
+'
+
 test_done
index cc5a4e1f44b0fb18d191ef64376fa318b0a171d1..99413b379eef7f09e9b766080ed0449866d27f0e 100644 (file)
@@ -593,6 +593,20 @@ int tree_entry_interesting(const struct name_entry *entry,
                                        match + baselen, matchlen - baselen,
                                        &never_interesting))
                                return 1;
+
+                       if (ps->items[i].has_wildcard) {
+                               if (!fnmatch(match + baselen, entry->path, 0))
+                                       return 1;
+
+                               /*
+                                * Match all directories. We'll try to
+                                * match files later on.
+                                */
+                               if (ps->recursive && S_ISDIR(entry->mode))
+                                       return 1;
+                       }
+
+                       continue;
                }
 
 match_wildcards: