All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Sergey Organov <sorganov@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v1 3/7] diff: make DIFF_FORMAT_NO_OUTPUT 0
Date: Fri, 12 May 2023 02:03:35 -0600	[thread overview]
Message-ID: <20230512080339.2186324-4-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20230512080339.2186324-1-felipe.contreras@gmail.com>

`-s` is considered a format, but if we change the meaning to absence of
a format it now becomes possible to distinguish `git diff` from
`git diff --no-patch`, although that isn't done in this commit.

This also fixes a bug in which specifying an output format did not clear
the NO_OUTPUT flag.

For example this now works correctly:

  git show -s --raw

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 diff.c       | 13 ++++++-------
 diff.h       |  6 +-----
 range-diff.c |  2 +-
 revision.c   |  4 ++--
 4 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/diff.c b/diff.c
index 387944f289..4f4b1d7e13 100644
--- a/diff.c
+++ b/diff.c
@@ -4750,8 +4750,7 @@ void diff_setup_done(struct diff_options *options)
 {
 	unsigned check_mask = DIFF_FORMAT_NAME |
 			      DIFF_FORMAT_NAME_STATUS |
-			      DIFF_FORMAT_CHECKDIFF |
-			      DIFF_FORMAT_NO_OUTPUT;
+			      DIFF_FORMAT_CHECKDIFF;
 	/*
 	 * This must be signed because we're comparing against a potentially
 	 * negative value.
@@ -4762,8 +4761,8 @@ void diff_setup_done(struct diff_options *options)
 		options->set_default(options);
 
 	if (HAS_MULTI_BITS(options->output_format & check_mask))
-		die(_("options '%s', '%s', '%s', and '%s' cannot be used together"),
-			"--name-only", "--name-status", "--check", "-s");
+		die(_("options '%s', '%s', and '%s' cannot be used together"),
+			"--name-only", "--name-status", "--check");
 
 	if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK))
 		die(_("options '%s', '%s', and '%s' cannot be used together"),
@@ -5494,9 +5493,9 @@ struct option *add_diff_options(const struct option *opts,
 		OPT_BITOP('p', "patch", &options->output_format,
 			  N_("generate patch"),
 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
-		OPT_BITOP('s', "no-patch", &options->output_format,
+		OPT_SET_INT_F('s', "no-patch", &options->output_format,
 			  N_("suppress diff output"),
-			  DIFF_FORMAT_NO_OUTPUT, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_PATCH),
+			  DIFF_FORMAT_NO_OUTPUT, PARSE_OPT_NONEG),
 		OPT_BITOP('u', NULL, &options->output_format,
 			  N_("generate patch"),
 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_DEFAULT | DIFF_FORMAT_NO_OUTPUT),
@@ -6646,7 +6645,7 @@ void diff_flush(struct diff_options *options)
 		separator++;
 	}
 
-	if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+	if (output_format == DIFF_FORMAT_NO_OUTPUT &&
 	    options->flags.exit_with_status &&
 	    options->flags.diff_from_contents) {
 		/*
diff --git a/diff.h b/diff.h
index 15a7bf2c9f..44da1a4ca7 100644
--- a/diff.h
+++ b/diff.h
@@ -94,6 +94,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 
 typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
 
+#define DIFF_FORMAT_NO_OUTPUT	0x0000
 #define DIFF_FORMAT_RAW		0x0001
 #define DIFF_FORMAT_DIFFSTAT	0x0002
 #define DIFF_FORMAT_NUMSTAT	0x0004
@@ -108,11 +109,6 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_FORMAT_NAME_STATUS	0x0200
 #define DIFF_FORMAT_CHECKDIFF	0x0400
 
-/* Same as output_format = 0 but we know that -s flag was given
- * and we should not give default value to output_format.
- */
-#define DIFF_FORMAT_NO_OUTPUT	0x0800
-
 #define DIFF_FORMAT_CALLBACK	0x1000
 
 #define DIFF_FLAGS_INIT { 0 }
diff --git a/range-diff.c b/range-diff.c
index 6c1ae9dd34..00ff5dc160 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -542,7 +542,7 @@ static void output(struct string_list *a, struct string_list *b,
 			a_util = a->items[b_util->matching].util;
 			output_pair_header(&opts, patch_no_width,
 					   &buf, &dashes, a_util, b_util);
-			if (!(opts.output_format & DIFF_FORMAT_NO_OUTPUT))
+			if (opts.output_format)
 				patch_diff(a->items[b_util->matching].string,
 					   b->items[j].string, &opts);
 			a_util->shown = 1;
diff --git a/revision.c b/revision.c
index cf68b533fd..07d653c197 100644
--- a/revision.c
+++ b/revision.c
@@ -3030,8 +3030,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
 
 	if (revs->line_level_traverse &&
-	    (revs->diffopt.output_format & ~(DIFF_FORMAT_DEFAULT | DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
-		die(_("-L does not yet support diff formats besides -p and -s"));
+	    (revs->diffopt.output_format & ~(DIFF_FORMAT_DEFAULT | DIFF_FORMAT_PATCH)))
+		die(_("-L does not yet support diff formats besides -p"));
 
 	if (revs->expand_tabs_in_log < 0)
 		revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
-- 
2.40.0+fc1


  parent reply	other threads:[~2023-05-12  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12  8:03 [PATCH v1 0/7] diff: fix -s and --no-patch Felipe Contreras
2023-05-12  8:03 ` [PATCH v1 1/7] line-log: set patch format explicitly by default Felipe Contreras
2023-05-12  8:03 ` [PATCH v1 2/7] diff: introduce DIFF_FORMAT_DEFAULT Felipe Contreras
2023-05-12  8:03 ` Felipe Contreras [this message]
2023-05-12  8:03 ` [PATCH v1 4/7] test: add various tests for diff formats with -s Felipe Contreras
2023-05-12  8:03 ` [PATCH v1 5/7] diff: split --no-patch from -s Felipe Contreras
2023-05-12  8:03 ` [PATCH v1 6/7] diff: add --silent as alias of -s Felipe Contreras
2023-05-12  8:03 ` [PATCH v1 7/7] diff: remove DIFF_FORMAT_NO_OUTPUT Felipe Contreras
2023-05-12  8:20 ` [PATCH v1 0/7] diff: fix -s and --no-patch Felipe Contreras
2023-05-12  9:32   ` Sergey Organov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230512080339.2186324-4-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sorganov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.