[PATCH] diff: alias -q to --quiet

Subsystems: documentation, the rest

STALE3216d

2 messages, 2 authors, 2017-10-13 · open the first message on its own page

[PATCH] diff: alias -q to --quiet

From: Anthony Sottile <hidden>
Date: 2017-10-13 16:56:46

Previously, `-q` was silently ignored:

Before:

$ git diff -q -- Documentation/; echo $?
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index a88c767..aa6e724 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -587,6 +587,7 @@ ifndef::git-log[]
        That is, it exits with 1 if there were differences and
        0 means no differences.

+-q::
 --quiet::
        Disable all output of the program. Implies `--exit-code`.
 endif::git-log[]
0
$

After:
$ ./git diff -q -- Documentation/; echo $?
1
$

Signed-off-by: Anthony Sottile <redacted>
---
 Documentation/diff-options.txt | 1 +
 diff.c                         | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index a88c767..aa6e724 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -587,6 +587,7 @@ ifndef::git-log[]
 	That is, it exits with 1 if there were differences and
 	0 means no differences.
 
+-q::
 --quiet::
 	Disable all output of the program. Implies `--exit-code`.
 endif::git-log[]
diff --git a/diff.c b/diff.c
index 69f0357..13dfc3e 100644
--- a/diff.c
+++ b/diff.c
@@ -4751,7 +4751,7 @@ int diff_opt_parse(struct diff_options *options,
 	}
 	else if (!strcmp(arg, "--exit-code"))
 		DIFF_OPT_SET(options, EXIT_WITH_STATUS);
-	else if (!strcmp(arg, "--quiet"))
+	else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
 		DIFF_OPT_SET(options, QUICK);
 	else if (!strcmp(arg, "--ext-diff"))
 		DIFF_OPT_SET(options, ALLOW_EXTERNAL);
-- 
2.7.4

Re: [PATCH] diff: alias -q to --quiet

From: Jeff King <hidden>
Date: 2017-10-13 17:57:03

On Fri, Oct 13, 2017 at 09:44:15AM -0700, Anthony Sottile wrote:
Previously, `-q` was silently ignored:
I'm not sure if is totally ignored. Normally if we have an unknown
options we'd complain:

  $ git diff -x
  error: invalid option: -x

but we don't with "-q". Why?

In builtin/diff.c:471, we can see:

  else if (!strcmp(argv[1], "-q"))
          options |= DIFF_SILENT_ON_REMOVED;

So it _does_ do something, just not what you expected.

But wait, that's not the whole story. We convert "-q" into
SILENT_ON_REMOVED in git-diff-files and in git-diff (when we're acting
like diff-files). But nobody ever seems to check it!

Running "git log -p -SSILENT_ON_REMOVED" turns up two interesting
commits:

  - 95a7c546b0 (diff: deprecate -q option to diff-files, 2013-07-17)

  - c48f6816f0 (diff: remove "diff-files -q" in a version of Git in a
    distant future, 2013-07-18).

So we dropped "-q" a few years ago and added a deprecation notice. "git
tag --contains 95a7c546b0" tells us that happened in v1.8.5, which
shipped in Nov 2013.

And then in v2.0.0 (May 2014) we tried to drop "-q" completely. Looking
over c48f6816f0, I _think_ it's a mistake that "-q" became a silent noop
there. That commit should have ripped out the remaining bits that set
the SILENT_ON_REMOVED flag, and "-q" would have become an error.

So there are two separate questions/tasks:

  1. Should we remove the special handling of "-q" leftover from this
     deprecation? I think the answer is yes.

  2. Should we teach the diff machinery as a whole to treat "-q" as a
     synonym for "--quiet".

     Probably yes, but it's less clear to me that this won't have funny
     interactions. Are there other commands which use the diff-options
     parser via setup_revisions(), but expect "-q" to be left in the
     output so that they can handle it themselves?

     It looks like git-log does so, but it pulls the "-q" out before
     handing the remainder to setup_revisions(). And anyway, it just
     converts the option into a quiet diff (though it does in a way
     that's different than the rest of the diff code -- that might bear
     investigating on its own).

     Grepping for 'q' and OPT__QUIET, I don't see any others, but I
     didn't spend very much time digging.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help