Imported Upstream version 2.17.0
[platform/upstream/git.git] / tree-walk.c
index 828f435..63a87ed 100644 (file)
@@ -78,15 +78,16 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l
        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;
@@ -581,15 +582,13 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
        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_init(result_path, 0);
        strbuf_addstr(&namebuf, name);
        hashcpy(current_tree_sha1, tree_sha1);
 
@@ -1004,6 +1003,20 @@ 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->recurse_submodules &&
+                                   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->recurse_submodules && 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);
 
                /*
@@ -1047,7 +1075,7 @@ match_wildcards:
                 * later on.
                 * max_depth is ignored but we may consider support it
                 * in future, see
-                * http://thread.gmane.org/gmane.comp.version-control.git/163757/focus=163840
+                * https://public-inbox.org/git/7vmxo5l2g4.fsf@alter.siamese.dyndns.org/
                 */
                if (ps->recursive && S_ISDIR(entry->mode))
                        return entry_interesting;