Re: Bug in "git diff --quiet" handling.

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Bug in "git diff --quiet" handling.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:01

Paul Gortmaker [off-list ref] writes:
I'm assuming this is a bug,...
Yeah, it sounds like you found an interesting one.

As far as I know, whatever "format-patch" does in response to "--quiet"
option is not a deliberate and designed behaviour, as squelching the patch
output in the context of the command does not make much sense [*1*]; the
current implementation simply writes anything off as an user error when
"format-patch --quiet" did anything "interesting" ;-).

A patch to make --quiet not to squelch the patch output, and instead
silence any progress output would be a good addition.

Thanks.

[Footnote]

*1* Also note that at least in the original design, the standard output
from "format-patch" was never meant to be squelched.  It was the only way
the calling scripts (and humans) can learn under what filenames the
patches were output, so that the command line to fire them off as e-mails
can be programatically formed without running "ls" and filtering non-patch
files manually (if you use "format-patch -o newdir" and newdir did not
have anythning in it before running the command, of course you can rely on
the output from "ls").

[PATCH] format-patch: don't pass on the --quiet flag

From: Carlos Martín Nieto <hidden>
Date: 2016-06-15 22:51:01

The --quiet flag is not meant to be passed on to the diff, as the user
always wants the patches to be produced so catch it and pass it to
reopen_stdout which decides whether to print the filename or not.

Noticed by Paul Gortmaker

Signed-off-by: Carlos Martín Nieto <redacted>
---
A patch to make --quiet not to squelch the patch output, and instead
silence any progress output would be a good addition.
Something like this? I guess the only use case would be together with
-o.

 builtin/log.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 9a15d69..1ce00ba 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -623,7 +623,7 @@ static FILE *realstdout = NULL;
 static const char *output_directory = NULL;
 static int outdir_offset;
 
-static int reopen_stdout(struct commit *commit, struct rev_info *rev)
+static int reopen_stdout(struct commit *commit, struct rev_info *rev, int quiet)
 {
 	struct strbuf filename = STRBUF_INIT;
 	int suffix_len = strlen(fmt_patch_suffix) + 1;
@@ -639,7 +639,7 @@ static int reopen_stdout(struct commit *commit, struct rev_info *rev)
 
 	get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);
 
-	if (!DIFF_OPT_TST(&rev->diffopt, QUICK))
+	if (!quiet)
 		fprintf(realstdout, "%s\n", filename.buf + outdir_offset);
 
 	if (freopen(filename.buf, "w", stdout) == NULL)
@@ -718,7 +718,8 @@ static void print_signature(void)
 static void make_cover_letter(struct rev_info *rev, int use_stdout,
 			      int numbered, int numbered_files,
 			      struct commit *origin,
-			      int nr, struct commit **list, struct commit *head)
+			      int nr, struct commit **list, struct commit *head,
+			      int quiet)
 {
 	const char *committer;
 	const char *subject_start = NULL;
@@ -754,7 +755,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 			sha1_to_hex(head->object.sha1), committer, committer);
 	}
 
-	if (!use_stdout && reopen_stdout(commit, rev))
+	if (!use_stdout && reopen_stdout(commit, rev, quiet))
 		return;
 
 	if (commit) {
@@ -995,6 +996,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	char *add_signoff = NULL;
 	struct strbuf buf = STRBUF_INIT;
 	int use_patch_format = 0;
+	int quiet = 0;
 	const struct option builtin_format_patch_options[] = {
 		{ OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
 			    "use [PATCH n/m] even with a single patch",
@@ -1050,6 +1052,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			    PARSE_OPT_OPTARG, thread_callback },
 		OPT_STRING(0, "signature", &signature, "signature",
 			    "add a signature"),
+		OPT_BOOLEAN(0, "quiet", &quiet,
+			    "don't print the patch filenames"),
 		OPT_END()
 	};
 
@@ -1259,7 +1263,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		if (thread)
 			gen_message_id(&rev, "cover");
 		make_cover_letter(&rev, use_stdout, numbered, numbered_files,
-				  origin, nr, list, head);
+				  origin, nr, list, head, quiet);
 		total++;
 		start_number--;
 	}
@@ -1305,7 +1309,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		}
 
 		if (!use_stdout && reopen_stdout(numbered_files ? NULL : commit,
-						 &rev))
+						 &rev, quiet))
 			die("Failed to create output files");
 		shown = log_tree_commit(&rev, commit);
 		free(commit->buffer);
-- 
1.7.4.2.437.g4fc7e.dirty

[PATCH] format-patch: document --quiet option

From: Carlos Martín Nieto <hidden>
Date: 2016-06-15 22:51:01

Signed-off-by: Carlos Martín Nieto <redacted>
---

I guess this should be squashed into the previous one. I forgot it
wasn't documented, partly because reading the commit log for
ec2956df59 (Nate Case, format-patch: Respect --quiet option) says the
man page suggests this should work.

 Documentation/git-format-patch.txt |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 9dcafc6..616726b 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -20,7 +20,7 @@ SYNOPSIS
 		   [--ignore-if-in-upstream]
 		   [--subject-prefix=Subject-Prefix]
 		   [--to=<email>] [--cc=<email>]
-		   [--cover-letter]
+		   [--cover-letter] [--quiet]
 		   [<common diff options>]
 		   [ <since> | <revision range> ]
 
@@ -192,6 +192,9 @@ will want to ensure that threading is disabled for `git send-email`.
 	filenames, use specified suffix.  A common alternative is
 	`--suffix=.txt`.  Leaving this empty will remove the `.patch`
 	suffix.
+
+--quiet::
+	Do not print the patch names to standard output.
 +
 Note that the leading character does not have to be a dot; for example,
 you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
-- 
1.7.4.2.437.g4fc7e.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help