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

[PATCH v3 2/3] diff: use add_diff_options() in diff_opt_parse()

From
René Scharfe <l.s.r@web.de>
Date
Dec 1, 2022, 22:51 UTC
Message-ID
<fb901635-8058-856d-c7cd-6fef24329f62@web.de>
In-Reply-To
<19325420-5630-87bb-0c2c-362151214b36@web.de>

Prepare the removal of the parseopts member of struct diff_options by using the API function add_diff_options() instead of accessing it directly to get the command line option definitions. Building the copy by concatenating with an empty option array is slightly awkward, but simpler than a non-concat version of add_diff_options() would be to use in places that need concatenation.

Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 diff.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/diff.c b/diff.c
index f1cf13e8e7..f6d85122a9 100644
--- a/diff.c
+++ b/diff.c
@@ -5702,15 +5702,19 @@ static void prep_parse_options(struct diff_options *options)
 int diff_opt_parse(struct diff_options *options,
 		   const char **av, int ac, const char *prefix)
 {
+	struct option no_options[] = { OPT_END() };
+	struct option *parseopts = add_diff_options(no_options, options);
+
 	if (!prefix)
 		prefix = "";

-	ac = parse_options(ac, av, prefix, options->parseopts, NULL,
+	ac = parse_options(ac, av, prefix, parseopts, NULL,
 			   PARSE_OPT_KEEP_DASHDASH |
 			   PARSE_OPT_KEEP_UNKNOWN_OPT |
 			   PARSE_OPT_NO_INTERNAL_HELP |
 			   PARSE_OPT_ONE_SHOT |
 			   PARSE_OPT_STOP_AT_NON_OPTION);
+	free(parseopts);

 	return ac;
 }
--
2.30.2
Previous: René ScharfeNext: René Scharfe
Message 22 of 23 in “diff: build parseopts array on demand”
  1. 0/3 diff: build parseopts array on demandRené Scharfe, Nov 30, 2022
  2. 1/3 diff: factor out add_diff_options()René Scharfe, Nov 30, 2022
  3. ZheNing HuDec 1, 2022
  4. 2/3 diff: let prep_parse_options() return parseopt arrayRené Scharfe, Nov 30, 2022
  5. 3/3 diff: remove parseopts member of struct diff_optionsRené Scharfe, Nov 30, 2022
  6. Junio C HamanoDec 1, 2022
  7. René ScharfeDec 1, 2022
  8. Junio C HamanoDec 1, 2022
  9. René ScharfeDec 1, 2022
  10. Junio C HamanoDec 1, 2022
  11. 0/3 diff: build parseopts array on demandRené Scharfe, Dec 1, 2022
  12. 1/3 diff: factor out add_diff_options()René Scharfe, Dec 1, 2022
  13. 2/3 diff: let prep_parse_options() return parseopt arrayRené Scharfe, Dec 1, 2022
  14. 3/3 diff: remove parseopts member from struct diff_optionsRené Scharfe, Dec 1, 2022
  15. Ævar Arnfjörð BjarmasonDec 1, 2022
  16. René ScharfeDec 1, 2022
  17. Eric SunshineDec 1, 2022
  18. René ScharfeDec 1, 2022
  19. Ævar Arnfjörð BjarmasonDec 1, 2022
  20. 0/3 diff: build parseopts array on demandRené Scharfe, Dec 1, 2022
  21. 1/3 diff: factor out add_diff_options()René Scharfe, Dec 1, 2022
  22. 2/3 diff: use add_diff_options() in diff_opt_parse()René Scharfe, Dec 1, 2022
  23. 3/3 diff: remove parseopts member from struct diff_optionsRené Scharfe, Dec 1, 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.