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, and limited. 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristofer Karlsson committed
May 27, 2026 at 15:50 UTC
d877b1af507a6aaf55e8643eb73277a30d3a800b
1 file changed
+48
-14
revision.c
+48
-14
@@ -4327,22 +4327,48 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
4327
revs->previous_parents = commit_list_copy(commit->parents);
4328
}
4329
4330
+enum rev_walk_mode {
4331
+ REV_WALK_REFLOG,
4332
+ REV_WALK_TOPO,
4333
+ REV_WALK_LIMITED,
4334
+ REV_WALK_STREAMING,
4335
+};
4336
+
4337
+static enum rev_walk_mode get_walk_mode(struct rev_info *revs)
4338
+{
4339
+ if (revs->reflog_info)
4340
+ return REV_WALK_REFLOG;
4341
+ if (revs->topo_walk_info)
4342
+ return REV_WALK_TOPO;
4343
+ if (revs->limited)
4344
+ return REV_WALK_LIMITED;
4345
+ return REV_WALK_STREAMING;
4346
+}
4347
+
4348
static struct commit *get_revision_1(struct rev_info *revs)
4349
{
4350
+ enum rev_walk_mode mode = get_walk_mode(revs);
4351
+
4352
while (1) {
4353
struct commit *commit;
4354
4335
- if (revs->reflog_info)
4355
+ switch (mode) {
4356
+ case REV_WALK_REFLOG:
4357
commit = next_reflog_entry(revs->reflog_info);
4337
- else if (revs->topo_walk_info)
4358
+ break;
4359
+ case REV_WALK_TOPO:
4360
commit = next_topo_commit(revs);
4339
- else
4361
+ break;
4362
+ case REV_WALK_LIMITED:
4363
+ case REV_WALK_STREAMING:
4364
commit = pop_commit(&revs->commits);
4365
+ break;
4366
+ }
4367
4368
if (!commit)
4369
return NULL;
4370
4345
- if (revs->reflog_info)
4371
+ if (mode == REV_WALK_REFLOG)
4372
commit->object.flags &= ~(ADDED | SEEN | SHOWN);
4373
4374
/*
@@ -4350,20 +4376,28 @@ static struct commit *get_revision_1(struct rev_info *revs)
4376
* the parents here. We also need to do the date-based limiting
4377
* that we'd otherwise have done in limit_list().
4378
*/
4353
- if (!revs->limited) {
4354
- if (revs->max_age != -1 &&
4355
- comparison_date(revs, commit) < revs->max_age)
4356
- continue;
4379
+ if (mode != REV_WALK_LIMITED &&
4380
+ revs->max_age != -1 &&
4381
+ comparison_date(revs, commit) < revs->max_age)
4382
+ continue;
4383
4358
- if (revs->reflog_info)
4359
- try_to_simplify_commit(revs, commit);
4360
- else if (revs->topo_walk_info)
4361
- expand_topo_walk(revs, commit);
4362
- else if (process_parents(revs, commit, &revs->commits, NULL) < 0) {
4384
+ switch (mode) {
4385
+ case REV_WALK_REFLOG:
4386
+ try_to_simplify_commit(revs, commit);
4387
+ break;
4388
+ case REV_WALK_TOPO:
4389
+ expand_topo_walk(revs, commit);
4390
+ break;
4391
+ case REV_WALK_STREAMING:
4392
+ if (process_parents(revs, commit,
4393
+ &revs->commits, NULL) < 0) {
4394
if (!revs->ignore_missing_links)
4395
die("Failed to traverse parents of commit %s",
4365
- oid_to_hex(&commit->object.oid));
4396
+ oid_to_hex(&commit->object.oid));
4397
}
4398
+ break;
4399
+ case REV_WALK_LIMITED:
4400
+ break;
4401
}
4402
4403
switch (simplify_commit(revs, commit)) {