Skip to content

Commit 7c2f08a

Browse files
peffgitster
authored andcommitted
get_revision_1(): replace do-while with an early return
The get_revision_1() function tries to avoid entering its main loop at all when there are no commits to look at. But it's perfectly safe to call pop_commit() on an empty list (in which case it will return NULL). Switching to an early return from the loop lets us skip repeating the loop condition before we enter the do-while. That will get more important when we start pulling reflog-walk commits from a source besides the revs->commits queue, as that condition will get much more complicated. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f35650d commit 7c2f08a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

revision.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,12 +3111,12 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
31113111

31123112
static struct commit *get_revision_1(struct rev_info *revs)
31133113
{
3114-
if (!revs->commits)
3115-
return NULL;
3116-
3117-
do {
3114+
while (1) {
31183115
struct commit *commit = pop_commit(&revs->commits);
31193116

3117+
if (!commit)
3118+
return NULL;
3119+
31203120
if (revs->reflog_info) {
31213121
save_parents(revs, commit);
31223122
fake_reflog_parent(revs->reflog_info, commit);
@@ -3150,8 +3150,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
31503150
track_linear(revs, commit);
31513151
return commit;
31523152
}
3153-
} while (revs->commits);
3154-
return NULL;
3153+
}
31553154
}
31563155

31573156
/*

0 commit comments

Comments
 (0)