git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] branch: fix --verbose output column alignment
@ 2013-11-14 18:18 Torstein Hegge
  2013-11-15  1:45 ` Jiang Xin
  2013-11-18 19:27 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Torstein Hegge @ 2013-11-14 18:18 UTC (permalink / raw
  To: git; +Cc: Jiang Xin, Matthieu Moy, Junio C Hamano, Torstein Hegge

Commit f2e0873 (branch: report invalid tracking branch as gone) removed
an early return from fill_tracking_info() in the path taken when 'git
branch -v' lists a branch in sync with its upstream. This resulted in an
unconditionally added space in front of the subject line:

    $ git branch -v
    * master f5eb3da  commit pushed to upstream
      topic  f935eb6 unpublished topic

Instead, only add the trailing space if a decoration have been added.

To catch this kind of whitespace breakage in the tests, be a bit less
smart when filtering the output through sed.

Signed-off-by: Torstein Hegge <hegge@resisty.net>
---
 builtin/branch.c         |  8 +++++++-
 t/t6040-tracking-info.sh | 24 +++++++++++++-----------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0bb0e93..636a16e 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -424,6 +424,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 	struct branch *branch = branch_get(branch_name);
 	struct strbuf fancy = STRBUF_INIT;
 	int upstream_is_gone = 0;
+	int added_decoration = 1;
 
 	switch (stat_tracking_info(branch, &ours, &theirs)) {
 	case 0:
@@ -451,9 +452,13 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 	if (upstream_is_gone) {
 		if (show_upstream_ref)
 			strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
+		else
+			added_decoration = 0;
 	} else if (!ours && !theirs) {
 		if (show_upstream_ref)
 			strbuf_addf(stat, _("[%s]"), fancy.buf);
+		else
+			added_decoration = 0;
 	} else if (!ours) {
 		if (show_upstream_ref)
 			strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
@@ -474,7 +479,8 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 				    ours, theirs);
 	}
 	strbuf_release(&fancy);
-	strbuf_addch(stat, ' ');
+	if (added_decoration)
+		strbuf_addch(stat, ' ');
 	free(ref);
 }
 
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index ba26cfe..7ac8fd0 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -39,12 +39,14 @@ test_expect_success setup '
 	advance h
 '
 
-script='s/^..\(b.\)[	 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
+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 [ahead 1, behind 1] d
+b2 [ahead 1, behind 1] d
+b3 [behind 1] b
+b4 [ahead 2] f
+b5 g
+b6 c
 EOF
 
 test_expect_success 'branch -v' '
@@ -57,12 +59,12 @@ test_expect_success 'branch -v' '
 '
 
 cat >expect <<\EOF
-b1 origin/master: ahead 1, behind 1
-b2 origin/master: ahead 1, behind 1
-b3 origin/master: behind 1
-b4 origin/master: ahead 2
-b5 brokenbase: gone
-b6 origin/master
+b1 [origin/master: ahead 1, behind 1] d
+b2 [origin/master: ahead 1, behind 1] d
+b3 [origin/master: behind 1] b
+b4 [origin/master: ahead 2] f
+b5 [brokenbase: gone] g
+b6 [origin/master] c
 EOF
 
 test_expect_success 'branch -vv' '
-- 
1.8.5.rc0.216.ge00de29

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

* Re: [PATCH] branch: fix --verbose output column alignment
  2013-11-14 18:18 [PATCH] branch: fix --verbose output column alignment Torstein Hegge
@ 2013-11-15  1:45 ` Jiang Xin
  2013-11-18 19:27 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Jiang Xin @ 2013-11-15  1:45 UTC (permalink / raw
  To: Torstein Hegge; +Cc: Git List, Matthieu Moy, Junio C Hamano

2013/11/15 Torstein Hegge <hegge@resisty.net>:
> Commit f2e0873 (branch: report invalid tracking branch as gone) removed
> an early return from fill_tracking_info() in the path taken when 'git
> branch -v' lists a branch in sync with its upstream. This resulted in an
> unconditionally added space in front of the subject line:
>
>     $ git branch -v
>     * master f5eb3da  commit pushed to upstream
>       topic  f935eb6 unpublished topic

Thank you for catching this. Confirmed that the output of "git branch -v"
is not aligned well. This example may be more clear ;-)

    $ git branch -v
     branch1    f0ec0da [ahead 1, behind 2] divert from upstream
     branch2    f5eb3da  commit pushed to upstream
     branch3    f935eb6 unpublished topic

>
> Instead, only add the trailing space if a decoration have been added.
>
> To catch this kind of whitespace breakage in the tests, be a bit less
> smart when filtering the output through sed.
>
> Signed-off-by: Torstein Hegge <hegge@resisty.net>
> ---
>  builtin/branch.c         |  8 +++++++-
>  t/t6040-tracking-info.sh | 24 +++++++++++++-----------
>  2 files changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index 0bb0e93..636a16e 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -424,6 +424,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
>         struct branch *branch = branch_get(branch_name);
>         struct strbuf fancy = STRBUF_INIT;
>         int upstream_is_gone = 0;
> +       int added_decoration = 1;
>
>         switch (stat_tracking_info(branch, &ours, &theirs)) {
>         case 0:
> @@ -451,9 +452,13 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
>         if (upstream_is_gone) {
>                 if (show_upstream_ref)
>                         strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
> +               else
> +                       added_decoration = 0;
>         } else if (!ours && !theirs) {
>                 if (show_upstream_ref)
>                         strbuf_addf(stat, _("[%s]"), fancy.buf);
> +               else
> +                       added_decoration = 0;
>         } else if (!ours) {
>                 if (show_upstream_ref)
>                         strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
> @@ -474,7 +479,8 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
>                                     ours, theirs);
>         }
>         strbuf_release(&fancy);
> -       strbuf_addch(stat, ' ');
> +       if (added_decoration)
> +               strbuf_addch(stat, ' ');
>         free(ref);
>  }
>

How about add "strbuf_addch(stat, ' ');" to each condition directly,  like this:


        if (upstream_is_gone) {
                if (show_upstream_ref) {
                        strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
                        strbuf_addch(stat, ' ');
                }
        } else if (!ours && !theirs) {
                if (show_upstream_ref) {
                        strbuf_addf(stat, _("[%s]"), fancy.buf);
                        strbuf_addch(stat, ' ');
                }
        } else if (!ours) {
                if (show_upstream_ref)
                        strbuf_addf(stat, _("[%s: behind %d]"),
fancy.buf, theirs);
                else
                        strbuf_addf(stat, _("[behind %d]"), theirs);
                strbuf_addch(stat, ' ');
        } else if (!theirs) {
                if (show_upstream_ref)
                        strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours);
                else
                        strbuf_addf(stat, _("[ahead %d]"), ours);
                strbuf_addch(stat, ' ');
        } else {
                if (show_upstream_ref)
                        strbuf_addf(stat, _("[%s: ahead %d, behind %d]"),
                                    fancy.buf, ours, theirs);
                else
                        strbuf_addf(stat, _("[ahead %d, behind %d]"),
                                    ours, theirs);
                strbuf_addch(stat, ' ');
        }
        strbuf_release(&fancy);
        free(ref);


-- 
Jiang Xin

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

* Re: [PATCH] branch: fix --verbose output column alignment
  2013-11-14 18:18 [PATCH] branch: fix --verbose output column alignment Torstein Hegge
  2013-11-15  1:45 ` Jiang Xin
@ 2013-11-18 19:27 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2013-11-18 19:27 UTC (permalink / raw
  To: Torstein Hegge; +Cc: git, Jiang Xin, Matthieu Moy

Torstein Hegge <hegge@resisty.net> writes:

> Commit f2e0873 (branch: report invalid tracking branch as gone) removed
> an early return from fill_tracking_info() in the path taken when 'git
> branch -v' lists a branch in sync with its upstream. This resulted in an
> unconditionally added space in front of the subject line:
>
>     $ git branch -v
>     * master f5eb3da  commit pushed to upstream
>       topic  f935eb6 unpublished topic
>
> Instead, only add the trailing space if a decoration have been added.
>
> To catch this kind of whitespace breakage in the tests, be a bit less
> smart when filtering the output through sed.
>
> Signed-off-by: Torstein Hegge <hegge@resisty.net>
> ---

Thanks.

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

end of thread, other threads:[~2013-11-18 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-14 18:18 [PATCH] branch: fix --verbose output column alignment Torstein Hegge
2013-11-15  1:45 ` Jiang Xin
2013-11-18 19:27 ` Junio C Hamano

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