Skip to content

Commit d05e56e

Browse files
committed
Merge branch 'jk/revision-walk-stop-at-max-count'
"git log -n 1 -- rarely-touched-path" was spending unnecessary cycles after showing the first change to find the next one, only to discard it. * jk/revision-walk-stop-at-max-count: revision: avoid work after --max-count is reached
2 parents a3ad9a0 + b72a190 commit d05e56e

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

revision.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,29 +2369,28 @@ static struct commit *get_revision_internal(struct rev_info *revs)
23692369
}
23702370

23712371
/*
2372-
* Now pick up what they want to give us
2372+
* If our max_count counter has reached zero, then we are done. We
2373+
* don't simply return NULL because we still might need to show
2374+
* boundary commits. But we want to avoid calling get_revision_1, which
2375+
* might do a considerable amount of work finding the next commit only
2376+
* for us to throw it away.
2377+
*
2378+
* If it is non-zero, then either we don't have a max_count at all
2379+
* (-1), or it is still counting, in which case we decrement.
23732380
*/
2374-
c = get_revision_1(revs);
2375-
if (c) {
2376-
while (0 < revs->skip_count) {
2377-
revs->skip_count--;
2378-
c = get_revision_1(revs);
2379-
if (!c)
2380-
break;
2381+
if (revs->max_count) {
2382+
c = get_revision_1(revs);
2383+
if (c) {
2384+
while (0 < revs->skip_count) {
2385+
revs->skip_count--;
2386+
c = get_revision_1(revs);
2387+
if (!c)
2388+
break;
2389+
}
23812390
}
2382-
}
23832391

2384-
/*
2385-
* Check the max_count.
2386-
*/
2387-
switch (revs->max_count) {
2388-
case -1:
2389-
break;
2390-
case 0:
2391-
c = NULL;
2392-
break;
2393-
default:
2394-
revs->max_count--;
2392+
if (revs->max_count > 0)
2393+
revs->max_count--;
23952394
}
23962395

23972396
if (c)

0 commit comments

Comments
 (0)