summaryrefslogtreecommitdiff
path: root/revision.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-07-22 12:56:30 -0700
committerJunio C Hamano <gitster@pobox.com>2012-07-22 12:56:30 -0700
commitd05e56ea67743b68336aede7f4c42fece7ae764c (patch)
treef3381bdf4e73a082584eef9dc8ea392d4dc08396 /revision.c
parenta3ad9a0f8d57cb0c98adc541ea1de1cc1081cf14 (diff)
parentb72a1904aefb9e27014a11790f3af4dc90b38e8d (diff)
downloadgit-d05e56ea67743b68336aede7f4c42fece7ae764c.tar.gz
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
Diffstat (limited to 'revision.c')
-rw-r--r--revision.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/revision.c b/revision.c
index c64bf68fa1..9e8f47a25d 100644
--- a/revision.c
+++ b/revision.c
@@ -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 (c) {
- while (0 < revs->skip_count) {
- revs->skip_count--;
- c = get_revision_1(revs);
- if (!c)
- break;
+ if (revs->max_count) {
+ c = get_revision_1(revs);
+ if (c) {
+ while (0 < revs->skip_count) {
+ revs->skip_count--;
+ c = get_revision_1(revs);
+ if (!c)
+ break;
+ }
}
- }
- /*
- * Check the max_count.
- */
- switch (revs->max_count) {
- case -1:
- break;
- case 0:
- c = NULL;
- break;
- default:
- revs->max_count--;
+ if (revs->max_count > 0)
+ revs->max_count--;
}
if (c)