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,8 +2369,16 @@ 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.
*/ */
if (revs->max_count) {
c = get_revision_1(revs); c = get_revision_1(revs);
if (c) { if (c) {
while (0 < revs->skip_count) { while (0 < revs->skip_count) {
@ -2381,16 +2389,7 @@ static struct commit *get_revision_internal(struct rev_info *revs)
} }
} }
/* if (revs->max_count > 0)
* Check the max_count.
*/
switch (revs->max_count) {
case -1:
break;
case 0:
c = NULL;
break;
default:
revs->max_count--; revs->max_count--;
} }