git show and the --quiet option
Hello everyone,
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to. The behavior change happened in 1c40c36b ("log: convert to parse-options"). Was this intentional?
The commit message talks about the --quiet handling being improved and the "git show" help doesn't mention a --quiet option. Is the simple answer that the previous behavior was incorrect?
/Gustaf
Quoted 6 lines · Gustaf Hendeby
Hello everyone,
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to. The behavior change happened in
1c40c36b("log: convert to parse-options"). Was this intentional?
Very much so.
Quoted 4 lines
The commit message talks about the --quiet handling being improved and the "git show" help doesn't mention a --quiet option. Is the simple answer that the previous behavior was incorrect?
Yes.
The long answer is that the log family (and git-format-patch, which
is where this started) never actually accepted --quiet, so it would get passed down to the diff machinery. This (for complicated reasons I'm not sure I comletely understand, but that have to do with the internal handling of 'quiet' as 'quick') caused every second commit not to show.
As you noticed, the man page never mentions a --quiet option
(because, honestly, it doesn't make any sense), so any use of that flag is wrong. Part of what the patch does is make --quiet a no-op to guard against the effect of disappearing commits.
How are you using the --quiet option and why would you even need it?
Cheers,
cmn
Signature · 3 lines
Carlos Martín Nieto | http://cmartin.tk "¿Cómo voy a decir bobadas si soy mudo?" -- CACHAI
Hi Carlos,
thanks for the detailed answer.
Quoted 8 lines · Carlos Martín Nieto
Quoted 6 lines · Gustaf Hendeby
Hello everyone,
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to. The behavior change happened in
1c40c36b("log: convert to parse-options"). Was this intentional?How are you using the --quiet option and why would you even need it?
I used
git show --quiet --pretty="format:%ci" HEAD
to extract the commit date of HEAD, and I simply replaced it with
git log -1 --quiet --pretty="format:%ci" HEAD
Though, the email from Junio suggests I should use (and this works)
git show -a --pretty="format:%ci" HEAD
still, I wonder if there is no better/more efficient solution to this.
/Gustaf
Quoted 18 lines · Gustaf Hendeby
Hi Carlos,
thanks for the detailed answer.
Quoted 8 lines · Carlos Martín Nieto
Quoted 6 lines · Gustaf Hendeby
Hello everyone,
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to. The behavior change happened in
1c40c36b("log: convert to parse-options"). Was this intentional?How are you using the --quiet option and why would you even need it?
I used
git show --quiet --pretty="format:%ci" HEAD
Quoted 8 lines
to extract the commit date of HEAD, and I simply replaced it with
git log -1 --quiet --pretty="format:%ci" HEAD
Though, the email from Junio suggests I should use (and this works)
git show -a --pretty="format:%ci" HEAD
I'm assuming you meant -s instead of -a
Quoted 2 lines
still, I wonder if there is no better/more efficient solution to this.
There is --format, so that line would look like
git show -s --format="%ci" HEAD
which IMO is quite compact and self-explanatory. Depending on how much control you have over the environment, you could set up an alias like
git config alias.show-commit 'show -s'
or even
git config alias.show-commit-date 'show -s --format="%ci"'
cmn
Signature · 3 lines
Carlos Martín Nieto | http://cmartin.tk "¿Cómo voy a decir bobadas si soy mudo?" -- CACHAI
Quoted 10 lines · Carlos Martín Nieto
Quoted 1 line
1c40c36b("log: convert to parse-options"). Was this intentional?Very much so.
Quoted 1 line
...
The long answer is that the log family (and git-format-patch, which is where this started) never actually accepted --quiet, so it would get passed down to the diff machinery. This (for complicated reasons I'm not sure I comletely understand, but that have to do with the internal handling of 'quiet' as 'quick') caused every second commit not to show.
Yes, "git format-patch" that gives empty patch for every other commit would have been incorrect, but "--quiet" to squelch patch output, especially in the context of "show" whose default is to show patch, is something people would naturally expect, even though admittedly it was doing so by accident.
How does this patch look?
It does not fix "git show master~10 master^..master", but instead of just hijacking and ignoring the --quiet option like your patch did, it actually flips the option the user wanted to affect from the command line.
builtin/log.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
builtin/log.c +2 -0
@@ -107,6 +107,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, PARSE_OPT_KEEP_DASHDASH); argc =setup_revisions (argc, argv, rev, opt); +if (quiet) + rev->diffopt.output_format |=DIFF_FORMAT_NO_OUTPUT ;/* Any arguments at this point are not recognized */ if (argc >1 )
Quoted 19 lines · Junio C Hamano
Quoted 10 lines · Carlos Martín Nieto
Quoted 1 line
1c40c36b("log: convert to parse-options"). Was this intentional?Very much so.
Quoted 1 line
...
The long answer is that the log family (and git-format-patch, which is where this started) never actually accepted --quiet, so it would get passed down to the diff machinery. This (for complicated reasons I'm not sure I comletely understand, but that have to do with the internal handling of 'quiet' as 'quick') caused every second commit not to show.
Yes, "git format-patch" that gives empty patch for every other commit would have been incorrect, but "--quiet" to squelch patch output, especially in the context of "show" whose default is to show patch, is something people would naturally expect, even though admittedly it was doing so by accident.
Quoted 5 lines
How does this patch look?
It does not fix "git show master~10 master^..master", but instead of just hijacking and ignoring the --quiet option like your patch did, it actually flips the option the user wanted to affect from the command line.
It's fine if that's what we want to do. The reason I blocked --quiet instead of converting it to -s is because it seemed less surprising than passing --quiet and still getting output (if I pass --quiet, I'd expect the application to really be quiet), which doesn't happen in the commands that accept --quiet on purpose. Then again, the log family doesn't make any sense without any output, so if you argue that way, --quiet means "quieter", which makes the interface less consistent, but I don't feel that strongly about it
So sure, if you think it helps, apply it.
Quoted 22 lines
builtin/log.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)builtin/log.c +2
-1@@ -107,6 +107,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, PARSE_OPT_KEEP_DASHDASH); argc =setup_revisions (argc, argv, rev, opt); +if (quiet) + rev->diffopt.output_format |=DIFF_FORMAT_NO_OUTPUT ;/* Any arguments at this point are not recognized */ if (argc >1 ) --To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Carlos Martín Nieto
Quoted 8 lines · Junio C Hamano
Carlos Martín Nieto <[email protected]> writes:
How does this patch look?
It does not fix "git show master~10 master^..master", but instead of just hijacking and ignoring the --quiet option like your patch did, it actually flips the option the user wanted to affect from the command line.
Quoted 8 lines
It's fine if that's what we want to do. The reason I blocked --quiet instead of converting it to -s is because it seemed less surprising than passing --quiet and still getting output (if I pass --quiet, I'd expect the application to really be quiet), which doesn't happen in the commands that accept --quiet on purpose. Then again, the log family doesn't make any sense without any output, so if you argue that way, --quiet means "quieter", which makes the interface less consistent, but I don't feel that strongly about it
There's a lot of stuff out there for which --quiet does not imply --silent. I side with Junio on the solution.
Signature · 4 lines
-Drew Northup ________________________________________________ "As opposed to vegetable or mineral error?" -John Pescatore, SANS NewsBites Vol. 12 Num. 59
Quoted 21 lines · Drew Northup
Quoted 10 lines · Carlos Martín Nieto
Quoted 8 lines · Junio C Hamano
Carlos Martín Nieto <[email protected]> writes:
How does this patch look?
It does not fix "git show master~10 master^..master", but instead of just hijacking and ignoring the --quiet option like your patch did, it actually flips the option the user wanted to affect from the command line.
Quoted 8 lines
It's fine if that's what we want to do. The reason I blocked --quiet instead of converting it to -s is because it seemed less surprising than passing --quiet and still getting output (if I pass --quiet, I'd expect the application to really be quiet), which doesn't happen in the commands that accept --quiet on purpose. Then again, the log family doesn't make any sense without any output, so if you argue that way, --quiet means "quieter", which makes the interface less consistent, but I don't feel that strongly about it
Quoted 2 lines
There's a lot of stuff out there for which --quiet does not imply --silent. I side with Junio on the solution.
Then don't let me stop you.
cmn
Signature · 3 lines
Carlos Martín Nieto | http://cmartin.tk "¿Cómo voy a decir bobadas si soy mudo?" -- CACHAI
Quoted 3 lines · Gustaf Hendeby
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to.
The official and right way to suppress diff output from "show" has always been with the "-s" option, and it should still work. Otherwise please report a bug here.
Thanks.
Quoted 7 lines · Junio C Hamano
Quoted 3 lines
I was playing around with "git show" lately and realized it has changed its behavior regarding the --quiet option, which no longer suppresses the diff output as it used to.
The official and right way to suppress diff output from "show" has always been with the "-s" option, and it should still work. Otherwise please report a bug here.
Having said that, I think this is a minor regression.
"git show A B C" has been about showing objects (not commits) A and B and C. It picks a convenient format for human consumption for each type, and shows commit as if it were given to "log -1 -p", tree as if it were given to "ls-tree --name-only", blob as if it were given to "cat-file blob".
But recently, Linus bolted "git show A..B" on to it, and in a way that is quite wrong. It walks the history by accident, not by design. This makes fixing this regression somewhat complex, I suspect.
Given the existing machinery to "show" each individual object given from the command line, one would naturally imagine that we have a routine that takes one object, tells its object type, and formats the object in the representation suitable for human consumption, and have a loop over the command line to call that routine with each object from the command line. And "git show A..B" would first walk to find individual commit objects between A and B, and feed the same routine with these commits one by one.
Not so. The current implementation walks the history between A..B as a side effect of showing a commit (starting from B) and works by pure accident.
Case in point: "git show master master" shows two copies of the same commit, as it should. "git show master^..master master" does not. The reason? Walking between "master^..master" is done as a side effect of showing "master^..master" and marks commit object "master" already shown, and makes the command ignore the second argument.
A worse example can be seen by running something silly like "git show master~10 master^..master", which you would expect to see two commits (master~10 and master). Do not do this on anything with a deep history like the kernel repository---it will walk down to the root commit.
I think the ideal fix would be to fix the "show A..B" support (one possible solution would be to simply disable it, but I'd see it as the last resort) so that it first collects the commit objects in a queue by properly walking (and clean the object flags that were used to control the walking after we know what commits are in the range), expand A..B into these commits on the command line arguments list, and then run the resulting command line arguments through the traditional "git show" machinery that shows one object at a time.
If we go that route, then we should always use "quiet" during the internal history walking that expands A..B to the set of commits in the range with or without command line --quiet. And then make both --quiet and -s from the command line to control if the patch is shown when showing a commit.