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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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,
-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]