On Thu, Mar 10, 2022 at 1:26 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > > I often use -W and the above would give us a natural extension, but > I agree that is a bit too dense and totally unintuitive. As we use > parse-options for patch output formatting options, my pick would be > "--new-only" vs "--old-only" ( I was "ok, that's really easy" and did + OPT_ALIAS(0, "new-only", "no-output-indicator-old"), + OPT_ALIAS(0, "old-only", "no-output-indicator-new"), but sadly the parse-options alias code isn't quite smart enough. Doing it with an explicit callback obviously works, but the "unique abbreviations" part doesn't actually work for me. I think it's due to PARSE_OPT_KEEP_UNKNOWN making the abbreviated options not work, but I don't know tha option parsing code well enough. Here's the stupid patch that "works" but doesn't allow the shortened version. Maybe somebody can point out what silly thing I did wrong. Linus
diff.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/diff.c b/diff.c index 895951b849..cf168e727d 100644 --- a/diff.c +++ b/diff.c @@ -5000,6 +5000,17 @@ static int diff_opt_char(const struct option *opt, return 0; } +static int diff_opt_no_char(const struct option *opt, + const char *arg, int unset) +{ + char *value = opt->value; + + BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); + *value = 0; + return 0; +} + static int diff_opt_color_moved(const struct option *opt, const char *arg, int unset) { @@ -5493,6 +5504,14 @@ static void prep_parse_options(struct diff_options *options) N_("<char>"), N_("specify the character to indicate a context instead of ' '"), PARSE_OPT_NONEG, diff_opt_char), + OPT_CALLBACK_F(0, "new-only", + &options->output_indicators[OUTPUT_INDICATOR_OLD], NULL, + N_("show only new lines in diff"), + PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_char), + OPT_CALLBACK_F(0, "old-only", + &options->output_indicators[OUTPUT_INDICATOR_NEW], NULL, + N_("show only old lines in diff"), + PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_char), OPT_GROUP(N_("Diff rename options")), OPT_CALLBACK_F('B', "break-rewrites", &options->break_opt, N_("<n>[/<m>]"),