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 74/76] range-diff: use parse_options() instead of diff_opt_parse()
Date: Thu, 17 Jan 2019 20:06:13 +0700	[thread overview]
Message-ID: <20190117130615.18732-75-pclouds@gmail.com> (raw)
In-Reply-To: <20190117130615.18732-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:[~2019-01-17 13:12 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 01/76] parse-options.h: remove extern on function prototypes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 02/76] parse-options: add one-shot mode Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination Nguyễn Thái Ngọc Duy
2019-01-17 18:33   ` Stefan Beller
2019-01-17 13:05 ` [PATCH 04/76] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 05/76] parse-options: add OPT_BITOP() Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 06/76] parse-options: stop abusing 'callback' for lowlevel callbacks Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 07/76] parse-options: avoid magic return codes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 08/76] parse-options: allow ll_callback with OPTION_CALLBACK Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 09/76] diff.h: keep forward struct declarations sorted Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 10/76] diff.h: avoid bit fields in struct diff_flags Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 11/76] diff.c: prepare to use parse_options() for parsing Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 12/76] diff.c: convert -u|-p|--patch Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 13/76] diff.c: convert -U|--unified Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 14/76] diff.c: convert -W|--[no-]function-context Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 15/76] diff.c: convert --raw Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 16/76] diff.c: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 17/76] diff.c: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 18/76] diff.c: convert --dirstat and friends Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 19/76] diff.c: convert --check Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 20/76] diff.c: convert --summary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 21/76] diff.c: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 22/76] diff.c: convert --name-only Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 23/76] diff.c: convert --name-status Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 24/76] diff.c: convert -s|--no-patch Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 25/76] diff.c: convert --stat* Nguyễn Thái Ngọc Duy
2019-01-19  1:21   ` SZEDER Gábor
2019-01-17 13:05 ` [PATCH 26/76] diff.c: convert --[no-]compact-summary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 27/76] diff.c: convert --output-* Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 28/76] diff.c: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
2019-01-21 12:07   ` Johannes Schindelin
2019-01-17 13:05 ` [PATCH 29/76] diff.c: convert -M|--find-renames Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 30/76] diff.c: convert -D|--irreversible-delete Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 31/76] diff.c: convert -C|--find-copies Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 32/76] diff.c: convert --find-copies-harder Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 33/76] diff.c: convert --no-renames|--[no--rename-empty Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 34/76] diff.c: convert --relative Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 35/76] diff.c: convert --[no-]minimal Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 36/76] diff.c: convert --ignore-some-changes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 37/76] diff.c: convert --[no-]indent-heuristic Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 38/76] diff.c: convert --patience Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 39/76] diff.c: convert --histogram Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 40/76] diff.c: convert --diff-algorithm Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 41/76] diff.c: convert --anchored Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 42/76] diff.c: convert --binary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 43/76] diff.c: convert --full-index Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 44/76] diff.c: convert -a|--text Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 45/76] diff.c: convert -R Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 46/76] diff.c: convert --[no-]follow Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 47/76] diff.c: convert --[no-]color Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 48/76] diff.c: convert --word-diff Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 49/76] diff.c: convert --word-diff-regex Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 50/76] diff.c: convert --color-words Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 51/76] diff.c: convert --exit-code Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 52/76] diff.c: convert --quiet Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 53/76] diff.c: convert --ext-diff Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 54/76] diff.c: convert --textconv Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 55/76] diff.c: convert --ignore-submodules Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 56/76] diff.c: convert --submodule Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 57/76] diff.c: convert --ws-error-highlight Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 58/76] diff.c: convert --ita-[in]visible-in-index Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 59/76] diff.c: convert -z Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 60/76] diff.c: convert -l Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 61/76] diff.c: convert -S|-G Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 62/76] diff.c: convert --pickaxe-all|--pickaxe-regex Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 63/76] diff.c: convert -O Nguyễn Thái Ngọc Duy
2019-01-21 12:14   ` Johannes Schindelin
2019-01-17 13:06 ` [PATCH 64/76] diff.c: convert --find-object Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 65/76] diff.c: convert --diff-filter Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 66/76] diff.c: convert --[no-]abbrev Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 67/76] diff.c: convert --[src|dst]-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 68/76] diff.c: convert --line-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 69/76] diff.c: convert --no-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 70/76] diff.c: convert --inter-hunk-context Nguyễn Thái Ngọc Duy
2019-01-19  1:18   ` SZEDER Gábor
2019-01-17 13:06 ` [PATCH 71/76] diff.c: convert --color-moved Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 72/76] diff.c: convert --color-moved-ws Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 73/76] diff.c: allow --no-color-moved-ws Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-17 19:46   ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Stefan Beller
2019-01-18  9:30     ` Duy Nguyen
2019-01-17 13:06 ` [PATCH 75/76] diff --no-index: " Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 76/76] am: avoid diff_opt_parse() Nguyễn Thái Ngọc Duy
2019-01-17 20:10   ` Johannes Schindelin
2019-01-18  0:19     ` Duy Nguyen
2019-01-17 14:32 ` [PATCH 00/76] Convert diff opt parser to parse_options() Ævar Arnfjörð Bjarmason
2019-01-17 19:50   ` Stefan Beller

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=20190117130615.18732-75-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).