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
This commit is contained in:
Junio C Hamano 2012-07-22 12:56:30 -07:00
commit d05e56ea67

View File

@ -2369,29 +2369,28 @@ static struct commit *get_revision_internal(struct rev_info *revs)
} }
/* /*
* Now pick up what they want to give us * If our max_count counter has reached zero, then we are done. We
* don't simply return NULL because we still might need to show
* boundary commits. But we want to avoid calling get_revision_1, which
* might do a considerable amount of work finding the next commit only
* for us to throw it away.
*
* If it is non-zero, then either we don't have a max_count at all
* (-1), or it is still counting, in which case we decrement.
*/ */
c = get_revision_1(revs); if (revs->max_count) {
if (c) { c = get_revision_1(revs);
while (0 < revs->skip_count) { if (c) {
revs->skip_count--; while (0 < revs->skip_count) {
c = get_revision_1(revs); revs->skip_count--;
if (!c) c = get_revision_1(revs);
break; if (!c)
break;
}
} }
}
/* if (revs->max_count > 0)
* Check the max_count. revs->max_count--;
*/
switch (revs->max_count) {
case -1:
break;
case 0:
c = NULL;
break;
default:
revs->max_count--;
} }
if (c) if (c)