get_revision_1(): replace do-while with an early return
authorJeff King <peff@peff.net>
Fri, 7 Jul 2017 09:07:58 +0000 (05:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 Jul 2017 17:00:48 +0000 (10:00 -0700)
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>
revision.c
index 6678de04d93d5e21c85c972a8b2f4f1245df9b55..4019e8cf231132ce2a8e6693a8023a272b93073e 100644 (file)
@@ -3111,12 +3111,12 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
 
 static struct commit *get_revision_1(struct rev_info *revs)
 {
-       if (!revs->commits)
-               return NULL;
-
-       do {
+       while (1) {
                struct commit *commit = pop_commit(&revs->commits);
 
+               if (!commit)
+                       return NULL;
+
                if (revs->reflog_info) {
                        save_parents(revs, commit);
                        fake_reflog_parent(revs->reflog_info, commit);
@@ -3150,8 +3150,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
                                track_linear(revs, commit);
                        return commit;
                }
-       } while (revs->commits);
-       return NULL;
+       }
 }
 
 /*