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

[RFC/PATCH] branch: show me the hot branches

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 13, 2013, 20:02 UTC
Message-ID
<1368475365-18680-1-git-send-email-artagnon@gmail.com>
Uses commit->date to sort displayed refs.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Just had this idea and wrote it down in five minutes.  The
 implementation is only meant to be indicative.
 Isn't this awesome?
 builtin/branch.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 0836890..8b08563 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -59,6 +59,11 @@ static enum merge_filter {
 } merge_filter;
 static unsigned char merge_filter_ref[20];
 
+static enum sort_strategy {
+	LEXICAL = 0,
+	DATE,
+} sort_strategy;
+
 static struct string_list output = STRING_LIST_INIT_DUP;
 static unsigned int colopts;
 
@@ -406,7 +411,7 @@ static void free_ref_list(struct ref_list *ref_list)
 	free(ref_list->list);
 }
 
-static int ref_cmp(const void *r1, const void *r2)
+static int ref_cmp_lexical(const void *r1, const void *r2)
 {
 	struct ref_item *c1 = (struct ref_item *)(r1);
 	struct ref_item *c2 = (struct ref_item *)(r2);
@@ -416,6 +421,16 @@ static int ref_cmp(const void *r1, const void *r2)
 	return strcmp(c1->name, c2->name);
 }
 
+static int ref_cmp_date(const void *r1, const void *r2)
+{
+	struct ref_item *c1 = (struct ref_item *)(r1);
+	struct ref_item *c2 = (struct ref_item *)(r2);
+
+	if (c1->kind != c2->kind)
+		return c1->kind - c2->kind;
+	return c1->commit->date < c2->commit->date;
+}
+
 static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 		int show_upstream_ref)
 {
@@ -621,7 +636,6 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 
 	memset(&ref_list, 0, sizeof(ref_list));
 	ref_list.kinds = kinds;
-	ref_list.verbose = verbose;
 	ref_list.abbrev = abbrev;
 	ref_list.with_commit = with_commit;
 	if (merge_filter != NO_FILTER)
@@ -629,7 +643,14 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 	cb.ref_list = &ref_list;
 	cb.pattern = pattern;
 	cb.ret = 0;
+
+	if (sort_strategy == DATE && verbose < 1)
+		ref_list.verbose = 1;
+	else
+		ref_list.verbose = verbose;
 	for_each_rawref(append_ref, &cb);
+	ref_list.verbose = verbose;
+
 	if (merge_filter != NO_FILTER) {
 		struct commit *filter;
 		filter = lookup_commit_reference_gently(merge_filter_ref, 0);
@@ -646,7 +667,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 			ref_list.maxwidth = calc_maxwidth(&ref_list);
 	}
 
-	qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
+	if (sort_strategy == DATE)
+		qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp_date);
+	else
+		qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp_lexical);
 
 	detached = (detached && (kinds & REF_LOCAL_BRANCH));
 	if (detached && match_patterns(pattern, "HEAD"))
@@ -843,6 +867,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT_END(),
 	};
 
+	sort_strategy = DATE;
+
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage_with_options(builtin_branch_usage, options);
 
-- 
1.8.3.rc1.49.g8d97506.dirty
Next: Phil Hord
Message 1 of 6 in “branch: show me the hot branches”
  1. branch: show me the hot branchesRamkumar Ramachandra, May 13, 2013
  2. Phil HordMay 14, 2013
  3. Junio C HamanoMay 14, 2013
  4. Phil HordMay 15, 2013
  5. Duy NguyenMay 15, 2013
  6. Ramkumar RamachandraMay 16, 2013

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.