aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-08-28 17:29:34 -0400
committerJunio C Hamano <gitster@pobox.com>2012-08-28 15:37:29 -0700
commitf9c75d858d85449a8a6f635bef4b5bd003edd764 (patch)
tree6bd4a68737c28df6bdcd997a797081363332485d
parentb52183179bb0a97ea4d91d1248aca303d8e8f892 (diff)
downloadgit-f9c75d858d85449a8a6f635bef4b5bd003edd764.tar.gz
git-f9c75d858d85449a8a6f635bef4b5bd003edd764.tar.xz
log: fix --quiet synonym for -s
Originally the "--quiet" option was parsed by the diff-option parser into the internal QUICK option. This had the effect of silencing diff output from the log (which was not intended, but happened to work and people started to use it). But it also had other odd side effects at the diff level (for example, it would suppress the second commit in "git show A B"). To fix this, commit 1c40c36 converted log to parse-options and handled the "quiet" option separately, not passing it on to the diff code. However, it simply ignored the option, which was a regression for people using it as a synonym for "-s". Commit 01771a8 then fixed that by interpreting the option to add DIFF_FORMAT_NO_OUTPUT to the list of output formats. However, that commit did not fix it in all cases. It sets the flag after setup_revisions is called. Naively, this makes sense because you would expect the setup_revisions parser to overwrite our output format flag if "-p" or another output format flag is seen. However, that is not how the NO_OUTPUT flag works. We actually store it in the bit-field as just another format. At the end of setup_revisions, we call diff_setup_done, which post-processes the bitfield and clears any other formats if we have set NO_OUTPUT. By setting the flag after setup_revisions is done, diff_setup_done does not have a chance to make this tweak, and we end up with other format options still set. As a result, the flag would have no effect in "git log -p --quiet" or "git show --quiet". Fix it by setting the format flag before the call to setup_revisions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/log.c2
-rwxr-xr-xt/t7007-show.sh12
2 files changed, 13 insertions, 1 deletions
diff --git a/builtin/log.c b/builtin/log.c
index 54f24e208..a8249d3c0 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -108,9 +108,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
PARSE_OPT_KEEP_DASHDASH);
- argc = setup_revisions(argc, argv, rev, opt);
if (quiet)
rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
+ argc = setup_revisions(argc, argv, rev, opt);
/* Any arguments at this point are not recognized */
if (argc > 1)
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index a40cd3630..e41fa00b8 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -108,4 +108,16 @@ test_expect_success 'showing range' '
test_cmp expect actual.filtered
'
+test_expect_success '-s suppresses diff' '
+ echo main3 >expect &&
+ git show -s --format=%s main3 >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--quiet suppresses diff' '
+ echo main3 >expect &&
+ git show --quiet --format=%s main3 >actual &&
+ test_cmp expect actual
+'
+
test_done