git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC/PATCH] branch: show me the hot branches
@ 2013-05-13 20:02 Ramkumar Ramachandra
  2013-05-14 23:19 ` Phil Hord
  2013-05-15  0:08 ` Duy Nguyen
  0 siblings, 2 replies; 6+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-13 20:02 UTC (permalink / raw
  To: Git List

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH] branch: show me the hot branches
  2013-05-13 20:02 [RFC/PATCH] branch: show me the hot branches Ramkumar Ramachandra
@ 2013-05-14 23:19 ` Phil Hord
  2013-05-14 23:34   ` Junio C Hamano
  2013-05-15  0:08 ` Duy Nguyen
  1 sibling, 1 reply; 6+ messages in thread
From: Phil Hord @ 2013-05-14 23:19 UTC (permalink / raw
  To: Ramkumar Ramachandra; +Cc: Git List

On Mon, May 13, 2013 at 4:02 PM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Uses commit->date to sort displayed refs.
>
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---

I dig it.

I imagine it with --date-order and whatnot.  But I might like it even
better if it were reverse-sorted.  Maybe it needs -rt for that. ;-)

Phil

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH] branch: show me the hot branches
  2013-05-14 23:19 ` Phil Hord
@ 2013-05-14 23:34   ` Junio C Hamano
  2013-05-15 12:54     ` Phil Hord
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2013-05-14 23:34 UTC (permalink / raw
  To: Phil Hord; +Cc: Ramkumar Ramachandra, Git List

Phil Hord <phil.hord@gmail.com> writes:

> I imagine it with --date-order and whatnot.

Perhaps modeled after this one.

    git for-each-ref \
        --format='%(refname:short) %(subject)'
        --sort='-committerdate' refs/heads/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH] branch: show me the hot branches
  2013-05-13 20:02 [RFC/PATCH] branch: show me the hot branches Ramkumar Ramachandra
  2013-05-14 23:19 ` Phil Hord
@ 2013-05-15  0:08 ` Duy Nguyen
  2013-05-16 13:58   ` Ramkumar Ramachandra
  1 sibling, 1 reply; 6+ messages in thread
From: Duy Nguyen @ 2013-05-15  0:08 UTC (permalink / raw
  To: Ramkumar Ramachandra; +Cc: Git List

On Tue, May 14, 2013 at 3:02 AM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> 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?

I tried a more generic approach a while ago.

http://thread.gmane.org/gmane.comp.version-control.git/188705
--
Duy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH] branch: show me the hot branches
  2013-05-14 23:34   ` Junio C Hamano
@ 2013-05-15 12:54     ` Phil Hord
  0 siblings, 0 replies; 6+ messages in thread
From: Phil Hord @ 2013-05-15 12:54 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Ramkumar Ramachandra, Git List, Nguyen Thai Ngoc Duy

On Tue, May 14, 2013 at 7:34 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Phil Hord <phil.hord@gmail.com> writes:
>
>> I imagine it with --date-order and whatnot.
>
> Perhaps modeled after this one.
>
>     git for-each-ref \
>         --format='%(refname:short) %(subject)'
>         --sort='-committerdate' refs/heads/
>

Nice.  I had no idea about for-each-ref.  I knew it was out there, but
not what it could do.  Another tool in the swiss army knife that is
git.

I think Duy was right about his patch's merits.

Phil

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH] branch: show me the hot branches
  2013-05-15  0:08 ` Duy Nguyen
@ 2013-05-16 13:58   ` Ramkumar Ramachandra
  0 siblings, 0 replies; 6+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-16 13:58 UTC (permalink / raw
  To: Duy Nguyen; +Cc: Git List

Duy Nguyen wrote:
> I tried a more generic approach a while ago.
>
> http://thread.gmane.org/gmane.comp.version-control.git/188705

Looks good.  Why didn't you polish it for inclusion?

It's a very useful feature in my opinion: the default git branch
output is quite horrible.  I want to make sort, count, and verbosity
(poorly chosen name?) configuration variables.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-16 13:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-13 20:02 [RFC/PATCH] branch: show me the hot branches Ramkumar Ramachandra
2013-05-14 23:19 ` Phil Hord
2013-05-14 23:34   ` Junio C Hamano
2013-05-15 12:54     ` Phil Hord
2013-05-15  0:08 ` Duy Nguyen
2013-05-16 13:58   ` Ramkumar Ramachandra

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).