threads / patch / 34812

patch, 2 partsbranch: improve verbose option

Subject: [PATCH 0/2] branch: improve verbose option

## tl;dr

5 messages between Aug 30, 2013 and Aug 31, 2013. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Felipe Contreras· Aug 30, 2013, 22:59 UTC · lore
Hi,
This has been discussed before:
http://thread.gmane.org/gmane.comp.version-control.git/224489
but in the spirit of the perfect being the enemy of the good, nothing got done.

This series makes 'git branch -v' much faster, and gives us the most important information; the configured upstream tracking branch. Showing ahead/behind is not as important, specially considering that currently 'git branch -v' doesn't show the branch we are comparing the ahead/behind to.

Strictly speaking it's a regression, but nobody would complain, and if somebody does, it should be easy to revert if needed.

Felipe Contreras (2):
  branch: trivial cleanup
  branch: reorganize verbose options
 builtin/branch.c         | 33 +++++++++++++++------------------
 t/t6040-tracking-info.sh |  8 ++++----
 2 files changed, 19 insertions(+), 22 deletions(-)
-- 
1.8.4-fc
Felipe Contreras· Aug 30, 2013, 22:59 UTC · re: Felipe Contreras · lore

[PATCH 1/2] branch: trivial cleanup

No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/branch.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
Show changes to builtin/branch.c +9 −10
diff --git a/builtin/branch.c b/builtin/branch.c
index 0836890..ac17b18 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -425,16 +425,15 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 	struct strbuf fancy = STRBUF_INIT;
 
 	if (!stat_tracking_info(branch, &ours, &theirs)) {
-		if (branch && branch->merge && branch->merge[0]->dst &&
-		    show_upstream_ref) {
-			ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
-			if (want_color(branch_use_color))
-				strbuf_addf(stat, "[%s%s%s] ",
-						branch_get_color(BRANCH_COLOR_UPSTREAM),
-						ref, branch_get_color(BRANCH_COLOR_RESET));
-			else
-				strbuf_addf(stat, "[%s] ", ref);
-		}
+		if (!branch || !branch->merge || !branch->merge[0]->dst || !show_upstream_ref)
+			return;
+		ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
+		if (want_color(branch_use_color))
+			strbuf_addf(stat, "[%s%s%s] ",
+					branch_get_color(BRANCH_COLOR_UPSTREAM),
+					ref, branch_get_color(BRANCH_COLOR_RESET));
+		else
+			strbuf_addf(stat, "[%s] ", ref);
 		return;
 	}
 
-- 
1.8.4-fc
Felipe Contreras· Aug 30, 2013, 22:59 UTC · re: Felipe Contreras · lore

[PATCH 2/2] branch: reorganize verbose options

Showing the upstream tracking branch is more important than how many commits are ahead/behind, so now 'git branch -v' shows the upstream, but not the tracking info, and 'git branch -vv' shows all information (as before).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/branch.c         | 22 ++++++++++------------
 t/t6040-tracking-info.sh |  8 ++++----
 2 files changed, 14 insertions(+), 16 deletions(-)
Show changes to 2 files +14 −16

builtin/branch.c, t/t6040-tracking-info.sh

diff --git a/builtin/branch.c b/builtin/branch.c
index ac17b18..baa1d31 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -417,15 +417,15 @@ static int ref_cmp(const void *r1, const void *r2)
 }
 
 static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
-		int show_upstream_ref)
+		int show_tracking)
 {
 	int ours, theirs;
 	char *ref = NULL;
 	struct branch *branch = branch_get(branch_name);
 	struct strbuf fancy = STRBUF_INIT;
 
-	if (!stat_tracking_info(branch, &ours, &theirs)) {
-		if (!branch || !branch->merge || !branch->merge[0]->dst || !show_upstream_ref)
+	if (!show_tracking || !stat_tracking_info(branch, &ours, &theirs)) {
+		if (!branch || !branch->merge || !branch->merge[0]->dst)
 			return;
 		ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
 		if (want_color(branch_use_color))
@@ -437,15 +437,13 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 		return;
 	}
 
-	if (show_upstream_ref) {
-		ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
-		if (want_color(branch_use_color))
-			strbuf_addf(&fancy, "%s%s%s",
-					branch_get_color(BRANCH_COLOR_UPSTREAM),
-					ref, branch_get_color(BRANCH_COLOR_RESET));
-		else
-			strbuf_addstr(&fancy, ref);
-	}
+	ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
+	if (want_color(branch_use_color))
+		strbuf_addf(&fancy, "%s%s%s",
+				branch_get_color(BRANCH_COLOR_UPSTREAM),
+				ref, branch_get_color(BRANCH_COLOR_RESET));
+	else
+		strbuf_addstr(&fancy, ref);
 
 	if (!ours) {
 		if (ref)
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index ec2b516..86e80eb 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -36,10 +36,10 @@ test_expect_success setup '
 
 script='s/^..\(b.\)[	 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
 cat >expect <<\EOF
-b1 ahead 1, behind 1
-b2 ahead 1, behind 1
-b3 behind 1
-b4 ahead 2
+b1 origin/master
+b2 origin/master
+b3 origin/master
+b4 origin/master
 EOF
 
 test_expect_success 'branch -v' '
-- 
1.8.4-fc
Philip Oakley· Aug 31, 2013, 14:41 UTC · re: Felipe Contreras · lore

Re: [PATCH 0/2] branch: improve verbose option

From: "Felipe Contreras" <felipe.contreras@gmail.com>
Sent: Friday, August 30, 2013 11:59 PM
Show 12 quoted lines
> Hi,
>
> This has been discussed before:
>
> http://thread.gmane.org/gmane.comp.version-control.git/224489
>
> but in the spirit of the perfect being the enemy of the good, nothing 
> got done.
>
> This series makes 'git branch -v' much faster, and gives us the most 
> important
> information; the configured upstream tracking branch.

Yes, It's someting I often want reminding of (which origin server, which master?, ..etc.) always appear to start here.

>        Showing ahead/behind is
> not as important,

I still find this useful - if it's up to date I don't need reminding of which remote / upstream tracking branch it's configured against ;-)

These two bits of information, while related are separate. If anything I think I'd prefer both, but then again optimisations are still good.

Bikeshedding ends.
Philip
Show 16 quoted lines
>    specially considering that currently 'git branch -v' doesn't
> show the branch we are comparing the ahead/behind to.
>
> Strictly speaking it's a regression, but nobody would complain, and if 
> somebody
> does, it should be easy to revert if needed.
>
> Felipe Contreras (2):
>  branch: trivial cleanup
>  branch: reorganize verbose options
>
> builtin/branch.c         | 33 +++++++++++++++------------------
> t/t6040-tracking-info.sh |  8 ++++----
> 2 files changed, 19 insertions(+), 22 deletions(-)
>
> -- 
Felipe Contreras· Aug 31, 2013, 17:24 UTC · re: Philip Oakley · lore

Re: [PATCH 0/2] branch: improve verbose option

On Sat, Aug 31, 2013 at 9:41 AM, Philip Oakley <philipoakley@iee.org> wrote:
> From: "Felipe Contreras" <felipe.contreras@gmail.com>
Show 6 quoted lines
>>        Showing ahead/behind is
>> not as important,
>
>
> I still find this useful - if it's up to date I don't need reminding of
> which remote / upstream tracking branch it's configured against ;-)

Whether or not it's up to date depends on which is the upstream tracking branch. What if you see "ahead 1", and you think it's not up to date, but it turns out it's tracking the wrong branch?

> These two bits of information, while related are separate. If anything I
> think I'd prefer both, but then again optimisations are still good.
So you can keep using 'git branch -vv'.
-- 
Felipe Contreras

← back to recent threads