]> git.ipfire.org Git - thirdparty/git.git/blobdiff - revision.c
traverse_commit_list: support pending blobs/trees with paths
[thirdparty/git.git] / revision.c
index 0d3e4171ef73f0cfb58a4f396e17717f3b0bb5a3..ebe3e93d1298c542ae655e3af3b5b2761f0061de 100644 (file)
@@ -198,9 +198,10 @@ void mark_parents_uninteresting(struct commit *commit)
        }
 }
 
-static void add_pending_object_with_mode(struct rev_info *revs,
+static void add_pending_object_with_path(struct rev_info *revs,
                                         struct object *obj,
-                                        const char *name, unsigned mode)
+                                        const char *name, unsigned mode,
+                                        const char *path)
 {
        if (!obj)
                return;
@@ -220,7 +221,14 @@ static void add_pending_object_with_mode(struct rev_info *revs,
                if (st)
                        return;
        }
-       add_object_array_with_mode(obj, name, &revs->pending, mode);
+       add_object_array_with_path(obj, name, &revs->pending, mode, path);
+}
+
+static void add_pending_object_with_mode(struct rev_info *revs,
+                                        struct object *obj,
+                                        const char *name, unsigned mode)
+{
+       add_pending_object_with_path(revs, obj, name, mode, NULL);
 }
 
 void add_pending_object(struct rev_info *revs,
@@ -265,8 +273,12 @@ void add_pending_sha1(struct rev_info *revs, const char *name,
 }
 
 static struct commit *handle_commit(struct rev_info *revs,
-                                   struct object *object, const char *name)
+                                   struct object_array_entry *entry)
 {
+       struct object *object = entry->item;
+       const char *name = entry->name;
+       const char *path = entry->path;
+       unsigned int mode = entry->mode;
        unsigned long flags = object->flags;
 
        /*
@@ -285,6 +297,14 @@ static struct commit *handle_commit(struct rev_info *revs,
                        die("bad object %s", sha1_to_hex(tag->tagged->sha1));
                }
                object->flags |= flags;
+               /*
+                * We'll handle the tagged object by looping or dropping
+                * through to the non-tag handlers below. Do not
+                * propagate data from the tag's pending entry.
+                */
+               name = "";
+               path = NULL;
+               mode = 0;
        }
 
        /*
@@ -300,7 +320,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                        revs->limited = 1;
                }
                if (revs->show_source && !commit->util)
-                       commit->util = (void *) name;
+                       commit->util = xstrdup(name);
                return commit;
        }
 
@@ -316,7 +336,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                        mark_tree_contents_uninteresting(tree);
                        return NULL;
                }
-               add_pending_object(revs, object, "");
+               add_pending_object_with_path(revs, object, name, mode, path);
                return NULL;
        }
 
@@ -328,7 +348,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                        return NULL;
                if (flags & UNINTERESTING)
                        return NULL;
-               add_pending_object(revs, object, "");
+               add_pending_object_with_path(revs, object, name, mode, path);
                return NULL;
        }
        die("%s is unknown object", name);
@@ -1275,7 +1295,7 @@ static int handle_one_reflog(const char *path, const unsigned char *sha1, int fl
        return 0;
 }
 
-static void handle_reflog(struct rev_info *revs, unsigned flags)
+void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
 {
        struct all_refs_cb cb;
        cb.all_revs = revs;
@@ -1397,7 +1417,7 @@ static void prepare_show_merge(struct rev_info *revs)
                        continue;
                if (ce_path_match(ce, &revs->prune_data, NULL)) {
                        prune_num++;
-                       prune = xrealloc(prune, sizeof(*prune) * prune_num);
+                       REALLOC_ARRAY(prune, prune_num);
                        prune[prune_num-2] = ce->name;
                        prune[prune_num-1] = NULL;
                }
@@ -2061,7 +2081,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
                for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
                clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--reflog")) {
-               handle_reflog(revs, *flags);
+               add_reflogs_to_pending(revs, *flags);
        } else if (!strcmp(arg, "--not")) {
                *flags ^= UNINTERESTING | BOTTOM;
        } else if (!strcmp(arg, "--no-walk")) {
@@ -2656,26 +2676,26 @@ void reset_revision_walk(void)
 
 int prepare_revision_walk(struct rev_info *revs)
 {
-       int nr = revs->pending.nr;
-       struct object_array_entry *e, *list;
+       int i;
+       struct object_array old_pending;
        struct commit_list **next = &revs->commits;
 
-       e = list = revs->pending.objects;
+       memcpy(&old_pending, &revs->pending, sizeof(old_pending));
        revs->pending.nr = 0;
        revs->pending.alloc = 0;
        revs->pending.objects = NULL;
-       while (--nr >= 0) {
-               struct commit *commit = handle_commit(revs, e->item, e->name);
+       for (i = 0; i < old_pending.nr; i++) {
+               struct object_array_entry *e = old_pending.objects + i;
+               struct commit *commit = handle_commit(revs, e);
                if (commit) {
                        if (!(commit->object.flags & SEEN)) {
                                commit->object.flags |= SEEN;
                                next = commit_list_append(commit, next);
                        }
                }
-               e++;
        }
        if (!revs->leak_pending)
-               free(list);
+               object_array_clear(&old_pending);
 
        /* Signal whether we need per-parent treesame decoration */
        if (revs->simplify_merges ||