From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List Mailing <git@vger.kernel.org>
Subject: Re: RFC: Using '--no-output-indicator-old' to only show new state
Date: Thu, 10 Mar 2022 14:13:10 -0800 [thread overview]
Message-ID: <CAHk-=whRbuJJ1LzYN9F48JaS7EjuP3FkppHJXi1wAO_qLJQ2xw@mail.gmail.com> (raw)
In-Reply-To: <xmqqfsnpcxdm.fsf@gitster.g>
[-- Attachment #1: Type: text/plain, Size: 981 bytes --]
On Thu, Mar 10, 2022 at 1:26 PM Junio C Hamano <gitster@pobox.com> 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
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1321 bytes --]
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>]"),
next prev parent reply other threads:[~2022-03-10 22:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 19:40 RFC: Using '--no-output-indicator-old' to only show new state Linus Torvalds
2022-03-10 20:13 ` Junio C Hamano
2022-03-10 20:40 ` Linus Torvalds
2022-03-10 21:26 ` Junio C Hamano
2022-03-10 22:13 ` Linus Torvalds [this message]
2022-03-11 0:01 ` Linus Torvalds
2022-03-11 7:48 ` Ævar Arnfjörð Bjarmason
2022-03-11 9:45 ` [PATCH] parse-options: add per-option flag to stop abbreviation Ævar Arnfjörð Bjarmason
2022-03-11 18:44 ` Linus Torvalds
2022-03-11 19:15 ` RFC: Using '--no-output-indicator-old' to only show new state Linus Torvalds
2022-03-11 19:42 ` Konstantin Ryabitsev
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='CAHk-=whRbuJJ1LzYN9F48JaS7EjuP3FkppHJXi1wAO_qLJQ2xw@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).