Merge branch 'bw/pathspec-match-submodule-boundary'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Dec 2017 19:33:56 +0000 (11:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Dec 2017 19:33:56 +0000 (11:33 -0800)
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

1  2 
builtin/grep.c
pathspec.h
tree-walk.c
diff --combined builtin/grep.c
index 5a6cfe6b45b06b6b75ea399a83cb8dcf7e197141,4bbbce2a642186b7de8d9653751e29b0aee617e7..3ca4ac80d8c7014e7e9aba228f542113a5103b48
@@@ -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;
                       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)
        }
  #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 6420d1080ae4165ad81b60376c714bd178463b6a,d000b63d80df8bbed3c3f1d7b4f3082ad4bdc850..099a170c2ef6eb01bee98c7ebf638f34655fda86
@@@ -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 {
   */
  #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 684f0e33736ca237a933f4def3e1560356bde2c2,d6de5315be195ca248ba524dcfa4cfa99f0a6b7c..63a87ed666bbb10cb3c2bd0e27117ac696e7d1b3
@@@ -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);