git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 73/75] range-diff: use parse_options() instead of diff_opt_parse()
Date: Thu, 27 Dec 2018 17:25:34 +0100	[thread overview]
Message-ID: <20181227162536.15895-14-pclouds@gmail.com> (raw)
In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com>

Diff's internal option parsing is now done with 'struct option', which
makes it possible to combine all diff options to range-diff and parse
everything all at once. Parsing code becomes simpler, and we get a
looong 'git range-diff -h'

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/range-diff.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index f01a0be851..784bd19321 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
 	int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
 	struct diff_options diffopt = { NULL };
 	int simple_color = -1;
-	struct option options[] = {
+	struct option range_diff_options[] = {
 		OPT_INTEGER(0, "creation-factor", &creation_factor,
 			    N_("Percentage by which creation is weighted")),
 		OPT_BOOL(0, "no-dual-color", &simple_color,
 			    N_("use simple diff colors")),
 		OPT_END()
 	};
-	int i, j, res = 0;
+	struct option *options;
+	int res = 0;
 	struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
 
 	git_config(git_diff_ui_config, NULL);
 
 	repo_diff_setup(the_repository, &diffopt);
 
+	options = parse_options_concat(range_diff_options, diffopt.parseopts);
 	argc = parse_options(argc, argv, NULL, options,
-			     builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
-			     PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
-
-	for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
-		int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
+			     builtin_range_diff_usage, 0);
 
-		if (!c)
-			argv[j++] = argv[i++];
-		else
-			i += c;
-	}
-	while (i < argc)
-		argv[j++] = argv[i++];
-	argc = j;
 	diff_setup_done(&diffopt);
 
-	/* Make sure that there are no unparsed options */
-	argc = parse_options(argc, argv, NULL,
-			     options + ARRAY_SIZE(options) - 1, /* OPT_END */
-			     builtin_range_diff_usage, 0);
-
 	/* force color when --dual-color was used */
 	if (!simple_color)
 		diffopt.use_color = 1;
@@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
 		error(_("need two commit ranges"));
 		usage_with_options(builtin_range_diff_usage, options);
 	}
+	FREE_AND_NULL(options);
 
 	res = show_range_diff(range1.buf, range2.buf, creation_factor,
 			      simple_color < 1, &diffopt);
-- 
2.20.0.482.g66447595a7


  parent reply	other threads:[~2018-12-27 16:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27 16:25 [PATCH 00/75] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 01/75] parse-options.h: remove extern on function prototypes Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 02/75] parse-options: add one-shot mode Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 03/75] parse-options: allow keep-unknown + stop-at-non-opt combination Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 04/75] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 05/75] parse-options: add OPT_BITOP() Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 06/75] parse-options: stop abusing 'callback' for lowlevel callbacks Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 07/75] parse-options: avoid magic return codes Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 08/75] parse-options: allow ll_callback with OPTION_CALLBACK Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 09/75] diff.h: keep forward struct declarations sorted Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 10/75] diff.h: avoid bit fields in struct diff_flags Nguyễn Thái Ngọc Duy
2019-01-09 20:21   ` Stefan Beller
2018-12-27 16:25 ` [PATCH 11/75] diff.c: prepare to use parse_options() for parsing Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` [PATCH 12/75] diff.c: convert -u|-p|--patch Nguyễn Thái Ngọc Duy
2018-12-27 16:25 ` Nguyễn Thái Ngọc Duy [this message]
2018-12-27 16:25 ` [PATCH 74/75] diff --no-index: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
2018-12-27 20:34   ` Eric Sunshine
2018-12-27 16:25 ` [PATCH 75/75] am: avoid diff_opt_parse() Nguyễn Thái Ngọc Duy

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181227162536.15895-14-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).