aboutsummaryrefslogtreecommitdiff
path: root/tree-walk.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2016-12-16 11:03:21 -0800
committerJunio C Hamano <gitster@pobox.com>2016-12-22 11:47:33 -0800
commit74ed43711fd1cd7ce155d338f87ebe52cb74d9e2 (patch)
tree3abc50be55697613432ff802730784d8fee088fd /tree-walk.c
parent0281e487fd913bd9a32a710f3109ff3002f3e4a9 (diff)
downloadgit-74ed43711fd1cd7ce155d338f87ebe52cb74d9e2.tar.gz
git-74ed43711fd1cd7ce155d338f87ebe52cb74d9e2.tar.xz
grep: enable recurse-submodules to work on <tree> objects
Teach grep to recursively search in submodules when provided with a <tree> object. This allows grep to search a submodule based on the state of the submodule that is present in a commit of the super project. When grep is provided with a <tree> object, the name of the object is prefixed to all output. In order to provide uniformity of output between the parent and child processes the option `--parent-basename` has been added so that the child can preface all of it's output with the name of the parent's object instead of the name of the commit SHA1 of the submodule. This changes output from the command `git grep -e. -l --recurse-submodules HEAD` from: HEAD:file <commit sha1 of submodule>:sub/file to: HEAD:file HEAD:sub/file Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tree-walk.c')
-rw-r--r--tree-walk.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tree-walk.c b/tree-walk.c
index 828f4356b..ff7760568 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1004,6 +1004,19 @@ static enum interesting do_match(const struct name_entry *entry,
*/
if (ps->recursive && S_ISDIR(entry->mode))
return entry_interesting;
+
+ /*
+ * When matching against submodules with
+ * wildcard characters, ensure that the entry
+ * at least matches up to the first wild
+ * character. More accurate matching can then
+ * be performed in the submodule itself.
+ */
+ if (ps->recursive && S_ISGITLINK(entry->mode) &&
+ !ps_strncmp(item, match + baselen,
+ entry->path,
+ item->nowildcard_len - baselen))
+ return entry_interesting;
}
continue;
@@ -1040,6 +1053,21 @@ match_wildcards:
strbuf_setlen(base, base_offset + baselen);
return entry_interesting;
}
+
+ /*
+ * When matching against submodules with
+ * wildcard characters, ensure that the entry
+ * at least matches up to the first wild
+ * character. More accurate matching can then
+ * be performed in the submodule itself.
+ */
+ if (ps->recursive && S_ISGITLINK(entry->mode) &&
+ !ps_strncmp(item, match, base->buf + base_offset,
+ item->nowildcard_len)) {
+ strbuf_setlen(base, base_offset + baselen);
+ return entry_interesting;
+ }
+
strbuf_setlen(base, base_offset + baselen);
/*