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

[2/4] Sorting commits by date

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Apr 19, 2005, 01:54 UTC
Message-ID
<Pine.LNX.4.21.0504182152000.30848-100000@iabervon.org>
In-Reply-To
<Pine.LNX.4.21.0504182139250.30848-100000@iabervon.org>

Functions for a date-ordered queue of commits, progressively pulled out of the history incrementally. Linus wanted this for finding the most recent common ancestor, and it might be relevant to logging.

Signed-Off-By: Daniel Barkalow <barkalow@iabervon.org>
Index: commit.c
===================================================================
--- b3cf8daf9b619ae9f06a28f42a4ae01b69729206/commit.c  (mode:100644 sha1:0099baa63971d86ee30ef2a7da25057f0f45a964)
+++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/commit.c  (mode:100644 sha1:ef9af397471817837e1799d72f6707e0ccc949b9)
@@ -83,3 +83,47 @@
 		free(temp);
 	}
 }
+
+static void insert_by_date(struct commit_list **list, struct commit *item)
+{
+	struct commit_list **pp = list;
+	struct commit_list *p;
+	while ((p = *pp) != NULL) {
+		if (p->item->date < item->date) {
+			break;
+		}
+		pp = &p->next;
+	}
+	struct commit_list *insert = malloc(sizeof(struct commit_list));
+	insert->next = *pp;
+	*pp = insert;
+	insert->item = item;
+}
+
+	
+void sort_by_date(struct commit_list **list)
+{
+	struct commit_list *ret = NULL;
+	while (*list) {
+		insert_by_date(&ret, (*list)->item);
+		*list = (*list)->next;
+	}
+	*list = ret;
+}
+
+struct commit *pop_most_recent_commit(struct commit_list **list)
+{
+	struct commit *ret = (*list)->item;
+	struct commit_list *parents = ret->parents;
+	struct commit_list *old = *list;
+
+	*list = (*list)->next;
+	free(old);
+
+	while (parents) {
+		parse_commit(parents->item);
+		insert_by_date(list, parents->item);
+		parents = parents->next;
+	}
+	return ret;
+}
Index: commit.h
===================================================================
--- b3cf8daf9b619ae9f06a28f42a4ae01b69729206/commit.h  (mode:100644 sha1:8cd20b046875f5f7e534b0607fdd97f330f53272)
+++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/commit.h  (mode:100644 sha1:35679482132ae5a6b7d72bbb684f21472470717c)
@@ -24,4 +24,8 @@
 
 void free_commit_list(struct commit_list *list);
 
+void sort_by_date(struct commit_list **list);
+
+struct commit *pop_most_recent_commit(struct commit_list **list);
+
 #endif /* COMMIT_H */
Previous: Daniel BarkalowNext: Petr Baudis
Message 5 of 12 in “More patches”
  1. Daniel BarkalowApr 19, 2005
  2. 1/4 Report info from treesDaniel Barkalow, Apr 19, 2005
  3. Junio C HamanoApr 19, 2005
  4. Daniel BarkalowApr 19, 2005
  5. 2/4 Sorting commits by dateDaniel Barkalow, Apr 19, 2005
  6. Petr BaudisApr 19, 2005
  7. David A. WheelerApr 19, 2005
  8. Daniel BarkalowApr 19, 2005
  9. Petr BaudisApr 19, 2005
  10. Daniel BarkalowApr 19, 2005
  11. 3/4 Add http-pullDaniel Barkalow, Apr 19, 2005
  12. 4/4 Make merge-base use dates to find answerDaniel Barkalow, Apr 19, 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.