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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 7, 2017 at 05:07 UTC 7c2f08aa7a26e68475abe5c9fd7250aacbb6b7b2
1 file changed +5 -6
revision.c
+5 -6
@@ -3111,12 +3111,12 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
3111
3112 static struct commit *get_revision_1(struct rev_info *revs)
3113 {
3114 - if (!revs->commits)
3115 - return NULL;
3116 -
3117 - do {
3114 + while (1) {
3115 struct commit *commit = pop_commit(&revs->commits);
3116
3117 + if (!commit)
3118 + return NULL;
3119 +
3120 if (revs->reflog_info) {
3121 save_parents(revs, commit);
3122 fake_reflog_parent(revs->reflog_info, commit);
@@ -3150,8 +3150,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
3150 track_linear(revs, commit);
3151 return commit;
3152 }
3153 - } while (revs->commits);
3154 - return NULL;
3153 + }
3154 }
3155
3156 /*