git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] revision: avoid work after --max-count is reached

From
Jeff King <peff@peff.net>
Date
Jul 13, 2012, 07:53 UTC
Message-ID
<20120713075326.GA32206@sigill.intra.peff.net>
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
Previous: Jeff KingNext: Junio C Hamano
Message 2 of 6 in “revision: avoid work after --max-count is reached”
  1. revision: avoid work after --max-count is reachedJeff King, Jul 13, 2012
  2. Jeff KingJul 13, 2012
  3. Junio C HamanoJul 13, 2012
  4. Jeff KingJul 13, 2012
  5. Junio C HamanoJul 13, 2012
  6. Jeff KingJul 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.