From: Junio C Hamano Date: Tue, 19 Dec 2017 19:33:56 +0000 (-0800) Subject: Merge branch 'bw/pathspec-match-submodule-boundary' X-Git-Tag: v2.16.0-rc0~47 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f4f233e13daa584e5178141eb10e6e9527a3454c?hp=-c Merge branch 'bw/pathspec-match-submodule-boundary' An v2.12-era regression in pathspec match logic, which made it look into submodule tree even when it is not desired, has been fixed. * bw/pathspec-match-submodule-boundary: pathspec: only match across submodule boundaries when requested --- f4f233e13daa584e5178141eb10e6e9527a3454c diff --combined builtin/grep.c index 5a6cfe6b45,4bbbce2a64..3ca4ac80d8 --- a/builtin/grep.c +++ b/builtin/grep.c @@@ -645,7 -645,7 +645,7 @@@ static int grep_objects(struct grep_op /* load the gitmodules file for this rev */ if (recurse_submodules) { submodule_free(); - gitmodules_config_sha1(real_obj->oid.hash); + gitmodules_config_oid(&real_obj->oid); } if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path, repo)) { @@@ -985,8 -985,8 +985,8 @@@ int cmd_grep(int argc, const char **arg break; } - if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH, - oid.hash, &oc)) { + if (get_oid_with_context(arg, GET_OID_RECORD_PATH, + &oid, &oc)) { if (seen_dashdash) die(_("unable to resolve revision: %s"), arg); break; @@@ -1015,6 -1015,7 +1015,7 @@@ prefix, argv + i); pathspec.max_depth = opt.max_depth; pathspec.recursive = 1; + pathspec.recurse_submodules = !!recurse_submodules; #ifndef NO_PTHREADS if (list.nr || cached || show_in_pager) @@@ -1050,6 -1051,10 +1051,6 @@@ } #endif - if (recurse_submodules) { - gitmodules_config(); - } - if (show_in_pager && (cached || list.nr)) die(_("--open-files-in-pager only works on the worktree")); diff --combined pathspec.h index 6420d1080a,d000b63d80..099a170c2e --- a/pathspec.h +++ b/pathspec.h @@@ -24,6 -24,7 +24,7 @@@ struct pathspec int nr; unsigned int has_wildcard:1; unsigned int recursive:1; + unsigned int recurse_submodules:1; unsigned magic; int max_depth; struct pathspec_item { @@@ -70,13 -71,6 +71,13 @@@ */ #define PATHSPEC_LITERAL_PATH (1<<6) +/* + * Given command line arguments and a prefix, convert the input to + * pathspec. die() if any magic in magic_mask is used. + * + * Any arguments used are copied. It is safe for the caller to modify + * or free 'prefix' and 'args' after calling this function. + */ extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask, unsigned flags, diff --combined tree-walk.c index 684f0e3373,d6de5315be..63a87ed666 --- a/tree-walk.c +++ b/tree-walk.c @@@ -78,16 -78,15 +78,16 @@@ int init_tree_desc_gently(struct tree_d return result; } -void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1) +void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid) { unsigned long size = 0; void *buf = NULL; - if (sha1) { - buf = read_object_with_reference(sha1, tree_type, &size, NULL); + if (oid) { + buf = read_object_with_reference(oid->hash, tree_type, &size, + NULL); if (!buf) - die("unable to read tree %s", sha1_to_hex(sha1)); + die("unable to read tree %s", oid_to_hex(oid)); } init_tree_desc(desc, buf, size); return buf; @@@ -582,11 -581,12 +582,11 @@@ enum follow_symlinks_result get_tree_en int retval = MISSING_OBJECT; struct dir_state *parents = NULL; size_t parents_alloc = 0; - ssize_t parents_nr = 0; + size_t i, parents_nr = 0; unsigned char current_tree_sha1[20]; struct strbuf namebuf = STRBUF_INIT; struct tree_desc t; int follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS; - int i; init_tree_desc(&t, NULL, 0UL); strbuf_addstr(&namebuf, name); @@@ -1011,7 -1011,8 +1011,8 @@@ static enum interesting do_match(const * character. More accurate matching can then * be performed in the submodule itself. */ - if (ps->recursive && S_ISGITLINK(entry->mode) && + if (ps->recurse_submodules && + S_ISGITLINK(entry->mode) && !ps_strncmp(item, match + baselen, entry->path, item->nowildcard_len - baselen)) @@@ -1060,7 -1061,7 +1061,7 @@@ match_wildcards * character. More accurate matching can then * be performed in the submodule itself. */ - if (ps->recursive && S_ISGITLINK(entry->mode) && + if (ps->recurse_submodules && S_ISGITLINK(entry->mode) && !ps_strncmp(item, match, base->buf + base_offset, item->nowildcard_len)) { strbuf_setlen(base, base_offset + baselen);