Skip to content

Commit 58004d9

Browse files
committed
revision: introduce rev_walk_mode to clarify get_revision_1()
get_revision_1() dispatches to different walk strategies based on a combination of rev_info flags: reflog_info, topo_walk_info, limited, and no_walk. These conditions are checked in multiple places within the function — once to select the next commit, and again to decide how to expand parents — and the two chains must stay in sync. Extract the mode selection into a rev_walk_mode enum and a small get_walk_mode() helper, resolved once at the top of get_revision_1(). Both dispatch sites now switch on the same mode variable, making it obvious that they agree and easier to verify that all modes are handled. No functional change. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
1 parent 3cf7992 commit 58004d9

1 file changed

Lines changed: 54 additions & 16 deletions

File tree

revision.c

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,49 +4322,87 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
43224322
revs->previous_parents = commit_list_copy(commit->parents);
43234323
}
43244324

4325+
enum rev_walk_mode {
4326+
REV_WALK_REFLOG,
4327+
REV_WALK_TOPO,
4328+
REV_WALK_LIMITED,
4329+
REV_WALK_NO_WALK,
4330+
REV_WALK_STREAMING,
4331+
};
4332+
4333+
static enum rev_walk_mode get_walk_mode(struct rev_info *revs)
4334+
{
4335+
if (revs->reflog_info)
4336+
return REV_WALK_REFLOG;
4337+
if (revs->topo_walk_info)
4338+
return REV_WALK_TOPO;
4339+
if (revs->limited)
4340+
return REV_WALK_LIMITED;
4341+
if (revs->no_walk)
4342+
return REV_WALK_NO_WALK;
4343+
return REV_WALK_STREAMING;
4344+
}
4345+
43254346
static struct commit *get_revision_1(struct rev_info *revs)
43264347
{
4348+
enum rev_walk_mode mode = get_walk_mode(revs);
4349+
4350+
if (mode == REV_WALK_STREAMING && revs->commits)
4351+
rev_info_commit_list_to_queue(revs);
4352+
43274353
while (1) {
43284354
struct commit *commit;
43294355

4330-
if (revs->reflog_info)
4356+
switch (mode) {
4357+
case REV_WALK_REFLOG:
43314358
commit = next_reflog_entry(revs->reflog_info);
4332-
else if (revs->topo_walk_info)
4359+
break;
4360+
case REV_WALK_TOPO:
43334361
commit = next_topo_commit(revs);
4334-
else if (revs->limited || revs->no_walk)
4362+
break;
4363+
case REV_WALK_LIMITED:
4364+
case REV_WALK_NO_WALK:
43354365
commit = pop_commit(&revs->commits);
4336-
else {
4337-
if (!revs->commit_queue.nr && revs->commits)
4338-
rev_info_commit_list_to_queue(revs);
4366+
break;
4367+
case REV_WALK_STREAMING:
43394368
commit = prio_queue_get(&revs->commit_queue);
4369+
break;
43404370
}
43414371

43424372
if (!commit)
43434373
return NULL;
43444374

4345-
if (revs->reflog_info)
4375+
if (mode == REV_WALK_REFLOG)
43464376
commit->object.flags &= ~(ADDED | SEEN | SHOWN);
43474377

43484378
/*
43494379
* If we haven't done the list limiting, we need to look at
43504380
* the parents here. We also need to do the date-based limiting
43514381
* that we'd otherwise have done in limit_list().
43524382
*/
4353-
if (!revs->limited) {
4383+
if (mode != REV_WALK_LIMITED) {
43544384
if (revs->max_age != -1 &&
43554385
comparison_date(revs, commit) < revs->max_age)
43564386
continue;
43574387

4358-
if (revs->reflog_info)
4388+
switch (mode) {
4389+
case REV_WALK_REFLOG:
43594390
try_to_simplify_commit(revs, commit);
4360-
else if (revs->topo_walk_info)
4391+
break;
4392+
case REV_WALK_TOPO:
43614393
expand_topo_walk(revs, commit);
4362-
else if (process_parents(revs, commit,
4363-
revs->no_walk ?
4364-
NULL : &revs->commit_queue) < 0) {
4365-
if (!revs->ignore_missing_links)
4366-
die("Failed to traverse parents of commit %s",
4367-
oid_to_hex(&commit->object.oid));
4394+
break;
4395+
case REV_WALK_STREAMING:
4396+
if (process_parents(revs, commit,
4397+
&revs->commit_queue) < 0) {
4398+
if (!revs->ignore_missing_links)
4399+
die("Failed to traverse parents of commit %s",
4400+
oid_to_hex(&commit->object.oid));
4401+
}
4402+
break;
4403+
case REV_WALK_NO_WALK:
4404+
case REV_WALK_LIMITED:
4405+
break;
43684406
}
43694407
}
43704408

0 commit comments

Comments
 (0)