From: Junio C Hamano Date: Sat, 18 Apr 2009 21:18:32 +0000 (-0700) Subject: Merge branch 'bs/maint-1.6.0-tree-walk-prefix' into maint X-Git-Tag: v1.6.3-rc1~4^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/08e7239c36a477c52ac83488537600a494002b31?hp=-c Merge branch 'bs/maint-1.6.0-tree-walk-prefix' into maint * bs/maint-1.6.0-tree-walk-prefix: match_tree_entry(): a pathspec only matches at directory boundaries tree_entry_interesting: a pathspec only matches at directory boundary --- 08e7239c36a477c52ac83488537600a494002b31 diff --combined t/t4010-diff-pathspec.sh index 9322298ecc,4c4c8b1570..94df7ae53a --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@@ -10,7 -10,7 +10,7 @@@ Prepare path1/file1 ' . ./test-lib.sh -. ../diff-lib.sh ;# test-lib chdir's into trash +. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash test_expect_success \ setup \ @@@ -62,4 -62,12 +62,12 @@@ test_expect_success 'git diff-index --cached $tree -- file0/ >current && compare_diff_raw current expected' + test_expect_success 'diff-tree pathspec' ' + tree2=$(git write-tree) && + echo "$tree2" && + git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current && + >expected && + test_cmp expected current + ' + test_done diff --combined tree.c index 25d2e29fa8,d82a047e55..0d703a0c47 --- a/tree.c +++ b/tree.c @@@ -60,8 -60,12 +60,12 @@@ static int match_tree_entry(const char /* If it doesn't match, move along... */ if (strncmp(base, match, matchlen)) continue; - /* The base is a subdirectory of a path which was specified. */ - return 1; + /* pathspecs match only at the directory boundaries */ + if (!matchlen || + base[matchlen] == '/' || + match[matchlen - 1] == '/') + return 1; + continue; } /* Does the base match? */ @@@ -110,7 -114,7 +114,7 @@@ int read_tree_recursive(struct tree *tr case 0: continue; case READ_TREE_RECURSIVE: - break;; + break; default: return -1; } @@@ -131,34 -135,6 +135,34 @@@ if (retval) return -1; continue; + } else if (S_ISGITLINK(entry.mode)) { + int retval; + struct strbuf path; + unsigned int entrylen; + struct commit *commit; + + entrylen = tree_entry_len(entry.path, entry.sha1); + strbuf_init(&path, baselen + entrylen + 1); + strbuf_add(&path, base, baselen); + strbuf_add(&path, entry.path, entrylen); + strbuf_addch(&path, '/'); + + commit = lookup_commit(entry.sha1); + if (!commit) + die("Commit %s in submodule path %s not found", + sha1_to_hex(entry.sha1), path.buf); + + if (parse_commit(commit)) + die("Invalid commit %s in submodule path %s", + sha1_to_hex(entry.sha1), path.buf); + + retval = read_tree_recursive(commit->tree, + path.buf, path.len, + stage, match, fn, context); + strbuf_release(&path); + if (retval) + return -1; + continue; } } return 0;