Merge branch 'nd/attr-pathspec-in-tree-walk'

The traversal over tree objects has learned to honor
":(attr:label)" pathspec match, which has been implemented only for
enumerating paths on the filesystem.

* nd/attr-pathspec-in-tree-walk:
  tree-walk: support :(attr) matching
  dir.c: move, rename and export match_attrs()
  pathspec.h: clean up "extern" in function declarations
  tree-walk.c: make tree_entry_interesting() take an index
  tree.c: make read_tree*() take 'struct repository *'
This commit is contained in:
Junio C Hamano
2019-01-14 15:29:28 -08:00
21 changed files with 234 additions and 108 deletions

View File

@ -31,7 +31,7 @@ test_expect_success 'setup a tree' '
mkdir sub &&
while read path
do
: >$path &&
echo content >$path &&
git add $path || return 1
done <expect &&
git commit -m "initial commit" &&
@ -48,6 +48,10 @@ test_expect_success 'pathspec with labels and non existent .gitattributes' '
test_must_be_empty actual
'
test_expect_success 'pathspec with labels and non existent .gitattributes (2)' '
test_must_fail git grep content HEAD -- ":(attr:label)"
'
test_expect_success 'setup .gitattributes' '
cat <<-\EOF >.gitattributes &&
fileA labelA
@ -74,6 +78,15 @@ test_expect_success 'check specific set attr' '
test_cmp expect actual
'
test_expect_success 'check specific set attr (2)' '
cat <<-\EOF >expect &&
HEAD:fileSetLabel
HEAD:sub/fileSetLabel
EOF
git grep -l content HEAD ":(attr:label)" >actual &&
test_cmp expect actual
'
test_expect_success 'check specific unset attr' '
cat <<-\EOF >expect &&
fileUnsetLabel
@ -83,6 +96,15 @@ test_expect_success 'check specific unset attr' '
test_cmp expect actual
'
test_expect_success 'check specific unset attr (2)' '
cat <<-\EOF >expect &&
HEAD:fileUnsetLabel
HEAD:sub/fileUnsetLabel
EOF
git grep -l content HEAD ":(attr:-label)" >actual &&
test_cmp expect actual
'
test_expect_success 'check specific value attr' '
cat <<-\EOF >expect &&
fileValue
@ -94,6 +116,16 @@ test_expect_success 'check specific value attr' '
test_must_be_empty actual
'
test_expect_success 'check specific value attr (2)' '
cat <<-\EOF >expect &&
HEAD:fileValue
HEAD:sub/fileValue
EOF
git grep -l content HEAD ":(attr:label=foo)" >actual &&
test_cmp expect actual &&
test_must_fail git grep -l content HEAD ":(attr:label=bar)"
'
test_expect_success 'check unspecified attr' '
cat <<-\EOF >expect &&
.gitattributes
@ -118,6 +150,30 @@ test_expect_success 'check unspecified attr' '
test_cmp expect actual
'
test_expect_success 'check unspecified attr (2)' '
cat <<-\EOF >expect &&
HEAD:.gitattributes
HEAD:fileA
HEAD:fileAB
HEAD:fileAC
HEAD:fileB
HEAD:fileBC
HEAD:fileC
HEAD:fileNoLabel
HEAD:fileWrongLabel
HEAD:sub/fileA
HEAD:sub/fileAB
HEAD:sub/fileAC
HEAD:sub/fileB
HEAD:sub/fileBC
HEAD:sub/fileC
HEAD:sub/fileNoLabel
HEAD:sub/fileWrongLabel
EOF
git grep -l ^ HEAD ":(attr:!label)" >actual &&
test_cmp expect actual
'
test_expect_success 'check multiple unspecified attr' '
cat <<-\EOF >expect &&
.gitattributes