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

5 messages from 2013-08-30 to 2013-08-31. Participants: Felipe Contreras, Philip Oakley.
Thread: https://gitlist.dev/t/34812

## Felipe Contreras, 2013-08-30 22:59

Subject: [PATCH 0/2] branch: improve verbose option
Message-ID: <1377903583-3550-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1377903583-3550-1-git-send-email-felipe.contreras%40gmail.com

```
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, 2013-08-30 22:59

Subject: [PATCH 1/2] branch: trivial cleanup
Message-ID: <1377903583-3550-2-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1377903583-3550-2-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1377903583-3550-1-git-send-email-felipe.contreras@gmail.com>

```
No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/branch.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

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, 2013-08-30 22:59

Subject: [PATCH 2/2] branch: reorganize verbose options
Message-ID: <1377903583-3550-3-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1377903583-3550-3-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1377903583-3550-1-git-send-email-felipe.contreras@gmail.com>

```
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(-)

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, 2013-08-31 14:41

Subject: Re: [PATCH 0/2] branch: improve verbose option
Message-ID: <CD323DA08A0540A89D9BFB28F541AFB4@PhilipOakley>
URL: https://gitlist.dev/e/CD323DA08A0540A89D9BFB28F541AFB4%40PhilipOakley
In-Reply-To: <1377903583-3550-1-git-send-email-felipe.contreras@gmail.com>

```
From: "Felipe Contreras" <felipe.contreras@gmail.com>
Sent: Friday, August 30, 2013 11:59 PM
> 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

>    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, 2013-08-31 17:24

Subject: Re: [PATCH 0/2] branch: improve verbose option
Message-ID: <CAMP44s00qUjqR6Daiy_3_hONuSBkxY99xaxCdbKyBM-t84Q0=w@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s00qUjqR6Daiy_3_hONuSBkxY99xaxCdbKyBM-t84Q0%3Dw%40mail.gmail.com
In-Reply-To: <CD323DA08A0540A89D9BFB28F541AFB4@PhilipOakley>

```
On Sat, Aug 31, 2013 at 9:41 AM, Philip Oakley <philipoakley@iee.org> wrote:
> From: "Felipe Contreras" <felipe.contreras@gmail.com>

>>        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

```
