revision: add next_commit_to_show()

get_revision() gets its commits from two sources depending on the mode: 1. Normally it gets the commits from get_revision_internal(). 2. --max-count-oldest which was introduced at bb4ce23284 (revision.c: implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit. Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from. This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source. The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change. Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pablo Sabater committed Jul 14, 2026 at 14:09 UTC 08a0bef796e3a1de6b5d08d7958bc122faf32f15
1 file changed +24 -12
revision.c
+24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,
4658 commit_list_insert(c, queue);
4659 }
4660
4661 +/*
4662 + * Returns the next commit that will be shown, regardless of whether it comes
4663 + * directly from the revision walk or from the list saved by the staged output
4664 + * of --max-count-oldest.
4665 + */
4666 +static struct commit *next_commit_to_show(struct rev_info *revs)
4667 +{
4668 + struct commit *c;
4669 + struct commit_list *p;
4670 +
4671 + if (!revs->max_count_stage)
4672 + return get_revision_internal(revs);
4673 +
4674 + c = pop_commit(&revs->commits);
4675 + if (c) {
4676 + c->object.flags |= SHOWN;
4677 + if (!(c->object.flags & BOUNDARY))
4678 + for (p = c->parents; p; p = p->next)
4679 + p->item->object.flags |= CHILD_SHOWN;
4680 + }
4681 + return c;
4682 +}
4683 +
4684 struct commit *get_revision(struct rev_info *revs)
4685 {
4686 struct commit *c;
4687 struct commit_list *reversed;
4688 struct commit_list *queue = NULL;
4666 - struct commit_list *p;
4689
4690 if (revs->max_count_type == 1 && !revs->max_count_stage) {
4691 retrieve_oldest_commits(revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)
4715 return c;
4716 }
4717
4696 - if (revs->max_count_stage) {
4697 - c = pop_commit(&revs->commits);
4698 - if (c) {
4699 - c->object.flags |= SHOWN;
4700 - if (!(c->object.flags & BOUNDARY))
4701 - for (p = c->parents; p; p = p->next)
4702 - p->item->object.flags |= CHILD_SHOWN;
4703 - }
4704 - } else {
4705 - c = get_revision_internal(revs);
4706 - }
4718 + c = next_commit_to_show(revs);
4719
4720 if (c && revs->graph)
4721 graph_update(revs->graph, c);