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

Fix git-rev-list "date order" with --topo-order

From
Linus Torvalds <torvalds@osdl.org>
Date
Nov 14, 2005, 18:01 UTC
Message-ID
<Pine.LNX.4.64.0511140940100.3263@g5.osdl.org>
In-Reply-To
<pan.2005.11.14.04.36.38.784541@smurf.noris.de>

This fixes git-rev-list so that when there are multiple branches, we still sort the heads in proper approximate date order even when sorting the output topologically.

This makes things like
	gitk --all -d

work sanely and show the branches in date order (where "date order" is obviously modified by the paren-child dependency requirements of the topological sort).

The trivial fix is to just build the "work" list in date order rather than inserting the new work entries at the beginning.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
This should also fix this report, although Matthias should double-test..
On Mon, 14 Nov 2005, Matthias Urlichs wrote:
Show 11 quoted lines
> 
> >           $ gitk $(cd .git/lost+found/commit && echo ??*)
> 
> Along those lines... I just tried that, it found a whole heap of old
> commits I didn't yet clean up, and they're sorted by their SHA1.
> 
> In other words, actually finding the latest commit in there was a
> nontrivial task.
> 
> I don't speak tcl, so could somebody please change "gitk -d" to sort its
> command line by date (newest first, of course)?  Thanks.
diff --git a/commit.c b/commit.c
index 534c03e..ebf4db6 100644
--- a/commit.c
+++ b/commit.c
@@ -536,7 +536,7 @@ int count_parents(struct commit * commit
 void sort_in_topological_order(struct commit_list ** list)
 {
 	struct commit_list * next = *list;
-	struct commit_list * work = NULL;
+	struct commit_list * work = NULL, **insert;
 	struct commit_list ** pptr = list;
 	struct sort_node * nodes;
 	struct sort_node * next_nodes;
@@ -580,11 +580,12 @@ void sort_in_topological_order(struct co
          * the tips serve as a starting set for the work queue.
          */
 	next=*list;
+	insert = &work;
 	while (next) {
 		struct sort_node * node = (struct sort_node *)next->item->object.util;
 
 		if (node->indegree == 0) {
-			commit_list_insert(next->item, &work);
+			insert = &commit_list_insert(next->item, insert)->next;
 		}
 		next=next->next;
 	}
Previous: Matthias Urlichs
Message 9 of 9 in “Regarding: git-lost+found”
  1. Johannes SchindelinNov 8, 2005
  2. Petr BaudisNov 8, 2005
  3. Petr BaudisNov 8, 2005
  4. Junio C HamanoNov 9, 2005
  5. Daniel BarkalowNov 9, 2005
  6. Junio C HamanoNov 9, 2005
  7. Daniel BarkalowNov 10, 2005
  8. Matthias UrlichsNov 14, 2005
  9. Fix git-rev-list "date order" with --topo-orderLinus Torvalds, Nov 14, 2005

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.