From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Subject: [PATCH] commit: use commit_stack
Date: Sun, 8 Feb 2026 12:37:38 +0100 [thread overview]
Message-ID: <db40d132-14ca-4749-937a-9410ecc17dde@web.de> (raw)
Use commit_stack instead of open-coding it. Also convert the loop
counter i to size_t to match the type of the nr member of struct
commit_stack.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
commit.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/commit.c b/commit.c
index 28bb5ce029..22ef0ea6a3 100644
--- a/commit.c
+++ b/commit.c
@@ -1015,9 +1015,7 @@ void sort_in_topological_order(struct commit_list **list, enum rev_sort_order so
}
struct rev_collect {
- struct commit **commit;
- int nr;
- int alloc;
+ struct commit_stack stack;
unsigned int initial : 1;
};
@@ -1034,8 +1032,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
repo_parse_commit(the_repository, commit))
return;
- ALLOC_GROW(revs->commit, revs->nr + 1, revs->alloc);
- revs->commit[revs->nr++] = commit;
+ commit_stack_push(&revs->stack, commit);
commit->object.flags |= TMP_MARK;
}
@@ -1060,7 +1057,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
struct object_id oid;
struct rev_collect revs;
struct commit_list *bases = NULL;
- int i;
+ size_t i;
struct commit *ret = NULL;
char *full_refname;
@@ -1074,19 +1071,19 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
die("Ambiguous refname: '%s'", refname);
}
- memset(&revs, 0, sizeof(revs));
+ commit_stack_init(&revs.stack);
revs.initial = 1;
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
full_refname, collect_one_reflog_ent, &revs);
- if (!revs.nr)
+ if (!revs.stack.nr)
add_one_commit(&oid, &revs);
- for (i = 0; i < revs.nr; i++)
- revs.commit[i]->object.flags &= ~TMP_MARK;
+ for (i = 0; i < revs.stack.nr; i++)
+ revs.stack.items[i]->object.flags &= ~TMP_MARK;
- if (repo_get_merge_bases_many(the_repository, commit, revs.nr,
- revs.commit, &bases) < 0)
+ if (repo_get_merge_bases_many(the_repository, commit, revs.stack.nr,
+ revs.stack.items, &bases) < 0)
exit(128);
/*
@@ -1097,16 +1094,16 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
goto cleanup_return;
/* And the found one must be one of the reflog entries */
- for (i = 0; i < revs.nr; i++)
- if (&bases->item->object == &revs.commit[i]->object)
+ for (i = 0; i < revs.stack.nr; i++)
+ if (&bases->item->object == &revs.stack.items[i]->object)
break; /* found */
- if (revs.nr <= i)
+ if (revs.stack.nr <= i)
goto cleanup_return;
ret = bases->item;
cleanup_return:
- free(revs.commit);
+ commit_stack_clear(&revs.stack);
free_commit_list(bases);
free(full_refname);
return ret;
--
2.52.0
reply other threads:[~2026-02-08 11:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=db40d132-14ca-4749-937a-9410ecc17dde@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox