Skip to content

Commit c74f97a

Browse files
committed
Merge branch 'nd/pathspec-recursion-cleanup'
* nd/pathspec-recursion-cleanup: diff-index: enable recursive pathspec matching in unpack_trees Document limited recursion pathspec matching with wildcards
2 parents 8ef7933 + 4838237 commit c74f97a

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Documentation/git-grep.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ OPTIONS
7979
--max-depth <depth>::
8080
For each <pathspec> given on command line, descend at most <depth>
8181
levels of directories. A negative value means no limit.
82+
This option is ignored if <pathspec> contains active wildcards.
83+
In other words if "a*" matches a directory named "a*",
84+
"*" is matched literally so --max-depth is still effective.
8285

8386
-w::
8487
--word-regexp::

diff-lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ static int diff_cache(struct rev_info *revs,
469469
opts.src_index = &the_index;
470470
opts.dst_index = NULL;
471471
opts.pathspec = &revs->diffopt.pathspec;
472+
opts.pathspec->recursive = 1;
473+
opts.pathspec->max_depth = -1;
472474

473475
init_tree_desc(&t, tree->buffer, tree->size);
474476
return unpack_trees(1, &t, &opts);

t/t4010-diff-pathspec.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ test_expect_success \
4747
'git diff-index --cached $tree -- path1/ >current &&
4848
compare_diff_raw current expected'
4949

50+
cat >expected <<\EOF
51+
:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
52+
EOF
53+
test_expect_success \
54+
'"*file1" should show path1/file1' \
55+
'git diff-index --cached $tree -- "*file1" >current &&
56+
compare_diff_raw current expected'
57+
5058
cat >expected <<\EOF
5159
:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M file0
5260
EOF

tree-walk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
661661
/*
662662
* Match all directories. We'll try to match files
663663
* later on.
664+
* max_depth is ignored but we may consider support it
665+
* in future, see
666+
* http://thread.gmane.org/gmane.comp.version-control.git/163757/focus=163840
664667
*/
665668
if (ps->recursive && S_ISDIR(entry->mode))
666669
return entry_interesting;

0 commit comments

Comments
 (0)