# [PATCH v2] log: if --decorate is not given, default to --decorate=auto

6 messages from 2017-03-24 to 2017-03-30. Participants: Alex Henrie, Junio C Hamano, Jonathan Nieder, Jeff King.
Thread: https://gitlist.dev/t/45489

## Alex Henrie, 2017-03-24 05:46

Subject: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <20170324054631.21622-1-alexhenrie24@gmail.com>
URL: https://gitlist.dev/e/20170324054631.21622-1-alexhenrie24%40gmail.com

```
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 builtin/log.c  |  9 ++++++++-
 t/t4202-log.sh | 10 +++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 281af8c1e..d755a5960 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -52,6 +52,11 @@ struct line_opt_callback_data {
 	struct string_list args;
 };
 
+static int auto_decoration_style(void)
+{
+	return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
+}
+
 static int parse_decoration_style(const char *var, const char *value)
 {
 	switch (git_config_maybe_bool(var, value)) {
@@ -67,7 +72,7 @@ static int parse_decoration_style(const char *var, const char *value)
 	else if (!strcmp(value, "short"))
 		return DECORATE_SHORT_REFS;
 	else if (!strcmp(value, "auto"))
-		return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
+		return auto_decoration_style();
 	return -1;
 }
 
@@ -405,6 +410,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
 		if (decoration_style < 0)
 			decoration_style = 0; /* maybe warn? */
 		return 0;
+	} else {
+		decoration_style = auto_decoration_style();
 	}
 	if (!strcmp(var, "log.showroot")) {
 		default_show_root = git_config_bool(var, value);
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 48b55bfd2..f57799071 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -4,6 +4,7 @@ test_description='git log'
 
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-gpg.sh"
+. "$TEST_DIRECTORY/lib-terminal.sh"
 
 test_expect_success setup '
 
@@ -520,7 +521,7 @@ test_expect_success 'log --graph with merge' '
 '
 
 test_expect_success 'log.decorate configuration' '
-	git log --oneline >expect.none &&
+	git log --oneline --no-decorate >expect.none &&
 	git log --oneline --decorate >expect.short &&
 	git log --oneline --decorate=full >expect.full &&
 
@@ -576,6 +577,13 @@ test_expect_success 'log.decorate configuration' '
 
 '
 
+test_expect_success TTY 'log output on a TTY' '
+	git log --oneline --decorate >expect.short &&
+
+	test_terminal git log --oneline >actual &&
+	test_cmp expect.short actual
+'
+
 test_expect_success 'reflog is expected format' '
 	git log -g --abbrev-commit --pretty=oneline >expect &&
 	git reflog >actual &&
-- 
2.12.0


```

## Junio C Hamano, 2017-03-24 17:41

Subject: Re: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <xmqq8tnu8te2.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq8tnu8te2.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170324054631.21622-1-alexhenrie24@gmail.com>

```
Alex Henrie <alexhenrie24@gmail.com> writes:

> +test_expect_success TTY 'log output on a TTY' '
> +	git log --oneline --decorate >expect.short &&
> +
> +	test_terminal git log --oneline >actual &&
> +	test_cmp expect.short actual
> +'
> +

Nice.  I didn't know test_terminal was so easy to use ;-)

Looks good.  Will queue.

Thanks.

```

## Jonathan Nieder, 2017-03-24 18:38

Subject: Re: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <20170324183825.GD31294@aiede.mtv.corp.google.com>
URL: https://gitlist.dev/e/20170324183825.GD31294%40aiede.mtv.corp.google.com
In-Reply-To: <20170324054631.21622-1-alexhenrie24@gmail.com>

```
Alex Henrie wrote:

> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
>  builtin/log.c  |  9 ++++++++-
>  t/t4202-log.sh | 10 +++++++++-
>  2 files changed, 17 insertions(+), 2 deletions(-)

Nice.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

```

## Junio C Hamano, 2017-03-30 18:03

Subject: Re: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <xmqqa88263qw.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqa88263qw.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170324183825.GD31294@aiede.mtv.corp.google.com>

```
With the "--decorate=auto" option becoming the default for "git
log", "git tbdiff" will be broken.

The configuration variable has been already there, so in that sense
this is not a new breakage (tbdiff wouldn't have worked well for
those with configured default).  A fix is trivial (attached).

I suspect that Alex's change may uncover similar breakages in
people's scripts.  Perhaps the topic should be cooked a bit longer
than other topics on 'next'?


 git-tbdiff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-tbdiff.py b/git-tbdiff.py
index ccf7a0b..ae7cbb5 100755
--- a/git-tbdiff.py
+++ b/git-tbdiff.py
@@ -75,7 +75,7 @@ def read_patches(rev_list_args):
     series = []
     diffs = {}
     p = subprocess.Popen(['git', 'log', '--no-color', '-p', '--no-merges',
-                          '--reverse', '--date-order']
+                          '--no-decorate', '--reverse', '--date-order']
                          + rev_list_args,
                          stdout=subprocess.PIPE)
     sha1 = None

```

## Jeff King, 2017-03-30 21:33

Subject: Re: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <20170330213358.qjsobjcbons66skf@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170330213358.qjsobjcbons66skf%40sigill.intra.peff.net
In-Reply-To: <xmqqa88263qw.fsf@gitster.mtv.corp.google.com>

```
On Thu, Mar 30, 2017 at 11:03:51AM -0700, Junio C Hamano wrote:

> With the "--decorate=auto" option becoming the default for "git
> log", "git tbdiff" will be broken.
> 
> The configuration variable has been already there, so in that sense
> this is not a new breakage (tbdiff wouldn't have worked well for
> those with configured default).  A fix is trivial (attached).
> 
> I suspect that Alex's change may uncover similar breakages in
> people's scripts.  Perhaps the topic should be cooked a bit longer
> than other topics on 'next'?

I'm confused. I thought "auto" would kick in only when we are outputting
to a terminal. Or is the problem that the "is it a terminal" check is
fooled by $GIT_PAGER_IN_USE, because you are running "git -p tbdiff"?

If so, this is the symptom of a more general problem, which is that
a script outputting to a pager will have confused sub-processes, who do
not know if their pipe is the pager one or not. Perhaps it is time to
resurrect my patch from:

  http://public-inbox.org/git/20150810052353.GB15441@sigill.intra.peff.net/

I think it would need a Windows-specific variant, but the general idea
is sound.

-Peff

PS I've been running git-tbdiff occasionally for years with log.decorate
   set to "true". I wonder why I haven't noticed any problems.

```

## Junio C Hamano, 2017-03-30 21:54

Subject: Re: [PATCH v2] log: if --decorate is not given, default to --decorate=auto
Message-ID: <xmqq1ste2zwu.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq1ste2zwu.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170330213358.qjsobjcbons66skf@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Thu, Mar 30, 2017 at 11:03:51AM -0700, Junio C Hamano wrote:
>
>> With the "--decorate=auto" option becoming the default for "git
>> log", "git tbdiff" will be broken.
>> ...
> I'm confused. I thought "auto" would kick in only when we are outputting
> to a terminal. Or is the problem that the "is it a terminal" check is
> fooled by $GIT_PAGER_IN_USE, because you are running "git -p tbdiff"?

Interesting.  Yes, I do use 

    [pager]
	tbdiff

in my ~/.gitconfig file.

    $ git tbdiff ..@{-1} @{-1}..

is one of the most frequently used commands in my ~/.bash_history
these days [*1*].  I by accident has been running the 'master'
version (not my private edition 'jch' that is a bit ahead of 'next')
for the past few weeks, and I just switched back to using the 'jch'
version so that I can say

    $ git tbdiff ..- -..

instead, and that is when I noticed we broke "tbdiff".

> If so, this is the symptom of a more general problem, which is that
> a script outputting to a pager will have confused sub-processes, who do
> not know if their pipe is the pager one or not. Perhaps it is time to
> resurrect my patch from:
>
>   http://public-inbox.org/git/20150810052353.GB15441@sigill.intra.peff.net/
>
> I think it would need a Windows-specific variant, but the general idea
> is sound.

Yes, that might be necessary.


[Footnote]

*1* The general flow to accept a reroll of a topic "au/topic" goes
    like this:

    $ git checkout au/topic
    $ git log master.. ;# to remind me what it was about
    $ git checkout master... ;# to go back to the original base
    $ Meta/CP ./+au-topic.mbox ;# run checkpatch
    $ git am -s3c
    $ git tbdiff ..@{-1} @{-1}..

    Then if the initial N patches are identical, e.g. when the
    output of tbdiff begins like this:

     1: f6d8dfd8b6 =  1: d681cf5ada do not check odb_mkstemp return value for errors
     2: 52dcad2c2e =  2: abf30edce4 odb_mkstemp: write filename into strbuf
     3: 033d6ae6cb =  3: 38fceca547 odb_mkstemp: use git_path_buf
     4: 55e3179076 !  4: 344267b632 diff: avoid fixed-size buffer for patch-ids
        @@ ... @@

    $ git rebase --onto 033d6ae6cb 38fceca547
    $ git tbdiff ..@{-1} @{-1}..

    That way, I can preserve the author and committer timestamps of
    the earlier part that did not change.

```
