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

Re: git-log to go forward instead of reverse?

From
Linus Torvalds <torvalds@osdl.org>
Date
Jul 10, 2006, 19:01 UTC
Message-ID
<Pine.LNX.4.64.0607101151470.5623@g5.osdl.org>
In-Reply-To
<86bqrxpai1.fsf@blue.stonehenge.com>
On Mon, 10 Jul 2006, Randal L. Schwartz wrote:
> 
> Am I missing an option to have git-log go forward in time rather than
> backward?  I'd really like "git-log --pretty=short ORIG_HEAD..HEAD" to show me
> a story I can read. :)

Well, as long as you realize that that automatically means that you have to walk the whole commit list, and you won't be able to get the incremental output that git-log and friends normally are able to give?

But this patch should do it. With it,
	git log --reverse --pretty=short ORIG_HEAD..
should do what you want.

It is _not_ possible to reverse the "gitk" view with this patch, though, as this does _not_ reverse parenthood information.

The "--reverse" flag could possibly be renamed. 
		Linus
---
diff --git a/revision.c b/revision.c
index 7df9089..13a3e40 100644
--- a/revision.c
+++ b/revision.c
@@ -698,6 +698,10 @@ int setup_revisions(int argc, const char
 				revs->topo_order = 1;
 				continue;
 			}
+			if (!strcmp(arg, "--reverse")) {
+				revs->reverse ^= 1;
+				continue;
+			}
 			if (!strcmp(arg, "--parents")) {
 				revs->parents = 1;
 				continue;
@@ -921,7 +925,7 @@ int setup_revisions(int argc, const char
 		add_pending_object(revs, object, def);
 	}
 
-	if (revs->topo_order || revs->unpacked)
+	if (revs->topo_order || revs->unpacked || revs->reverse)
 		revs->limited = 1;
 
 	if (revs->prune_data) {
@@ -941,6 +945,19 @@ int setup_revisions(int argc, const char
 	return left;
 }
 
+static struct commit_list *reverse_commit_list(struct commit_list *p)
+{
+	struct commit_list *result = NULL;
+
+	while (p) {
+		struct commit_list *next = p->next;
+		p->next = result;
+		result = p;
+		p = next;
+	}
+	return result;
+}
+
 void prepare_revision_walk(struct rev_info *revs)
 {
 	int nr = revs->pending.nr;
@@ -968,6 +985,8 @@ void prepare_revision_walk(struct rev_in
 		sort_in_topological_order_fn(&revs->commits, revs->lifo,
 					     revs->topo_setter,
 					     revs->topo_getter);
+	if (revs->reverse)
+		revs->commits = reverse_commit_list(revs->commits);
 }
 
 static int rewrite_one(struct rev_info *revs, struct commit **pp)
diff --git a/revision.h b/revision.h
index c010a08..ff6ce44 100644
--- a/revision.h
+++ b/revision.h
@@ -32,6 +32,7 @@ struct rev_info {
 			remove_empty_trees:1,
 			simplify_history:1,
 			lifo:1,
+			reverse:1,
 			topo_order:1,
 			tag_objects:1,
 			tree_objects:1,
Previous: Randal L. SchwartzNext: Randal L. Schwartz
Message 2 of 11 in “git-log to go forward instead of reverse?”
  1. Randal L. SchwartzJul 10, 2006
  2. Linus TorvaldsJul 10, 2006
  3. Randal L. SchwartzJul 10, 2006
  4. Linus TorvaldsJul 10, 2006
  5. Randal L. SchwartzJul 10, 2006
  6. Linus TorvaldsJul 10, 2006
  7. Randal L. SchwartzJul 10, 2006
  8. Junio C HamanoJul 10, 2006
  9. Junio C HamanoJul 10, 2006
  10. Randal L. SchwartzJul 10, 2006
  11. Linus TorvaldsJul 10, 2006

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.