git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: git-dev@github.com
Subject: Re: [PATCH] revision: avoid work after --max-count is reached
Date: Fri, 13 Jul 2012 03:53:26 -0400	[thread overview]
Message-ID: <20120713075326.GA32206@sigill.intra.peff.net> (raw)
In-Reply-To: <20120713075023.GA31618@sigill.intra.peff.net>

On Fri, Jul 13, 2012 at 03:50:23AM -0400, Jeff King wrote:

>  revision.c | 39 +++++++++++++++++++--------------------
>  1 file changed, 19 insertions(+), 20 deletions(-)

BTW, the patch is slightly hard to read because of the re-indentation.
Here it is with "-w -U5":

diff --git a/revision.c b/revision.c
index 5b81a92..7e39655 100644
--- a/revision.c
+++ b/revision.c
@@ -2359,32 +2359,31 @@ static struct commit *get_revision_internal(struct rev_info *revs)
 			c->object.flags |= SHOWN;
 		return c;
 	}
 
 	/*
-	 * 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);
 		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:
+		if (revs->max_count > 0)
 			revs->max_count--;
 	}
 
 	if (c)
 		c->object.flags |= SHOWN;
-- 
1.7.11.35.gbaf554e.dirty

  reply	other threads:[~2012-07-13  7:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-13  7:50 [PATCH] revision: avoid work after --max-count is reached Jeff King
2012-07-13  7:53 ` Jeff King [this message]
2012-07-13 21:10 ` Junio C Hamano
2012-07-13 21:20   ` Jeff King
2012-07-13 22:12     ` Junio C Hamano
2012-07-14  8:10       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120713075326.GA32206@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git-dev@github.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).