git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC: Using '--no-output-indicator-old' to only show new state

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 10, 2022, 22:13 UTC
Message-ID
<CAHk-=whRbuJJ1LzYN9F48JaS7EjuP3FkppHJXi1wAO_qLJQ2xw@mail.gmail.com>
In-Reply-To
<xmqqfsnpcxdm.fsf@gitster.g>
On Thu, Mar 10, 2022 at 1:26 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
>
> 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>]"),
Previous: Junio C HamanoNext: Linus Torvalds
Message 5 of 11 in “RFC: Using '--no-output-indicator-old' to only show new state”
  1. Linus TorvaldsMar 10, 2022
  2. Junio C HamanoMar 10, 2022
  3. Linus TorvaldsMar 10, 2022
  4. Junio C HamanoMar 10, 2022
  5. Linus TorvaldsMar 10, 2022
  6. Linus TorvaldsMar 11, 2022
  7. Ævar Arnfjörð BjarmasonMar 11, 2022
  8. parse-options: add per-option flag to stop abbreviationÆvar Arnfjörð Bjarmason, Mar 11, 2022
  9. Linus TorvaldsMar 11, 2022
  10. Linus TorvaldsMar 11, 2022
  11. Konstantin RyabitsevMar 11, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.