From 95e926c38267eb7ec8956ea47db55bf8080fb282 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 10 Mar 2022 11:00:43 -0800 Subject: [PATCH 1/2] Allow '--no-output-indicator-{old,new}' to disable diff output This is particularly useful if you want to just see the end result of a diff, without the original lines that have been removed (or the reverse). That's a fairly common model in various GUI diff viewers, but it's not unusual to want to just see "what is the end result of my changes" without seeing (a) everything that didn't change and (b) the old removed state. Example: git show --no-output-indicator-old 04bf052eef to see just the end result of the changes in commit 04bf052eef ("grep: simplify config parsing and option parsing"). This is a technology presentation, I think it needs a shorter option name too if people agree that this is useful (this basically replaces my hacky git diff | grep -v '^-' that I use for the same purpose, but the very long argument name obviously makes it no more convenient, although the end result is qualitatively better). Signed-off-by: Linus Torvalds --- diff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 2bd5e0d817..895951b849 100644 --- a/diff.c +++ b/diff.c @@ -1254,6 +1254,8 @@ static void emit_line_ws_markup(struct diff_options *o, const char *ws = NULL; int sign = o->output_indicators[sign_index]; + if (!sign) + return; if (o->ws_error_highlight & ws_rule) { ws = diff_get_color_opt(o, DIFF_WHITESPACE); if (!*ws) @@ -4986,6 +4988,10 @@ static int diff_opt_char(const struct option *opt, { char *value = opt->value; + if (unset) { + *value = 0; + return 0; + } BUG_ON_OPT_NEG(unset); if (arg[1]) return error(_("%s expects a character, got '%s'"), @@ -5476,12 +5482,12 @@ static void prep_parse_options(struct diff_options *options) &options->output_indicators[OUTPUT_INDICATOR_NEW], N_(""), N_("specify the character to indicate a new line instead of '+'"), - PARSE_OPT_NONEG, diff_opt_char), + 0, diff_opt_char), OPT_CALLBACK_F(0, "output-indicator-old", &options->output_indicators[OUTPUT_INDICATOR_OLD], N_(""), N_("specify the character to indicate an old line instead of '-'"), - PARSE_OPT_NONEG, diff_opt_char), + 0, diff_opt_char), OPT_CALLBACK_F(0, "output-indicator-context", &options->output_indicators[OUTPUT_INDICATOR_CONTEXT], N_(""), -- 2.35.1.459.gabbef95d73