# [PATCH] Reformat "your branch has diverged..." lines to reduce line length.

4 messages from 2008-07-16 to 2008-07-16. Participants: Avery Pennarun, Junio C Hamano.
Thread: https://gitlist.dev/t/14490

## Avery Pennarun, 2008-07-16 19:19

Subject: [PATCH] Reformat "your branch has diverged..." lines to reduce line length.
Message-ID: <1216235967-9510-1-git-send-email-apenwarr@gmail.com>
URL: https://gitlist.dev/e/1216235967-9510-1-git-send-email-apenwarr%40gmail.com

```
The message length depends on the length of the branch name.  In my case,
the branch name "origin/add-chickens2" put the first line of the "your
branch has diverged" message over 80 characters, which triggered "less -FS"
to not exit automatically as expected.

This patch puts the newlines in slightly different places to reduce the
probability of this happening.  Now you'd need a significantly longer
branch name to trigger the problem.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
---
 remote.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
 
I suppose a full-on automatic wordwrapper would be nicer :)
 

diff --git a/remote.c b/remote.c
index df8bd72..4f32032 100644
--- a/remote.c
+++ b/remote.c
@@ -1321,19 +1321,19 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 		remote_msg = "";
 	}
 	if (!num_theirs)
-		strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s' "
+		strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s'\n"
 			    "by %d commit%s.\n",
 			    remote_msg, base,
 			    num_ours, (num_ours == 1) ? "" : "s");
 	else if (!num_ours)
-		strbuf_addf(sb, "Your branch is behind the tracked%s branch '%s' "
-			    "by %d commit%s,\n"
+		strbuf_addf(sb, "Your branch is behind the tracked%s branch '%s'\n"
+			    "by %d commit%s, "
 			    "and can be fast-forwarded.\n",
 			    remote_msg, base,
 			    num_theirs, (num_theirs == 1) ? "" : "s");
 	else
-		strbuf_addf(sb, "Your branch and the tracked%s branch '%s' "
-			    "have diverged,\nand respectively "
+		strbuf_addf(sb, "Your branch and the tracked%s branch '%s'\n"
+			    "have diverged, and respectively "
 			    "have %d and %d different commit(s) each.\n",
 			    remote_msg, base,
 			    num_ours, num_theirs);
-- 
1.5.6.3.385.g94745

```

## Junio C Hamano, 2008-07-16 19:48

Subject: Re: [PATCH] Reformat "your branch has diverged..." lines to reduce line length.
Message-ID: <7v4p6pr4ob.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4p6pr4ob.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1216235967-9510-1-git-send-email-apenwarr@gmail.com>

```
Avery Pennarun <apenwarr@gmail.com> writes:

>  	if (!num_theirs)
> -		strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s' "
> +		strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s'\n"
>  			    "by %d commit%s.\n",

I wonder if a simple "s/of the tracked%s branch //" is better for this
kind of thing.  If the message says 'origin/master', you know it is a
tracked remote branch anyway, don't you?

Too wide is bad, but too tall is worse.  Some of us still work in 80x24
;-) and I prefer to make the message succinct when possible, rather than
keeping it long and spread over multiple lines.

>  	else
> -		strbuf_addf(sb, "Your branch and the tracked%s branch '%s' "
> -			    "have diverged,\nand respectively "
> +		strbuf_addf(sb, "Your branch and the tracked%s branch '%s'\n"
> +			    "have diverged, and respectively "
>  			    "have %d and %d different commit(s) each.\n",

This does not make the message taller, but if we were to make the "only
one side advanced" cases shorter, we would need to reword this to be
consistent.  Perhaps something like this would be just as easy to read and
more compact?

	Your branch is ahead of 'origin/add-chickens2' by 21 commits.

        Your branch is behind 'origin/add-chickens2' by 1 commit.

        Your branch and 'origin/add-chickens2' have diverged, and have
        21 and 1 different commit(s) each, respectively.

I moved "respectively" so that the variable parts will come close to the
beginning of physical line.

```

## Avery Pennarun, 2008-07-16 20:27

Subject: Re: [PATCH] Reformat "your branch has diverged..." lines to reduce line length.
Message-ID: <32541b130807161327k17f3a58ay5ab2da75963a2d50@mail.gmail.com>
URL: https://gitlist.dev/e/32541b130807161327k17f3a58ay5ab2da75963a2d50%40mail.gmail.com
In-Reply-To: <7v4p6pr4ob.fsf@gitster.siamese.dyndns.org>

```
On 7/16/08, Junio C Hamano <gitster@pobox.com> wrote:
> Avery Pennarun <apenwarr@gmail.com> writes:
>  >       if (!num_theirs)
>  > -             strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s' "
>  > +             strbuf_addf(sb, "Your branch is ahead of the tracked%s branch '%s'\n"
>  >                           "by %d commit%s.\n",
>
>  I wonder if a simple "s/of the tracked%s branch //" is better for this
>  kind of thing.  If the message says 'origin/master', you know it is a
>  tracked remote branch anyway, don't you?

Personally, I would be fine with shorter messages; this doesn't seem
the best time to
report the name of the tracked branch anyhow.  I use 80x24 terminals
too most of the time.

However, I didn't write the original patch either, and I recall that
this feature was so popular that it actually resulted in a list thread
complimenting it, so I was hesitant to change it too much :)

>         Your branch is ahead of 'origin/add-chickens2' by 21 commits.
>
>         Your branch is behind 'origin/add-chickens2' by 1 commit.
>
>         Your branch and 'origin/add-chickens2' have diverged, and have
>         21 and 1 different commit(s) each, respectively.
>
>  I moved "respectively" so that the variable parts will come close to the
>  beginning of physical line.

Well, the fact that the number of commits is "variable" isn't so
important, unless you start diverging by 1e9 commits or something :)
It might be nice to minimize the amount of static text on the line
containing the branch name, though.  Your rephrasing would allow us to
go as far as:

    Your branch and 'origin/add-chickens2'
    have diverged, and have 21 and 1 different commit(s) each, respectively.

Which looks a little imbalanced, but works with long branch names.

Alternatively, your rephrasing above made me think of the idea of just
printing *both* of the first two messages in the "diverging" case.
Depending how you think of it, that would be either more clear or less
clear.  It's actually easier to parse the two short sentences than the
long one.

Please let me know if you want me to resubmit the patch with your
suggestions or whether you'll handle it.  I'm still a little vague on
the exact patch approval process.

Have fun,

Avery

```

## Junio C Hamano, 2008-07-16 22:03

Subject: Re: [PATCH] Reformat "your branch has diverged..." lines to reduce line length.
Message-ID: <7v3am9pjvf.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v3am9pjvf.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <32541b130807161327k17f3a58ay5ab2da75963a2d50@mail.gmail.com>

```
"Avery Pennarun" <apenwarr@gmail.com> writes:

>>         Your branch is ahead of 'origin/add-chickens2' by 21 commits.
>>
>>         Your branch is behind 'origin/add-chickens2' by 1 commit.
>>
>>         Your branch and 'origin/add-chickens2' have diverged, and have
>>         21 and 1 different commit(s) each, respectively.
>>
>>  I moved "respectively" so that the variable parts will come close to the
>>  beginning of physical line.
>
> Well, the fact that the number of commits is "variable" isn't so
> important, unless you start diverging by 1e9 commits or something :)

No, no, no.  The point is not about keeping it on screen when "less -S"
chops at the right end.  The point is to limit eye-movement of the user;
i.e. presenting important information consistently at around the same
column, closer to the left edge.  Probably the line break should be before
"and have" to make it even easier to read.

>>         Your branch and 'origin/add-chickens2' have diverged,
>>         and have 21 and 1 different commit(s) each, respectively.

> Alternatively, your rephrasing above made me think of the idea of just
> printing *both* of the first two messages in the "diverging" case.

I do not think it is such a good idea --- we invite silly comments like
"You say X is ahead of Y, and X is behind of Y, which is true?".

> Please let me know if you want me to resubmit the patch with your
> suggestions or whether you'll handle it.  I'm still a little vague on
> the exact patch approval process.

It is very much more "consensus building" than "approval", and at this
point we wait for a day or two to see if people come up with even better
alternatives.  Just be kind enough to prod me if I forget after a few
days, though ;-)

```
