]> git.ipfire.org Git - thirdparty/git.git/blobdiff - revision.c
Merge branch 'sb/object-store-grafts'
[thirdparty/git.git] / revision.c
index 260b9c276c7690245658f2ed5ce9c97acea8f38b..72abe235e4a8045b92d40b18c7d1fb574456e38c 100644 (file)
@@ -30,6 +30,8 @@ volatile show_early_output_fn_t show_early_output;
 static const char *term_bad;
 static const char *term_good;
 
+implement_shared_commit_slab(revision_sources, char *);
+
 void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
        const char *p;
@@ -53,12 +55,9 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
 {
        struct tree_desc desc;
        struct name_entry entry;
-       struct object *obj = &tree->object;
 
-       if (!has_object_file(&obj->oid))
+       if (parse_tree_gently(tree, 1) < 0)
                return;
-       if (parse_tree(tree) < 0)
-               die("bad tree %s", oid_to_hex(&obj->oid));
 
        init_tree_desc(&desc, tree->buffer, tree->size);
        while (tree_entry(&desc, &entry)) {
@@ -96,50 +95,63 @@ void mark_tree_uninteresting(struct tree *tree)
        mark_tree_contents_uninteresting(tree);
 }
 
-void mark_parents_uninteresting(struct commit *commit)
+struct commit_stack {
+       struct commit **items;
+       size_t nr, alloc;
+};
+#define COMMIT_STACK_INIT { NULL, 0, 0 }
+
+static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
 {
-       struct commit_list *parents = NULL, *l;
+       ALLOC_GROW(stack->items, stack->nr + 1, stack->alloc);
+       stack->items[stack->nr++] = commit;
+}
 
-       for (l = commit->parents; l; l = l->next)
-               commit_list_insert(l->item, &parents);
+static struct commit *commit_stack_pop(struct commit_stack *stack)
+{
+       return stack->nr ? stack->items[--stack->nr] : NULL;
+}
 
-       while (parents) {
-               struct commit *commit = pop_commit(&parents);
+static void commit_stack_clear(struct commit_stack *stack)
+{
+       FREE_AND_NULL(stack->items);
+       stack->nr = stack->alloc = 0;
+}
 
-               while (commit) {
-                       /*
-                        * A missing commit is ok iff its parent is marked
-                        * uninteresting.
-                        *
-                        * We just mark such a thing parsed, so that when
-                        * it is popped next time around, we won't be trying
-                        * to parse it and get an error.
-                        */
-                       if (!commit->object.parsed &&
-                           !has_object_file(&commit->object.oid))
-                               commit->object.parsed = 1;
+static void mark_one_parent_uninteresting(struct commit *commit,
+                                         struct commit_stack *pending)
+{
+       struct commit_list *l;
 
-                       if (commit->object.flags & UNINTERESTING)
-                               break;
+       if (commit->object.flags & UNINTERESTING)
+               return;
+       commit->object.flags |= UNINTERESTING;
+
+       /*
+        * Normally we haven't parsed the parent
+        * yet, so we won't have a parent of a parent
+        * here. However, it may turn out that we've
+        * reached this commit some other way (where it
+        * wasn't uninteresting), in which case we need
+        * to mark its parents recursively too..
+        */
+       for (l = commit->parents; l; l = l->next)
+               commit_stack_push(pending, l->item);
+}
 
-                       commit->object.flags |= UNINTERESTING;
+void mark_parents_uninteresting(struct commit *commit)
+{
+       struct commit_stack pending = COMMIT_STACK_INIT;
+       struct commit_list *l;
 
-                       /*
-                        * Normally we haven't parsed the parent
-                        * yet, so we won't have a parent of a parent
-                        * here. However, it may turn out that we've
-                        * reached this commit some other way (where it
-                        * wasn't uninteresting), in which case we need
-                        * to mark its parents recursively too..
-                        */
-                       if (!commit->parents)
-                               break;
+       for (l = commit->parents; l; l = l->next)
+               mark_one_parent_uninteresting(l->item, &pending);
 
-                       for (l = commit->parents->next; l; l = l->next)
-                               commit_list_insert(l->item, &parents);
-                       commit = commit->parents->item;
-               }
-       }
+       while (pending.nr > 0)
+               mark_one_parent_uninteresting(commit_stack_pop(&pending),
+                                             &pending);
+
+       commit_stack_clear(&pending);
 }
 
 static void add_pending_object_with_path(struct rev_info *revs,
@@ -256,14 +268,19 @@ static struct commit *handle_commit(struct rev_info *revs,
         */
        if (object->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *)object;
+
                if (parse_commit(commit) < 0)
                        die("unable to parse commit %s", name);
                if (flags & UNINTERESTING) {
                        mark_parents_uninteresting(commit);
                        revs->limited = 1;
                }
-               if (revs->show_source && !commit->util)
-                       commit->util = xstrdup(name);
+               if (revs->sources) {
+                       char **slot = revision_sources_at(revs->sources, commit);
+
+                       if (!*slot)
+                               *slot = xstrdup(name);
+               }
                return commit;
        }
 
@@ -442,8 +459,8 @@ static void file_change(struct diff_options *options,
 static int rev_compare_tree(struct rev_info *revs,
                            struct commit *parent, struct commit *commit)
 {
-       struct tree *t1 = parent->tree;
-       struct tree *t2 = commit->tree;
+       struct tree *t1 = get_commit_tree(parent);
+       struct tree *t2 = get_commit_tree(commit);
 
        if (!t1)
                return REV_TREE_NEW;
@@ -479,7 +496,7 @@ static int rev_compare_tree(struct rev_info *revs,
 static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
 {
        int retval;
-       struct tree *t1 = commit->tree;
+       struct tree *t1 = get_commit_tree(commit);
 
        if (!t1)
                return 0;
@@ -617,7 +634,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
        if (!revs->prune)
                return;
 
-       if (!commit->tree)
+       if (!get_commit_tree(commit))
                return;
 
        if (!commit->parents) {
@@ -815,8 +832,12 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
                        }
                        return -1;
                }
-               if (revs->show_source && !p->util)
-                       p->util = commit->util;
+               if (revs->sources) {
+                       char **slot = revision_sources_at(revs->sources, p);
+
+                       if (!*slot)
+                               *slot = *revision_sources_at(revs->sources, commit);
+               }
                p->object.flags |= left_flag;
                if (!(p->object.flags & SEEN)) {
                        p->object.flags |= SEEN;
@@ -1753,6 +1774,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        const char *arg = argv[0];
        const char *optarg;
        int argcount;
+       const unsigned hexsz = the_hash_algo->hexsz;
 
        /* pseudo revision arguments */
        if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") ||
@@ -2040,8 +2062,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->abbrev = strtoul(optarg, NULL, 10);
                if (revs->abbrev < MINIMUM_ABBREV)
                        revs->abbrev = MINIMUM_ABBREV;
-               else if (revs->abbrev > 40)
-                       revs->abbrev = 40;
+               else if (revs->abbrev > hexsz)
+                       revs->abbrev = hexsz;
        } else if (!strcmp(arg, "--abbrev-commit")) {
                revs->abbrev_commit = 1;
                revs->abbrev_commit_given = 1;
@@ -2109,7 +2131,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->ignore_missing = 1;
        } else if (!strcmp(arg, "--exclude-promisor-objects")) {
                if (fetch_if_missing)
-                       die("BUG: exclude_promisor_objects can only be used when fetch_if_missing is 0");
+                       BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
                revs->exclude_promisor_objects = 1;
        } else {
                int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
@@ -2175,7 +2197,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
                 * supported right now, so stick to single worktree.
                 */
                if (!revs->single_worktree)
-                       die("BUG: --single-worktree cannot be used together with submodule");
+                       BUG("--single-worktree cannot be used together with submodule");
                refs = get_submodule_ref_store(submodule);
        } else
                refs = get_main_ref_store(the_repository);
@@ -3088,7 +3110,7 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
 {
        if (commit->object.flags & SHOWN)
                return commit_ignore;
-       if (revs->unpacked && has_sha1_pack(commit->object.oid.hash))
+       if (revs->unpacked && has_object_pack(&commit->object.oid))
                return commit_ignore;
        if (commit->object.flags & UNINTERESTING)
                return commit_ignore;