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

2017-03-30 Thread Junio C Hamano
Jeff King  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.gb15...@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.


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

2017-03-30 Thread Jeff King
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.gb15...@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.


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

2017-03-30 Thread Junio C Hamano
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


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

2017-03-24 Thread Jonathan Nieder
Alex Henrie wrote:

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

Nice.

Reviewed-by: Jonathan Nieder 


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

2017-03-24 Thread Junio C Hamano
Alex Henrie  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.


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

2017-03-23 Thread Alex Henrie
Signed-off-by: Alex Henrie 
---
 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