[PATCH 3/4] Default to displaying /all/ non-tag refs, not just locals

Subsystems: the rest

STALE3679d

4 messages, 3 authors, 2016-08-11 · open the first message on its own page

[PATCH 3/4] Default to displaying /all/ non-tag refs, not just locals

From: Andy Parkins <hidden>
Date: 2016-08-11 19:32:59

Adds support for display_mode == 2; which shows all non-tag refs.  I've set
display_mode = 2 by default so it's easily reverted if needed - or if a switch
for the old mode is wanted it can be easily added

Signed-off-by: Andy Parkins <redacted>
---
 builtin-branch.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 85b7007..b88413a 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -104,20 +104,38 @@ static void print_ref_list(int display_m
 {
 	int i;
 	char c;
+	char *p;
 
-	if (display_mode)
-		for_each_remote_ref(append_ref, NULL);
-	else
-		for_each_branch_ref(append_ref, NULL);
+	switch (display_mode) {
+		case 0:
+			for_each_branch_ref(append_ref, NULL);
+			break;
+		case 1:
+			for_each_remote_ref(append_ref, NULL);
+			break;
+		case 2:
+			for_each_ref(append_ref, NULL);
+			break;
+	}
 
 	qsort(ref_list, ref_index, sizeof(char *), ref_cmp);
 
 	for (i = 0; i < ref_index; i++) {
+		p = ref_list[i];
+		if (display_mode == 2) {
+			if (!strncmp( p, "refs/", 5 ))
+				p += 5;
+			if (!strncmp( p, "tags/", 5 ))
+				continue;
+			if (!strncmp( p, "heads/", 6 ))
+				p += 6;
+		}
+
 		c = ' ';
-		if (!strcmp(ref_list[i], head))
+		if (!strcmp(p, head))
 			c = '*';
 
-		printf("%c %s\n", c, ref_list[i]);
+		printf("%c %s\n", c, p);
 	}
 }
 
@@ -160,7 +178,7 @@ static void create_branch(const char *na
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
 {
-	int delete = 0, force_delete = 0, force_create = 0, display_mode = 0;
+	int delete = 0, force_delete = 0, force_create = 0, display_mode = 2;
 	int reflog = 0;
 	int i;
 
-- 
1.4.3.2

Re: [PATCH 3/4] Default to displaying /all/ non-tag refs, not just locals

From: Junio C Hamano <hidden>
Date: 2016-08-11 19:33:19

Andy Parkins [off-list ref] writes:
Adds support for display_mode == 2; which shows all non-tag refs.
That is a change in behaviour and given that we introduced
remotes for the explicit purpose of not to clutter the local
branch namespace, I doubt defaulting to _show_ remotes is a good
change.  See the 'bitfield' comment in my other reply.

Re: [PATCH 3/4] Default to displaying /all/ non-tag refs, not just locals

From: Andy Parkins <hidden>
Date: 2016-08-11 19:47:15

On Friday 2006 November 03 02:40, Junio C Hamano wrote:
That is a change in behaviour and given that we introduced
remotes for the explicit purpose of not to clutter the local
branch namespace, I doubt defaulting to _show_ remotes is a good
Really?  I had imagined it was to prevent accidental checking out of an 
upstream-tracking branch.  Also; I don't think "not cluttering the namespace" 
is the same as "not showing multiple namespaces".  The local namespace 
remains as uncluttered as it ever was.  This is a question of what to 
display.

Assuming my "mixed mode" display thing were in place, doesn't that make the 
two choices of UI

1)
 git-branch            : show local branches
 git-branch --all      : show local and remote branches
 git-branch -r         : show remote branches
2)
 git-branch            : show local and remote branches
 git-branch --local    : show local branches
 git-branch -r         : show remote branches

In case 2) the switch is simply selecting a filter, and so fits in with 
the "-r" better.



Andy

-- 
Dr Andy Parkins, M Eng (hons), MIEE

Re: [PATCH 3/4] Default to displaying /all/ non-tag refs, not just locals

From: Andreas Ericsson <hidden>
Date: 2016-08-11 20:17:17

Andy Parkins wrote:
On Friday 2006 November 03 02:40, Junio C Hamano wrote:
quoted
That is a change in behaviour and given that we introduced
remotes for the explicit purpose of not to clutter the local
branch namespace, I doubt defaulting to _show_ remotes is a good
Really?  I had imagined it was to prevent accidental checking out of an 
upstream-tracking branch.  Also; I don't think "not cluttering the namespace" 
is the same as "not showing multiple namespaces".  The local namespace 
remains as uncluttered as it ever was.  This is a question of what to 
display.

Assuming my "mixed mode" display thing were in place, doesn't that make the 
two choices of UI

1)
 git-branch            : show local branches
 git-branch --all      : show local and remote branches
 git-branch -r         : show remote branches
2)
 git-branch            : show local and remote branches
 git-branch --local    : show local branches
 git-branch -r         : show remote branches

In case 2) the switch is simply selecting a filter, and so fits in with 
the "-r" better.
I think it'd make more sense if git-branch could instead take a --filter 
parameter that does a simple strncmp(filter, branch, strlen(filter)) to 
see if it should show a branch or not. That way, "--filter=remotes" 
would work splendidly. "local" as keyword to "--filter" could possibly 
be a special case and need documentation.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help