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

[PATCH] Fix git rev-list --reverse --max-count=N

From
MSMichael Spang <spang@google.com>
Date
Jan 27, 2010, 20:03 UTC
Message-ID
<1264622600-20981-1-git-send-email-spang@google.com>

Using --max-count with --reverse currently outputs the last N commits in the final output rather than the first N commits. We want to truncate the reversed list after the first few commits, rather than truncating the initial list and reversing that.

Signed-off-by: Michael Spang <spang@google.com>
---
 revision.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/revision.c b/revision.c
index f54d43f..62135e0 100644
--- a/revision.c
+++ b/revision.c
@@ -1993,7 +1993,8 @@ static struct commit *get_revision_internal(struct rev_info *revs)
 		c = NULL;
 		break;
 	default:
-		revs->max_count--;
+		if (!revs->reverse)
+			revs->max_count--;
 	}
 
 	if (c)
@@ -2055,8 +2056,21 @@ struct commit *get_revision(struct rev_info *revs)
 		revs->reverse_output_stage = 1;
 	}
 
-	if (revs->reverse_output_stage)
-		return pop_commit(&revs->commits);
+	if (revs->reverse_output_stage) {
+		c = pop_commit(&revs->commits);
+
+		switch (revs->max_count) {
+		case -1:
+			break;
+		case 0:
+			c = NULL;
+			break;
+		default:
+			revs->max_count--;
+		}
+
+		return c;
+	}
 
 	c = get_revision_internal(revs);
 	if (c && revs->graph)
-- 
1.6.6
Next: Johannes Sixt
Message 1 of 6 in “Fix git rev-list --reverse --max-count=N”
  1. Fix git rev-list --reverse --max-count=NMichael Spang, Jan 27, 2010
  2. Johannes SixtJan 27, 2010
  3. Sverre RabbelierJan 27, 2010
  4. Michael SpangJan 27, 2010
  5. Junio C HamanoJan 27, 2010
  6. Michael SpangJan 27, 2010

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.