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

[PATCH] Teach revision machinery about --reverse

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 21, 2007, 11:19 UTC
Message-ID
<Pine.LNX.4.63.0701211154320.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<45B2D651.7010606@fs.ei.tum.de>
The option --reverse reverses the order of the commits.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	On Sun, 21 Jan 2007, Simon 'corecode' Schubert wrote:
	
	> > [the --reverse patch]
	
	Please do not quote parts of the mail you don't really refer to.
	
	> I like this.  However, rev_info.reverse needs some 
	> documentation.  Or the block in get_revision does:
	> 
	> /*
	> * rev_info.reverse is used to note the fact that we want to output the list
	> * of revisions in reverse order.  To accomplish this goal, reverse can have
	> * different values:
	> *  0  do nothing
	> *  1  reverse the list
	> *  2  internal use:  we have already obtained and reversed the list,
	> *     now we only need to yield its items.
	> */
	
	I liked the comment in get_revision() better.
	
	But then an idea just hit me: it might make sense to introduce 
	another flag instead, "no_walk", which says that revs->commits 
	should be walked as is, not walking parents.
	
	And then I saw it already exists. D'oh.
 Documentation/git-rev-list.txt |    5 +++++
 revision.c                     |   20 ++++++++++++++++++++
 revision.h                     |    3 ++-
 3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index 86c94e7..6bb9f51 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -27,6 +27,7 @@ SYNOPSIS
 	     [ \--pretty | \--header ]
 	     [ \--bisect ]
 	     [ \--merge ]
+	     [ \--reverse ]
 	     <commit>... [ \-- <paths>... ]
 
 DESCRIPTION
@@ -249,6 +250,10 @@ By default, the commits are shown in reverse chronological order.
 	parent comes before all of its children, but otherwise things
 	are still ordered in the commit timestamp order.
 
+--reverse::
+
+	Output the commits in reverse order.
+
 Object Traversal
 ~~~~~~~~~~~~~~~~
 
diff --git a/revision.c b/revision.c
index ebd0250..6d512ff 100644
--- a/revision.c
+++ b/revision.c
@@ -1057,6 +1057,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 					git_log_output_encoding = "";
 				continue;
 			}
+			if (!strcmp(arg, "--reverse")) {
+				revs->reverse ^= 1;
+				continue;
+			}
 
 			opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
 			if (opts > 0) {
@@ -1285,6 +1289,22 @@ struct commit *get_revision(struct rev_info *revs)
 {
 	struct commit *c = NULL;
 
+	if (revs->reverse) {
+		struct commit_list *list;
+
+		revs->reverse = 0;
+		list = NULL;
+		while ((c = get_revision(revs)))
+			commit_list_insert(c, &list);
+		revs->commits = list;
+		revs->no_walk = 1;
+		/* reset flags */
+		while (list) {
+			list->item->object.flags &= ~(ADDED | SEEN | SHOWN);
+			list = list->next;
+		}
+	}
+
 	if (0 < revs->skip_count) {
 		while ((c = get_revision_1(revs)) != NULL) {
 			if (revs->skip_count-- <= 0)
diff --git a/revision.h b/revision.h
index d93481f..3eb1ce4 100644
--- a/revision.h
+++ b/revision.h
@@ -42,7 +42,8 @@ struct rev_info {
 			unpacked:1, /* see also ignore_packed below */
 			boundary:1,
 			left_right:1,
-			parents:1;
+			parents:1,
+			reverse:1;
 
 	/* Diff flags */
 	unsigned int	diff:1,
-- 
1.5.0.rc1.g956c1-dirty
Previous: Simon 'corecode' Schubert
Message 31 of 31 in “Re: [PATCH] Lose perl dependency. (fwd)”
  1. Johannes SchindelinJan 18, 2007
  2. Simon 'corecode' SchubertJan 18, 2007
  3. Johannes SchindelinJan 18, 2007
  4. Simon 'corecode' SchubertJan 18, 2007
  5. Andy ParkinsJan 18, 2007
  6. Johannes SchindelinJan 18, 2007
  7. Junio C HamanoJan 19, 2007
  8. Johannes SchindelinJan 19, 2007
  9. Junio C HamanoJan 20, 2007
  10. Johannes SchindelinJan 20, 2007
  11. Junio C HamanoJan 20, 2007
  12. Johannes SchindelinJan 20, 2007
  13. Junio C HamanoJan 20, 2007
  14. Simon 'corecode' SchubertJan 20, 2007
  15. Johannes SchindelinJan 20, 2007
  16. Junio C HamanoJan 20, 2007
  17. Johannes SchindelinJan 20, 2007
  18. Robin RosenbergJan 21, 2007
  19. Johannes SchindelinJan 21, 2007
  20. Bill LearJan 21, 2007
  21. Junio C HamanoJan 21, 2007
  22. David KågedalJan 21, 2007
  23. Johannes SchindelinJan 21, 2007
  24. Krzysztof HalasaJan 23, 2007
  25. David KågedalJan 23, 2007
  26. Krzysztof HalasaJan 23, 2007
  27. Randal L. SchwartzJan 23, 2007
  28. Krzysztof HalasaJan 23, 2007
  29. Krzysztof HalasaJan 23, 2007
  30. Simon 'corecode' SchubertJan 21, 2007
  31. Teach revision machinery about --reverseJohannes Schindelin, Jan 21, 2007

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.