threads / patch / 45489

v2log: if --decorate is not given, default to --decorate=auto

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

## tl;dr

6 messages between Mar 24, 2017 and Mar 30, 2017. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Alex Henrie· Mar 24, 2017, 05:46 UTC · lore
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 builtin/log.c  |  9 ++++++++-
 t/t4202-log.sh | 10 +++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
Show changes to 2 files +17 −2

builtin/log.c, t/t4202-log.sh

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· Mar 24, 2017, 17:41 UTC · re: Alex Henrie · lore

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

Alex Henrie <alexhenrie24@gmail.com> writes:
Show 7 quoted lines
> +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· Mar 24, 2017, 18:38 UTC · re: Alex Henrie · lore

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

Alex Henrie wrote:
Show 5 quoted lines
> 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· Mar 30, 2017, 18:03 UTC · re: Jonathan Nieder · lore

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

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(-)
Show changes to git-tbdiff.py +1 −1
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· Mar 30, 2017, 21:33 UTC · re: Junio C Hamano · lore

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

On Thu, Mar 30, 2017 at 11:03:51AM -0700, Junio C Hamano wrote:
Show 10 quoted lines
> 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· Mar 30, 2017, 21:54 UTC · re: Jeff King · lore

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

Jeff King <peff@peff.net> writes:
Show 8 quoted lines
> 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".
Show 9 quoted lines
> 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.

← back to recent threads