git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 00/76] Convert diff opt parser to parse_options()
@ 2019-01-17 13:04 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
                   ` (76 more replies)
  0 siblings, 77 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This series converts diff option parsing to using parse-options. There
are a couple benefits of using parse-options, including "git <cmd> -h"
output, completion and less duplicate work.

This is the first half. The second one would be converting the option
parser in revision.c.  After that, the end game is, any command can
take a 'struct option[]' somewhere from diff/rev code, remove the
options they are not interested, then merge with their own options and
do parse_options() just once. There will be no separate parse phase
for revision/diff anymore.

I sent a sneak peek [1] last year and got two good comments. I take it
people at least did not oppose to this. The most interesting parts are
at the top and bottom. The middle is just boring conversion, usually
one option per patch.

This will conflict with pw/diff-color-moved-ws-fix on 'pu' because
that series adds --no-color-moved-ws option. I redid the same thing in
73/76 so that conflict resolution could be simply taking this side of
change.

This series is also available for fetching here

https://gitlab.com/pclouds/git/commits/diff-opt-parse-options

[1] http://public-inbox.org/git/20181227162536.15895-1-pclouds@gmail.com/

Nguyễn Thái Ngọc Duy (76):
  parse-options.h: remove extern on function prototypes
  parse-options: add one-shot mode
  parse-options: allow keep-unknown + stop-at-non-opt combination
  parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
  parse-options: add OPT_BITOP()
  parse-options: stop abusing 'callback' for lowlevel callbacks
  parse-options: avoid magic return codes
  parse-options: allow ll_callback with OPTION_CALLBACK
  diff.h: keep forward struct declarations sorted
  diff.h: avoid bit fields in struct diff_flags
  diff.c: prepare to use parse_options() for parsing
  diff.c: convert -u|-p|--patch
  diff.c: convert -U|--unified
  diff.c: convert -W|--[no-]function-context
  diff.c: convert --raw
  diff.c: convert --patch-with-raw
  diff.c: convert --numstat and --shortstat
  diff.c: convert --dirstat and friends
  diff.c: convert --check
  diff.c: convert --summary
  diff.c: convert --patch-with-stat
  diff.c: convert --name-only
  diff.c: convert --name-status
  diff.c: convert -s|--no-patch
  diff.c: convert --stat*
  diff.c: convert --[no-]compact-summary
  diff.c: convert --output-*
  diff.c: convert -B|--break-rewrites
  diff.c: convert -M|--find-renames
  diff.c: convert -D|--irreversible-delete
  diff.c: convert -C|--find-copies
  diff.c: convert --find-copies-harder
  diff.c: convert --no-renames|--[no--rename-empty
  diff.c: convert --relative
  diff.c: convert --[no-]minimal
  diff.c: convert --ignore-some-changes
  diff.c: convert --[no-]indent-heuristic
  diff.c: convert --patience
  diff.c: convert --histogram
  diff.c: convert --diff-algorithm
  diff.c: convert --anchored
  diff.c: convert --binary
  diff.c: convert --full-index
  diff.c: convert -a|--text
  diff.c: convert -R
  diff.c: convert --[no-]follow
  diff.c: convert --[no-]color
  diff.c: convert --word-diff
  diff.c: convert --word-diff-regex
  diff.c: convert --color-words
  diff.c: convert --exit-code
  diff.c: convert --quiet
  diff.c: convert --ext-diff
  diff.c: convert --textconv
  diff.c: convert --ignore-submodules
  diff.c: convert --submodule
  diff.c: convert --ws-error-highlight
  diff.c: convert --ita-[in]visible-in-index
  diff.c: convert -z
  diff.c: convert -l
  diff.c: convert -S|-G
  diff.c: convert --pickaxe-all|--pickaxe-regex
  diff.c: convert -O
  diff.c: convert --find-object
  diff.c: convert --diff-filter
  diff.c: convert --[no-]abbrev
  diff.c: convert --[src|dst]-prefix
  diff.c: convert --line-prefix
  diff.c: convert --no-prefix
  diff.c: convert --inter-hunk-context
  diff.c: convert --color-moved
  diff.c: convert --color-moved-ws
  diff.c: allow --no-color-moved-ws
  range-diff: use parse_options() instead of diff_opt_parse()
  diff --no-index: use parse_options() instead of diff_opt_parse()
  am: avoid diff_opt_parse()

 Documentation/diff-options.txt |   24 +-
 builtin/am.c                   |    4 +-
 builtin/blame.c                |    2 +-
 builtin/diff.c                 |   21 +-
 builtin/merge.c                |    9 +-
 builtin/range-diff.c           |   26 +-
 builtin/update-index.c         |   41 +-
 diff-no-index.c                |   49 +-
 diff.c                         | 1136 ++++++++++++++++++++------------
 diff.h                         |   85 +--
 parse-options-cb.c             |   11 +-
 parse-options.c                |  152 +++--
 parse-options.h                |  114 ++--
 t/t4053-diff-no-index.sh       |    3 +-
 t/t7800-difftool.sh            |    4 +-
 15 files changed, 1054 insertions(+), 627 deletions(-)

-- 
2.20.0.482.g66447595a7


^ permalink raw reply	[flat|nested] 88+ messages in thread

* [PATCH 01/76] parse-options.h: remove extern on function prototypes
  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 ` 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
                   ` (75 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.h | 58 ++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/parse-options.h b/parse-options.h
index 14fe32428e..f5e7ec7d23 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -174,18 +174,18 @@ struct option {
  * for translation with N_().
  * Returns the number of arguments left in argv[].
  */
-extern int parse_options(int argc, const char **argv, const char *prefix,
-			 const struct option *options,
-			 const char * const usagestr[], int flags);
+int parse_options(int argc, const char **argv, const char *prefix,
+		  const struct option *options,
+		  const char * const usagestr[], int flags);
 
-extern NORETURN void usage_with_options(const char * const *usagestr,
-					const struct option *options);
+NORETURN void usage_with_options(const char * const *usagestr,
+				 const struct option *options);
 
-extern NORETURN void usage_msg_opt(const char *msg,
-				   const char * const *usagestr,
-				   const struct option *options);
+NORETURN void usage_msg_opt(const char *msg,
+			    const char * const *usagestr,
+			    const struct option *options);
 
-extern int optbug(const struct option *opt, const char *reason);
+int optbug(const struct option *opt, const char *reason);
 const char *optname(const struct option *opt, int flags);
 
 /*
@@ -227,31 +227,31 @@ struct parse_opt_ctx_t {
 	const char *prefix;
 };
 
-extern void parse_options_start(struct parse_opt_ctx_t *ctx,
-				int argc, const char **argv, const char *prefix,
-				const struct option *options, int flags);
+void parse_options_start(struct parse_opt_ctx_t *ctx,
+			 int argc, const char **argv, const char *prefix,
+			 const struct option *options, int flags);
 
-extern int parse_options_step(struct parse_opt_ctx_t *ctx,
-			      const struct option *options,
-			      const char * const usagestr[]);
+int parse_options_step(struct parse_opt_ctx_t *ctx,
+		       const struct option *options,
+		       const char * const usagestr[]);
 
-extern int parse_options_end(struct parse_opt_ctx_t *ctx);
+int parse_options_end(struct parse_opt_ctx_t *ctx);
 
-extern struct option *parse_options_concat(struct option *a, struct option *b);
+struct option *parse_options_concat(struct option *a, struct option *b);
 
 /*----- some often used options -----*/
-extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
-extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
-extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
-extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
-extern int parse_opt_object_name(const struct option *, const char *, int);
-extern int parse_opt_commits(const struct option *, const char *, int);
-extern int parse_opt_tertiary(const struct option *, const char *, int);
-extern int parse_opt_string_list(const struct option *, const char *, int);
-extern int parse_opt_noop_cb(const struct option *, const char *, int);
-extern int parse_opt_unknown_cb(const struct option *, const char *, int);
-extern int parse_opt_passthru(const struct option *, const char *, int);
-extern int parse_opt_passthru_argv(const struct option *, const char *, int);
+int parse_opt_abbrev_cb(const struct option *, const char *, int);
+int parse_opt_expiry_date_cb(const struct option *, const char *, int);
+int parse_opt_color_flag_cb(const struct option *, const char *, int);
+int parse_opt_verbosity_cb(const struct option *, const char *, int);
+int parse_opt_object_name(const struct option *, const char *, int);
+int parse_opt_commits(const struct option *, const char *, int);
+int parse_opt_tertiary(const struct option *, const char *, int);
+int parse_opt_string_list(const struct option *, const char *, int);
+int parse_opt_noop_cb(const struct option *, const char *, int);
+int parse_opt_unknown_cb(const struct option *, const char *, int);
+int parse_opt_passthru(const struct option *, const char *, int);
+int parse_opt_passthru_argv(const struct option *, const char *, int);
 
 #define OPT__VERBOSE(var, h)  OPT_COUNTUP('v', "verbose", (var), (h))
 #define OPT__QUIET(var, h)    OPT_COUNTUP('q', "quiet",   (var), (h))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 02/76] parse-options: add one-shot mode
  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 ` 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
                   ` (74 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This is to help reimplement diff_opt_parse() using parse_options().
The behavior of parse_options() is changed to be the same as the
other:

- no argv0 in argv[], everything can be processed
- argv[] must not be updated, it's the caller's job to do that
- return the number of arguments processed
- leave all unknown options / non-options alone (this one can already
  be achieved with PARSE_OPT_KEEP_UNKNOWN and
  PARSE_OPT_STOP_AT_NON_OPTION)

This mode is NOT supposed to stay here for long. It's to help
converting diff/rev option parsing. Once that work is over and we can
just use parse_options() throughout the code base, this will be
deleted.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 23 ++++++++++++++++++++---
 parse-options.h | 17 +++++++++++++----
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index 9f84bacce6..eb5de0da29 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -416,15 +416,23 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
 			 const struct option *options, int flags)
 {
 	memset(ctx, 0, sizeof(*ctx));
-	ctx->argc = ctx->total = argc - 1;
-	ctx->argv = argv + 1;
-	ctx->out  = argv;
+	ctx->argc = argc;
+	ctx->argv = argv;
+	if (!(flags & PARSE_OPT_ONE_SHOT)) {
+		ctx->argc--;
+		ctx->argv++;
+	}
+	ctx->total = ctx->argc;
+	ctx->out   = argv;
 	ctx->prefix = prefix;
 	ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
 	ctx->flags = flags;
 	if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
 	    (flags & PARSE_OPT_STOP_AT_NON_OPTION))
 		BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
+	if ((flags & PARSE_OPT_ONE_SHOT) &&
+	    (flags & PARSE_OPT_KEEP_ARGV0))
+		BUG("Can't keep argv0 if you don't have it");
 	parse_options_check(options);
 }
 
@@ -536,6 +544,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 	for (; ctx->argc; ctx->argc--, ctx->argv++) {
 		const char *arg = ctx->argv[0];
 
+		if (ctx->flags & PARSE_OPT_ONE_SHOT &&
+		    ctx->argc != ctx->total)
+			break;
+
 		if (*arg != '-' || !arg[1]) {
 			if (parse_nodash_opt(ctx, arg, options) == 0)
 				continue;
@@ -610,6 +622,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		}
 		continue;
 unknown:
+		if (ctx->flags & PARSE_OPT_ONE_SHOT)
+			break;
 		if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN))
 			return PARSE_OPT_UNKNOWN;
 		ctx->out[ctx->cpidx++] = ctx->argv[0];
@@ -623,6 +637,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 
 int parse_options_end(struct parse_opt_ctx_t *ctx)
 {
+	if (ctx->flags & PARSE_OPT_ONE_SHOT)
+		return ctx->total - ctx->argc;
+
 	MOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc);
 	ctx->out[ctx->cpidx + ctx->argc] = NULL;
 	return ctx->cpidx + ctx->argc;
diff --git a/parse-options.h b/parse-options.h
index f5e7ec7d23..d663b83973 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -27,7 +27,8 @@ enum parse_opt_flags {
 	PARSE_OPT_STOP_AT_NON_OPTION = 2,
 	PARSE_OPT_KEEP_ARGV0 = 4,
 	PARSE_OPT_KEEP_UNKNOWN = 8,
-	PARSE_OPT_NO_INTERNAL_HELP = 16
+	PARSE_OPT_NO_INTERNAL_HELP = 16,
+	PARSE_OPT_ONE_SHOT = 32
 };
 
 enum parse_opt_option_flags {
@@ -169,10 +170,18 @@ struct option {
 	  N_("no-op (backward compatibility)"),		\
 	  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
 
-/* parse_options() will filter out the processed options and leave the
- * non-option arguments in argv[]. usagestr strings should be marked
- * for translation with N_().
+/*
+ * parse_options() will filter out the processed options and leave the
+ * non-option arguments in argv[]. argv0 is assumed program name and
+ * skipped.
+ *
+ * usagestr strings should be marked for translation with N_().
+ *
  * Returns the number of arguments left in argv[].
+ *
+ * In one-shot mode, argv0 is not a program name, argv[] is left
+ * untouched and parse_options() returns the number of options
+ * processed.
  */
 int parse_options(int argc, const char **argv, const char *prefix,
 		  const struct option *options,
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination
  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 ` 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
                   ` (73 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

These two are orthogonal. One is about unknown _option_ while the
other non-option.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index eb5de0da29..678b263897 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -427,9 +427,6 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
 	ctx->prefix = prefix;
 	ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
 	ctx->flags = flags;
-	if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
-	    (flags & PARSE_OPT_STOP_AT_NON_OPTION))
-		BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
 	if ((flags & PARSE_OPT_ONE_SHOT) &&
 	    (flags & PARSE_OPT_KEEP_ARGV0))
 		BUG("Can't keep argv0 if you don't have it");
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 04/76] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  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 13:05 ` 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
                   ` (72 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

parse-options can unambiguously find an abbreviation only if it sees
all available options. This is usually the case when you use
parse_options(). But there are other callers like blame or shortlog
which uses parse_options_start() in combination with a custom option
parser, like rev-list. parse-options cannot see all options in this
case and will get abbrev detection wrong. Disable it.

t7800 needs update because --symlink no longer expands to --symlinks
and will be passed down to git-diff, which will not recognize it. I
still think this is the correct thing to do. But if --symlink has been
actually used in the wild, we would just add an option alias for it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c     | 3 ++-
 t/t7800-difftool.sh | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index 678b263897..9710ec9d5e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -266,7 +266,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 		}
 		if (!rest) {
 			/* abbreviated? */
-			if (!strncmp(long_name, arg, arg_end - arg)) {
+			if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
+			    !strncmp(long_name, arg, arg_end - arg)) {
 is_abbreviated:
 				if (abbrev_option) {
 					/*
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 22b9199d59..bb9a7f4ff9 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -546,7 +546,7 @@ do
 done >actual
 EOF
 
-test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
+test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
 	cat >expect <<-EOF &&
 	file
 	$PWD/file
@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha
 	sub/sub
 	$PWD/sub/sub
 	EOF
-	git difftool --dir-diff --symlink \
+	git difftool --dir-diff --symlinks \
 		--extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
 	test_cmp expect actual
 '
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 05/76] parse-options: add OPT_BITOP()
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (3 preceding siblings ...)
  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 ` 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
                   ` (71 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This is needed for diff_opt_parse() where we do

   value = (value & ~mask) | some_more;

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 7 +++++++
 parse-options.h | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/parse-options.c b/parse-options.c
index 9710ec9d5e..1244968855 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -109,6 +109,13 @@ static int get_value(struct parse_opt_ctx_t *p,
 			*(int *)opt->value &= ~opt->defval;
 		return 0;
 
+	case OPTION_BITOP:
+		if (unset)
+			BUG("BITOP can't have unset form");
+		*(int *)opt->value &= ~opt->extra;
+		*(int *)opt->value |= opt->defval;
+		return 0;
+
 	case OPTION_COUNTUP:
 		if (*(int *)opt->value < 0)
 			*(int *)opt->value = 0;
diff --git a/parse-options.h b/parse-options.h
index d663b83973..c97324f576 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -10,6 +10,7 @@ enum parse_opt_type {
 	/* options with no arguments */
 	OPTION_BIT,
 	OPTION_NEGBIT,
+	OPTION_BITOP,
 	OPTION_COUNTUP,
 	OPTION_SET_INT,
 	OPTION_CMDMODE,
@@ -118,6 +119,7 @@ struct option {
 	int flags;
 	parse_opt_cb *callback;
 	intptr_t defval;
+	intptr_t extra;
 };
 
 #define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \
@@ -133,6 +135,9 @@ struct option {
 				      (h), PARSE_OPT_NOARG}
 #define OPT_GROUP(h)                { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
 #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)
+#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
+					    PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
+					    (set), (clear) }
 #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, NULL, (b) }
 #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 06/76] parse-options: stop abusing 'callback' for lowlevel callbacks
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (4 preceding siblings ...)
  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 ` 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
                   ` (70 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Lowlevel callbacks have different function signatures. Add a new field
in 'struct option' with the right type for lowlevel callbacks.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/blame.c        |  2 +-
 builtin/merge.c        |  2 +-
 builtin/update-index.c | 11 ++++++-----
 parse-options-cb.c     |  3 ++-
 parse-options.c        | 15 ++++++++++++++-
 parse-options.h        | 12 ++++++++----
 6 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 6d798f9939..8dcc55dffa 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -814,7 +814,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 		 * and are only included here to get included in the "-h"
 		 * output:
 		 */
-		{ OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb },
+		{ OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, NULL, 0, parse_opt_unknown_cb },
 
 		OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
 		OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
diff --git a/builtin/merge.c b/builtin/merge.c
index dc0b7cc521..07839b0bb8 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -261,7 +261,7 @@ static struct option builtin_merge_options[] = {
 		option_parse_message),
 	{ OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
 		N_("read message from file"), PARSE_OPT_NONEG,
-		(parse_opt_cb *) option_read_message },
+		NULL, 0, option_read_message },
 	OPT__VERBOSITY(&verbosity),
 	OPT_BOOL(0, "abort", &abort_current_merge,
 		N_("abort the current in-progress merge")),
diff --git a/builtin/update-index.c b/builtin/update-index.c
index e19da77edc..727a8118b8 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -985,7 +985,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 			N_("add the specified entry to the index"),
 			PARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */
 			PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
-			(parse_opt_cb *) cacheinfo_callback},
+			NULL, 0,
+			cacheinfo_callback},
 		{OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x",
 			N_("override the executable bit of the listed files"),
 			PARSE_OPT_NONEG,
@@ -1011,19 +1012,19 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 		{OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &read_from_stdin, NULL,
 			N_("read list of paths to be updated from standard input"),
 			PARSE_OPT_NONEG | PARSE_OPT_NOARG,
-			(parse_opt_cb *) stdin_callback},
+			NULL, 0, stdin_callback},
 		{OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &nul_term_line, NULL,
 			N_("add entries from standard input to the index"),
 			PARSE_OPT_NONEG | PARSE_OPT_NOARG,
-			(parse_opt_cb *) stdin_cacheinfo_callback},
+			NULL, 0, stdin_cacheinfo_callback},
 		{OPTION_LOWLEVEL_CALLBACK, 0, "unresolve", &has_errors, NULL,
 			N_("repopulate stages #2 and #3 for the listed paths"),
 			PARSE_OPT_NONEG | PARSE_OPT_NOARG,
-			(parse_opt_cb *) unresolve_callback},
+			NULL, 0, unresolve_callback},
 		{OPTION_LOWLEVEL_CALLBACK, 'g', "again", &has_errors, NULL,
 			N_("only update entries that differ from HEAD"),
 			PARSE_OPT_NONEG | PARSE_OPT_NOARG,
-			(parse_opt_cb *) reupdate_callback},
+			NULL, 0, reupdate_callback},
 		OPT_BIT(0, "ignore-missing", &refresh_args.flags,
 			N_("ignore files missing from worktree"),
 			REFRESH_IGNORE_MISSING),
diff --git a/parse-options-cb.c b/parse-options-cb.c
index e2f3eaed07..e05bcea809 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -170,7 +170,8 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
  * "-h" output even if it's not being handled directly by
  * parse_options().
  */
-int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset)
+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
+			 const struct option *opt, int unset)
 {
 	return -2;
 }
diff --git a/parse-options.c b/parse-options.c
index 1244968855..ac109e11e9 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -93,7 +93,7 @@ static int get_value(struct parse_opt_ctx_t *p,
 
 	switch (opt->type) {
 	case OPTION_LOWLEVEL_CALLBACK:
-		return (*(parse_opt_ll_cb *)opt->callback)(p, opt, unset);
+		return opt->ll_callback(p, opt, unset);
 
 	case OPTION_BIT:
 		if (unset)
@@ -408,6 +408,19 @@ static void parse_options_check(const struct option *opts)
 			if ((opts->flags & PARSE_OPT_OPTARG) ||
 			    !(opts->flags & PARSE_OPT_NOARG))
 				err |= optbug(opts, "should not accept an argument");
+			break;
+		case OPTION_CALLBACK:
+			if (!opts->callback)
+				BUG("OPTION_CALLBACK needs a callback");
+			if (opts->ll_callback)
+				BUG("OPTION_CALLBACK needs no ll_callback");
+			break;
+		case OPTION_LOWLEVEL_CALLBACK:
+			if (!opts->ll_callback)
+				BUG("OPTION_LOWLEVEL_CALLBACK needs a callback");
+			if (opts->callback)
+				BUG("OPTION_LOWLEVEL_CALLBACK needs no high level callback");
+			break;
 		default:
 			; /* ok. (usually accepts an argument) */
 		}
diff --git a/parse-options.h b/parse-options.h
index c97324f576..f1f246387c 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -100,13 +100,16 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
  *			 the option takes optional argument.
  *
  * `callback`::
- *   pointer to the callback to use for OPTION_CALLBACK or
- *   OPTION_LOWLEVEL_CALLBACK.
+ *   pointer to the callback to use for OPTION_CALLBACK
  *
  * `defval`::
  *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
  *   OPTION_{BIT,SET_INT} store the {mask,integer} to put in the value when met.
  *   CALLBACKS can use it like they want.
+ *
+ * `ll_callback`::
+ *   pointer to the callback to use for OPTION_LOWLEVEL_CALLBACK
+ *
  */
 struct option {
 	enum parse_opt_type type;
@@ -119,6 +122,7 @@ struct option {
 	int flags;
 	parse_opt_cb *callback;
 	intptr_t defval;
+	parse_opt_ll_cb *ll_callback;
 	intptr_t extra;
 };
 
@@ -137,7 +141,7 @@ struct option {
 #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)
 #define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
 					    PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
-					    (set), (clear) }
+					    (set), NULL, (clear) }
 #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, NULL, (b) }
 #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)
@@ -263,7 +267,7 @@ int parse_opt_commits(const struct option *, const char *, int);
 int parse_opt_tertiary(const struct option *, const char *, int);
 int parse_opt_string_list(const struct option *, const char *, int);
 int parse_opt_noop_cb(const struct option *, const char *, int);
-int parse_opt_unknown_cb(const struct option *, const char *, int);
+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int);
 int parse_opt_passthru(const struct option *, const char *, int);
 int parse_opt_passthru_argv(const struct option *, const char *, int);
 
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 07/76] parse-options: avoid magic return codes
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (5 preceding siblings ...)
  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 ` 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
                   ` (69 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Give names to these magic negative numbers. Make parse_opt_ll_cb
return an enum to make clear it can actually control parse_options()
with different return values (parse_opt_cb can too, but nobody needs
it).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/merge.c        |  5 +--
 builtin/update-index.c | 20 ++++++------
 parse-options-cb.c     |  6 ++--
 parse-options.c        | 69 +++++++++++++++++++++++++++---------------
 parse-options.h        | 14 ++++-----
 5 files changed, 68 insertions(+), 46 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 07839b0bb8..de64d7850e 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -112,8 +112,9 @@ static int option_parse_message(const struct option *opt,
 	return 0;
 }
 
-static int option_read_message(struct parse_opt_ctx_t *ctx,
-			       const struct option *opt, int unset)
+static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx,
+						 const struct option *opt,
+						 int unset)
 {
 	struct strbuf *buf = opt->value;
 	const char *arg;
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 727a8118b8..21c84e5590 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -847,8 +847,8 @@ static int parse_new_style_cacheinfo(const char *arg,
 	return 0;
 }
 
-static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
-				const struct option *opt, int unset)
+static enum parse_opt_result cacheinfo_callback(
+	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
 {
 	struct object_id oid;
 	unsigned int mode;
@@ -873,8 +873,8 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
-static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,
-			      const struct option *opt, int unset)
+static enum parse_opt_result stdin_cacheinfo_callback(
+	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
 {
 	int *nul_term_line = opt->value;
 
@@ -887,8 +887,8 @@ static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
-static int stdin_callback(struct parse_opt_ctx_t *ctx,
-				const struct option *opt, int unset)
+static enum parse_opt_result stdin_callback(
+	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
 {
 	int *read_from_stdin = opt->value;
 
@@ -900,8 +900,8 @@ static int stdin_callback(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
-static int unresolve_callback(struct parse_opt_ctx_t *ctx,
-				const struct option *opt, int unset)
+static enum parse_opt_result unresolve_callback(
+	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
 {
 	int *has_errors = opt->value;
 	const char *prefix = startup_info->prefix;
@@ -919,8 +919,8 @@ static int unresolve_callback(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
-static int reupdate_callback(struct parse_opt_ctx_t *ctx,
-				const struct option *opt, int unset)
+static enum parse_opt_result reupdate_callback(
+	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
 {
 	int *has_errors = opt->value;
 	const char *prefix = startup_info->prefix;
diff --git a/parse-options-cb.c b/parse-options-cb.c
index e05bcea809..ec01ef722b 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -170,10 +170,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
  * "-h" output even if it's not being handled directly by
  * parse_options().
  */
-int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
-			 const struct option *opt, int unset)
+enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
+					   const struct option *opt, int unset)
 {
-	return -2;
+	return PARSE_OPT_UNKNOWN;
 }
 
 /**
diff --git a/parse-options.c b/parse-options.c
index ac109e11e9..372f5cede4 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -20,8 +20,9 @@ int optbug(const struct option *opt, const char *reason)
 	return error("BUG: switch '%c' %s", opt->short_name, reason);
 }
 
-static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
-		   int flags, const char **arg)
+static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p,
+				     const struct option *opt,
+				     int flags, const char **arg)
 {
 	if (p->opt) {
 		*arg = p->opt;
@@ -44,9 +45,10 @@ static void fix_filename(const char *prefix, const char **file)
 	*file = prefix_filename(prefix, *file);
 }
 
-static int opt_command_mode_error(const struct option *opt,
-				  const struct option *all_opts,
-				  int flags)
+static enum parse_opt_result opt_command_mode_error(
+	const struct option *opt,
+	const struct option *all_opts,
+	int flags)
 {
 	const struct option *that;
 	struct strbuf that_name = STRBUF_INIT;
@@ -69,16 +71,16 @@ static int opt_command_mode_error(const struct option *opt,
 		error(_("%s is incompatible with %s"),
 		      optname(opt, flags), that_name.buf);
 		strbuf_release(&that_name);
-		return -1;
+		return PARSE_OPT_ERROR;
 	}
 	return error(_("%s : incompatible with something else"),
 		     optname(opt, flags));
 }
 
-static int get_value(struct parse_opt_ctx_t *p,
-		     const struct option *opt,
-		     const struct option *all_opts,
-		     int flags)
+static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
+				       const struct option *opt,
+				       const struct option *all_opts,
+				       int flags)
 {
 	const char *s, *arg;
 	const int unset = flags & OPT_UNSET;
@@ -208,7 +210,8 @@ static int get_value(struct parse_opt_ctx_t *p,
 	}
 }
 
-static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options)
+static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p,
+					     const struct option *options)
 {
 	const struct option *all_opts = options;
 	const struct option *numopt = NULL;
@@ -239,11 +242,12 @@ static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *optio
 		free(arg);
 		return rc;
 	}
-	return -2;
+	return PARSE_OPT_UNKNOWN;
 }
 
-static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
-			  const struct option *options)
+static enum parse_opt_result parse_long_opt(
+	struct parse_opt_ctx_t *p, const char *arg,
+	const struct option *options)
 {
 	const struct option *all_opts = options;
 	const char *arg_end = strchrnul(arg, '=');
@@ -269,7 +273,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 			if (*rest)
 				continue;
 			p->out[p->cpidx++] = arg - 2;
-			return 0;
+			return PARSE_OPT_DONE;
 		}
 		if (!rest) {
 			/* abbreviated? */
@@ -334,11 +338,11 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 			ambiguous_option->long_name,
 			(abbrev_flags & OPT_UNSET) ?  "no-" : "",
 			abbrev_option->long_name);
-		return -3;
+		return PARSE_OPT_HELP;
 	}
 	if (abbrev_option)
 		return get_value(p, abbrev_option, all_opts, abbrev_flags);
-	return -2;
+	return PARSE_OPT_UNKNOWN;
 }
 
 static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
@@ -586,22 +590,28 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		if (arg[1] != '-') {
 			ctx->opt = arg + 1;
 			switch (parse_short_opt(ctx, options)) {
-			case -1:
+			case PARSE_OPT_ERROR:
 				return PARSE_OPT_ERROR;
-			case -2:
+			case PARSE_OPT_UNKNOWN:
 				if (ctx->opt)
 					check_typos(arg + 1, options);
 				if (internal_help && *ctx->opt == 'h')
 					goto show_usage;
 				goto unknown;
+			case PARSE_OPT_NON_OPTION:
+			case PARSE_OPT_HELP:
+			case PARSE_OPT_COMPLETE:
+				BUG("parse_short_opt() cannot return these");
+			case PARSE_OPT_DONE:
+				break;
 			}
 			if (ctx->opt)
 				check_typos(arg + 1, options);
 			while (ctx->opt) {
 				switch (parse_short_opt(ctx, options)) {
-				case -1:
+				case PARSE_OPT_ERROR:
 					return PARSE_OPT_ERROR;
-				case -2:
+				case PARSE_OPT_UNKNOWN:
 					if (internal_help && *ctx->opt == 'h')
 						goto show_usage;
 
@@ -613,6 +623,12 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 					ctx->argv[0] = xstrdup(ctx->opt - 1);
 					*(char *)ctx->argv[0] = '-';
 					goto unknown;
+				case PARSE_OPT_NON_OPTION:
+				case PARSE_OPT_COMPLETE:
+				case PARSE_OPT_HELP:
+					BUG("parse_short_opt() cannot return these");
+				case PARSE_OPT_DONE:
+					break;
 				}
 			}
 			continue;
@@ -631,12 +647,17 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		if (internal_help && !strcmp(arg + 2, "help"))
 			goto show_usage;
 		switch (parse_long_opt(ctx, arg + 2, options)) {
-		case -1:
+		case PARSE_OPT_ERROR:
 			return PARSE_OPT_ERROR;
-		case -2:
+		case PARSE_OPT_UNKNOWN:
 			goto unknown;
-		case -3:
+		case PARSE_OPT_HELP:
 			goto show_usage;
+		case PARSE_OPT_NON_OPTION:
+		case PARSE_OPT_COMPLETE:
+			BUG("parse_long_opt() cannot return these");
+		case PARSE_OPT_DONE:
+			break;
 		}
 		continue;
 unknown:
diff --git a/parse-options.h b/parse-options.h
index f1f246387c..4e49185027 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -49,8 +49,8 @@ struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
 struct parse_opt_ctx_t;
-typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
-				const struct option *opt, int unset);
+typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
+					      const struct option *opt, int unset);
 
 /*
  * `type`::
@@ -222,12 +222,12 @@ const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
-enum {
-	PARSE_OPT_COMPLETE = -2,
-	PARSE_OPT_HELP = -1,
-	PARSE_OPT_DONE,
+enum parse_opt_result {
+	PARSE_OPT_COMPLETE = -3,
+	PARSE_OPT_HELP = -2,
+	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
+	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
 	PARSE_OPT_NON_OPTION,
-	PARSE_OPT_ERROR,
 	PARSE_OPT_UNKNOWN
 };
 
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 08/76] parse-options: allow ll_callback with OPTION_CALLBACK
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (6 preceding siblings ...)
  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 ` 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
                   ` (68 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

OPTION_CALLBACK is much simpler/safer to use, but parse_opt_cb does
not allow access to parse_opt_ctx_t, which sometimes is useful
(e.g. to obtain the prefix).

Extending parse_opt_cb to take parse_opt_cb could result in a lot of
changes. Instead let's just allow ll_callback to be used with
OPTION_CALLBACK. The user will have to be careful, not to change
anything in ctx, or return wrong result code. But that's the price for
ll_callback.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/merge.c        |  2 ++
 builtin/update-index.c | 20 +++++++++++++++-----
 parse-options-cb.c     |  4 +++-
 parse-options.c        | 42 ++++++++++++++++++++++++++++--------------
 parse-options.h        |  5 +++--
 5 files changed, 51 insertions(+), 22 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index de64d7850e..563a16f38a 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -114,11 +114,13 @@ static int option_parse_message(const struct option *opt,
 
 static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx,
 						 const struct option *opt,
+						 const char *arg_not_used,
 						 int unset)
 {
 	struct strbuf *buf = opt->value;
 	const char *arg;
 
+	BUG_ON_OPT_ARG(arg_not_used);
 	if (unset)
 		BUG("-F cannot be negated");
 
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 21c84e5590..7abde20169 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -848,13 +848,15 @@ static int parse_new_style_cacheinfo(const char *arg,
 }
 
 static enum parse_opt_result cacheinfo_callback(
-	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
+	struct parse_opt_ctx_t *ctx, const struct option *opt,
+	const char *arg, int unset)
 {
 	struct object_id oid;
 	unsigned int mode;
 	const char *path;
 
 	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
 
 	if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) {
 		if (add_cacheinfo(mode, &oid, path, 0))
@@ -874,11 +876,13 @@ static enum parse_opt_result cacheinfo_callback(
 }
 
 static enum parse_opt_result stdin_cacheinfo_callback(
-	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
+	struct parse_opt_ctx_t *ctx, const struct option *opt,
+	const char *arg, int unset)
 {
 	int *nul_term_line = opt->value;
 
 	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
 
 	if (ctx->argc != 1)
 		return error("option '%s' must be the last argument", opt->long_name);
@@ -888,11 +892,13 @@ static enum parse_opt_result stdin_cacheinfo_callback(
 }
 
 static enum parse_opt_result stdin_callback(
-	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
+	struct parse_opt_ctx_t *ctx, const struct option *opt,
+	const char *arg, int unset)
 {
 	int *read_from_stdin = opt->value;
 
 	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
 
 	if (ctx->argc != 1)
 		return error("option '%s' must be the last argument", opt->long_name);
@@ -901,12 +907,14 @@ static enum parse_opt_result stdin_callback(
 }
 
 static enum parse_opt_result unresolve_callback(
-	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
+	struct parse_opt_ctx_t *ctx, const struct option *opt,
+	const char *arg, int unset)
 {
 	int *has_errors = opt->value;
 	const char *prefix = startup_info->prefix;
 
 	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
 
 	/* consume remaining arguments. */
 	*has_errors = do_unresolve(ctx->argc, ctx->argv,
@@ -920,12 +928,14 @@ static enum parse_opt_result unresolve_callback(
 }
 
 static enum parse_opt_result reupdate_callback(
-	struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
+	struct parse_opt_ctx_t *ctx, const struct option *opt,
+	const char *arg, int unset)
 {
 	int *has_errors = opt->value;
 	const char *prefix = startup_info->prefix;
 
 	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
 
 	/* consume remaining arguments. */
 	setup_work_tree();
diff --git a/parse-options-cb.c b/parse-options-cb.c
index ec01ef722b..2733393546 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -171,8 +171,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
  * parse_options().
  */
 enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
-					   const struct option *opt, int unset)
+					   const struct option *opt,
+					   const char *arg, int unset)
 {
+	BUG_ON_OPT_ARG(arg);
 	return PARSE_OPT_UNKNOWN;
 }
 
diff --git a/parse-options.c b/parse-options.c
index 372f5cede4..a0ff8ea225 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -95,7 +95,7 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
 
 	switch (opt->type) {
 	case OPTION_LOWLEVEL_CALLBACK:
-		return opt->ll_callback(p, opt, unset);
+		return opt->ll_callback(p, opt, NULL, unset);
 
 	case OPTION_BIT:
 		if (unset)
@@ -161,16 +161,27 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
 		return err;
 
 	case OPTION_CALLBACK:
+	{
+		const char *p_arg = NULL;
+		int p_unset;
+
 		if (unset)
-			return (*opt->callback)(opt, NULL, 1) ? (-1) : 0;
-		if (opt->flags & PARSE_OPT_NOARG)
-			return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
-		if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
-			return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
-		if (get_arg(p, opt, flags, &arg))
+			p_unset = 1;
+		else if (opt->flags & PARSE_OPT_NOARG)
+			p_unset = 0;
+		else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
+			p_unset = 0;
+		else if (get_arg(p, opt, flags, &arg))
 			return -1;
-		return (*opt->callback)(opt, arg, 0) ? (-1) : 0;
-
+		else {
+			p_unset = 0;
+			p_arg = arg;
+		}
+		if (opt->callback)
+			return (*opt->callback)(opt, p_arg, p_unset) ? (-1) : 0;
+		else
+			return (*opt->ll_callback)(p, opt, p_arg, p_unset);
+	}
 	case OPTION_INTEGER:
 		if (unset) {
 			*(int *)opt->value = 0;
@@ -238,7 +249,10 @@ static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p,
 			len++;
 		arg = xmemdupz(p->opt, len);
 		p->opt = p->opt[len] ? p->opt + len : NULL;
-		rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;
+		if (numopt->callback)
+			rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;
+		else
+			rc = (*numopt->ll_callback)(p, numopt, arg, 0);
 		free(arg);
 		return rc;
 	}
@@ -414,10 +428,10 @@ static void parse_options_check(const struct option *opts)
 				err |= optbug(opts, "should not accept an argument");
 			break;
 		case OPTION_CALLBACK:
-			if (!opts->callback)
-				BUG("OPTION_CALLBACK needs a callback");
-			if (opts->ll_callback)
-				BUG("OPTION_CALLBACK needs no ll_callback");
+			if (!opts->callback && !opts->ll_callback)
+				BUG("OPTION_CALLBACK needs one callback");
+			if (opts->callback && opts->ll_callback)
+				BUG("OPTION_CALLBACK can't have two callbacks");
 			break;
 		case OPTION_LOWLEVEL_CALLBACK:
 			if (!opts->ll_callback)
diff --git a/parse-options.h b/parse-options.h
index 4e49185027..ce75278804 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -50,7 +50,8 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
 struct parse_opt_ctx_t;
 typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
-					      const struct option *opt, int unset);
+					      const struct option *opt,
+					      const char *arg, int unset);
 
 /*
  * `type`::
@@ -267,7 +268,7 @@ int parse_opt_commits(const struct option *, const char *, int);
 int parse_opt_tertiary(const struct option *, const char *, int);
 int parse_opt_string_list(const struct option *, const char *, int);
 int parse_opt_noop_cb(const struct option *, const char *, int);
-int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int);
+int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, const char *, int);
 int parse_opt_passthru(const struct option *, const char *, int);
 int parse_opt_passthru_argv(const struct option *, const char *, int);
 
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 09/76] diff.h: keep forward struct declarations sorted
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (7 preceding siblings ...)
  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 ` 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
                   ` (67 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.h b/diff.h
index b512d0477a..c872a41344 100644
--- a/diff.h
+++ b/diff.h
@@ -9,16 +9,16 @@
 #include "object.h"
 #include "oidset.h"
 
-struct rev_info;
+struct combine_diff_path;
+struct commit;
+struct diff_filespec;
 struct diff_options;
 struct diff_queue_struct;
-struct strbuf;
-struct diff_filespec;
-struct userdiff_driver;
 struct oid_array;
-struct commit;
-struct combine_diff_path;
 struct repository;
+struct rev_info;
+struct strbuf;
+struct userdiff_driver;
 
 typedef int (*pathchange_fn_t)(struct diff_options *options,
 		 struct combine_diff_path *path);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 10/76] diff.h: avoid bit fields in struct diff_flags
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (8 preceding siblings ...)
  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 ` 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
                   ` (66 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Bitfield addresses cannot be passed around in a pointer. This makes it
hard to use parse-options to set/unset them. Turn this struct to
normal integers. This of course increases the size of this struct
multiple times, but since we only have a handful of diff_options
variables around, memory consumption is not at all a concern.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.h | 66 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/diff.h b/diff.h
index c872a41344..8abe1649d0 100644
--- a/diff.h
+++ b/diff.h
@@ -64,39 +64,39 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 
 #define DIFF_FLAGS_INIT { 0 }
 struct diff_flags {
-	unsigned recursive:1;
-	unsigned tree_in_recursive:1;
-	unsigned binary:1;
-	unsigned text:1;
-	unsigned full_index:1;
-	unsigned silent_on_remove:1;
-	unsigned find_copies_harder:1;
-	unsigned follow_renames:1;
-	unsigned rename_empty:1;
-	unsigned has_changes:1;
-	unsigned quick:1;
-	unsigned no_index:1;
-	unsigned allow_external:1;
-	unsigned exit_with_status:1;
-	unsigned reverse_diff:1;
-	unsigned check_failed:1;
-	unsigned relative_name:1;
-	unsigned ignore_submodules:1;
-	unsigned dirstat_cumulative:1;
-	unsigned dirstat_by_file:1;
-	unsigned allow_textconv:1;
-	unsigned textconv_set_via_cmdline:1;
-	unsigned diff_from_contents:1;
-	unsigned dirty_submodules:1;
-	unsigned ignore_untracked_in_submodules:1;
-	unsigned ignore_dirty_submodules:1;
-	unsigned override_submodule_config:1;
-	unsigned dirstat_by_line:1;
-	unsigned funccontext:1;
-	unsigned default_follow_renames:1;
-	unsigned stat_with_summary:1;
-	unsigned suppress_diff_headers:1;
-	unsigned dual_color_diffed_diffs:1;
+	unsigned recursive;
+	unsigned tree_in_recursive;
+	unsigned binary;
+	unsigned text;
+	unsigned full_index;
+	unsigned silent_on_remove;
+	unsigned find_copies_harder;
+	unsigned follow_renames;
+	unsigned rename_empty;
+	unsigned has_changes;
+	unsigned quick;
+	unsigned no_index;
+	unsigned allow_external;
+	unsigned exit_with_status;
+	unsigned reverse_diff;
+	unsigned check_failed;
+	unsigned relative_name;
+	unsigned ignore_submodules;
+	unsigned dirstat_cumulative;
+	unsigned dirstat_by_file;
+	unsigned allow_textconv;
+	unsigned textconv_set_via_cmdline;
+	unsigned diff_from_contents;
+	unsigned dirty_submodules;
+	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_dirty_submodules;
+	unsigned override_submodule_config;
+	unsigned dirstat_by_line;
+	unsigned funccontext;
+	unsigned default_follow_renames;
+	unsigned stat_with_summary;
+	unsigned suppress_diff_headers;
+	unsigned dual_color_diffed_diffs;
 };
 
 static inline void diff_flags_or(struct diff_flags *a,
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 11/76] diff.c: prepare to use parse_options() for parsing
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (9 preceding siblings ...)
  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 ` 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
                   ` (65 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This is a preparation step to start using parse_options() to parse
diff/revision options instead of what we have now. There are a couple
of good things from using parse_options():

- better help usage
- easier to add new options
- better completion support
- help usage generation
- better integration with main command option parser. We can just
  concat the main command's option array and diffopt's together and
  parse all in one go.
- detect colidding options (e.g. --reverse is used by revision code,
  so diff code can't use it as long name for -R)
- consistent syntax, e.g. option that takes mandatory argument will
  now accept both "--option=value" and "--option value".

The plan is migrate all diff/rev options to parse_options(). Then we
could get rid of diff_opt_parse() and expose parseopts[] directly to
the caller.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 27 +++++++++++++++++++++++++++
 diff.h |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/diff.c b/diff.c
index f1e901a5fc..60f46052a4 100644
--- a/diff.c
+++ b/diff.c
@@ -23,6 +23,7 @@
 #include "argv-array.h"
 #include "graph.h"
 #include "packfile.h"
+#include "parse-options.h"
 #include "help.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
@@ -4424,6 +4425,8 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
 	builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
 }
 
+static void prep_parse_options(struct diff_options *options);
+
 void repo_diff_setup(struct repository *r, struct diff_options *options)
 {
 	memcpy(options, &default_diff_options, sizeof(*options));
@@ -4465,6 +4468,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 
 	options->color_moved = diff_color_moved_default;
 	options->color_moved_ws_handling = diff_color_moved_ws_default;
+
+	prep_parse_options(options);
 }
 
 void diff_setup_done(struct diff_options *options)
@@ -4568,6 +4573,8 @@ void diff_setup_done(struct diff_options *options)
 
 	if (!options->use_color || external_diff())
 		options->color_moved = 0;
+
+	FREE_AND_NULL(options->parseopts);
 }
 
 static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
@@ -4858,6 +4865,16 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static void prep_parse_options(struct diff_options *options)
+{
+	struct option parseopts[] = {
+		OPT_END()
+	};
+
+	ALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts));
+	memcpy(options->parseopts, parseopts, sizeof(parseopts));
+}
+
 int diff_opt_parse(struct diff_options *options,
 		   const char **av, int ac, const char *prefix)
 {
@@ -4868,6 +4885,16 @@ int diff_opt_parse(struct diff_options *options,
 	if (!prefix)
 		prefix = "";
 
+	ac = parse_options(ac, av, prefix, options->parseopts, NULL,
+			   PARSE_OPT_KEEP_DASHDASH |
+			   PARSE_OPT_KEEP_UNKNOWN |
+			   PARSE_OPT_NO_INTERNAL_HELP |
+			   PARSE_OPT_ONE_SHOT |
+			   PARSE_OPT_STOP_AT_NON_OPTION);
+
+	if (ac)
+		return ac;
+
 	/* Output format options */
 	if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
 	    || opt_arg(arg, 'U', "unified", &options->context))
diff --git a/diff.h b/diff.h
index 8abe1649d0..d9ad73f0e1 100644
--- a/diff.h
+++ b/diff.h
@@ -15,6 +15,7 @@ struct diff_filespec;
 struct diff_options;
 struct diff_queue_struct;
 struct oid_array;
+struct option;
 struct repository;
 struct rev_info;
 struct strbuf;
@@ -229,6 +230,7 @@ struct diff_options {
 	unsigned color_moved_ws_handling;
 
 	struct repository *repo;
+	struct option *parseopts;
 };
 
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 12/76] diff.c: convert -u|-p|--patch
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (10 preceding siblings ...)
  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 ` 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
                   ` (64 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/diff.c b/diff.c
index 60f46052a4..7b78af623b 100644
--- a/diff.c
+++ b/diff.c
@@ -4868,6 +4868,13 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 static void prep_parse_options(struct diff_options *options)
 {
 	struct option parseopts[] = {
+		OPT_GROUP(N_("Diff output format options")),
+		OPT_BITOP('p', "patch", &options->output_format,
+			  N_("generate patch"),
+			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
+		OPT_BITOP('u', NULL, &options->output_format,
+			  N_("generate patch"),
+			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
 		OPT_END()
 	};
 
@@ -4896,8 +4903,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
-	    || opt_arg(arg, 'U', "unified", &options->context))
+	if (opt_arg(arg, 'U', "unified", &options->context))
 		enable_patch_output(&options->output_format);
 	else if (!strcmp(arg, "--raw"))
 		options->output_format |= DIFF_FORMAT_RAW;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 13/76] diff.c: convert -U|--unified
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (11 preceding siblings ...)
  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 ` 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
                   ` (63 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  2 +-
 diff.c                         | 23 ++++++++++++++++++++---
 parse-options.h                |  5 +++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index b94d332f71..0711734b12 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -36,7 +36,7 @@ endif::git-format-patch[]
 -U<n>::
 --unified=<n>::
 	Generate diffs with <n> lines of context instead of
-	the usual three.
+	the usual three. Implies `--patch`.
 ifndef::git-format-patch[]
 	Implies `-p`.
 endif::git-format-patch[]
diff --git a/diff.c b/diff.c
index 7b78af623b..5e31b95426 100644
--- a/diff.c
+++ b/diff.c
@@ -4865,6 +4865,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_unified(const struct option *opt,
+			    const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+	char *s;
+
+	BUG_ON_OPT_NEG(unset);
+
+	options->context = strtol(arg, &s, 10);
+	if (*s)
+		return error(_("%s expects a numerical value"), "--unified");
+	enable_patch_output(&options->output_format);
+
+	return 0;
+}
+
 static void prep_parse_options(struct diff_options *options)
 {
 	struct option parseopts[] = {
@@ -4875,6 +4891,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BITOP('u', NULL, &options->output_format,
 			  N_("generate patch"),
 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
+		OPT_CALLBACK_F('U', "unified", options, N_("<n>"),
+			       N_("generate diffs with <n> lines context"),
+			       PARSE_OPT_NONEG, diff_opt_unified),
 		OPT_END()
 	};
 
@@ -4903,9 +4922,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (opt_arg(arg, 'U', "unified", &options->context))
-		enable_patch_output(&options->output_format);
-	else if (!strcmp(arg, "--raw"))
+	if (!strcmp(arg, "--raw"))
 		options->output_format |= DIFF_FORMAT_RAW;
 	else if (!strcmp(arg, "--patch-with-raw")) {
 		enable_patch_output(&options->output_format);
diff --git a/parse-options.h b/parse-options.h
index ce75278804..7d83e2971d 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -134,6 +134,8 @@ struct option {
 #define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \
 					  (h), PARSE_OPT_NOARG | (f), NULL, (i) }
 #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f)
+#define OPT_CALLBACK_F(s, l, v, a, h, f, cb)			\
+	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
 
 #define OPT_END()                   { OPTION_END }
 #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -164,8 +166,7 @@ struct option {
 #define OPT_EXPIRY_DATE(s, l, v, h) \
 	{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,	\
 	  parse_opt_expiry_date_cb }
-#define OPT_CALLBACK(s, l, v, a, h, f) \
-	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
+#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f)
 #define OPT_NUMBER_CALLBACK(v, h, f) \
 	{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
 	  PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 14/76] diff.c: convert -W|--[no-]function-context
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (12 preceding siblings ...)
  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 ` 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
                   ` (62 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 5e31b95426..db8cf7df87 100644
--- a/diff.c
+++ b/diff.c
@@ -4894,6 +4894,8 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F('U', "unified", options, N_("<n>"),
 			       N_("generate diffs with <n> lines context"),
 			       PARSE_OPT_NONEG, diff_opt_unified),
+		OPT_BOOL('W', "function-context", &options->flags.funccontext,
+			 N_("generate diffs with <n> lines context")),
 		OPT_END()
 	};
 
@@ -5210,12 +5212,6 @@ int diff_opt_parse(struct diff_options *options,
 	else if (opt_arg(arg, '\0', "inter-hunk-context",
 			 &options->interhunkcontext))
 		;
-	else if (!strcmp(arg, "-W"))
-		options->flags.funccontext = 1;
-	else if (!strcmp(arg, "--function-context"))
-		options->flags.funccontext = 1;
-	else if (!strcmp(arg, "--no-function-context"))
-		options->flags.funccontext = 0;
 	else if ((argcount = parse_long_opt("output", av, &optarg))) {
 		char *path = prefix_filename(prefix, optarg);
 		options->file = xfopen(path, "w");
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 15/76] diff.c: convert --raw
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (13 preceding siblings ...)
  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 ` 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
                   ` (61 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index db8cf7df87..2ebe9b23c5 100644
--- a/diff.c
+++ b/diff.c
@@ -4896,6 +4896,9 @@ static void prep_parse_options(struct diff_options *options)
 			       PARSE_OPT_NONEG, diff_opt_unified),
 		OPT_BOOL('W', "function-context", &options->flags.funccontext,
 			 N_("generate diffs with <n> lines context")),
+		OPT_BIT_F(0, "raw", &options->output_format,
+			  N_("generate the diff in raw format"),
+			  DIFF_FORMAT_RAW, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4924,9 +4927,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--raw"))
-		options->output_format |= DIFF_FORMAT_RAW;
-	else if (!strcmp(arg, "--patch-with-raw")) {
+	if (!strcmp(arg, "--patch-with-raw")) {
 		enable_patch_output(&options->output_format);
 		options->output_format |= DIFF_FORMAT_RAW;
 	} else if (!strcmp(arg, "--numstat"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 16/76] diff.c: convert --patch-with-raw
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (14 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 15/76] diff.c: convert --raw Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (60 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index 2ebe9b23c5..07796d2b3c 100644
--- a/diff.c
+++ b/diff.c
@@ -4899,6 +4899,10 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "raw", &options->output_format,
 			  N_("generate the diff in raw format"),
 			  DIFF_FORMAT_RAW, PARSE_OPT_NONEG),
+		OPT_BITOP(0, "patch-with-raw", &options->output_format,
+			  N_("synonym for '-p --raw'"),
+			  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,
+			  DIFF_FORMAT_NO_OUTPUT),
 		OPT_END()
 	};
 
@@ -4927,10 +4931,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--patch-with-raw")) {
-		enable_patch_output(&options->output_format);
-		options->output_format |= DIFF_FORMAT_RAW;
-	} else if (!strcmp(arg, "--numstat"))
+	if (!strcmp(arg, "--numstat"))
 		options->output_format |= DIFF_FORMAT_NUMSTAT;
 	else if (!strcmp(arg, "--shortstat"))
 		options->output_format |= DIFF_FORMAT_SHORTSTAT;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 17/76] diff.c: convert --numstat and --shortstat
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (15 preceding siblings ...)
  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 ` 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
                   ` (59 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index 07796d2b3c..69a4d55e38 100644
--- a/diff.c
+++ b/diff.c
@@ -4903,6 +4903,12 @@ static void prep_parse_options(struct diff_options *options)
 			  N_("synonym for '-p --raw'"),
 			  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,
 			  DIFF_FORMAT_NO_OUTPUT),
+		OPT_BIT_F(0, "numstat", &options->output_format,
+			  N_("machine friendly --stat"),
+			  DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "shortstat", &options->output_format,
+			  N_("output only the last line of --stat"),
+			  DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4931,11 +4937,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--numstat"))
-		options->output_format |= DIFF_FORMAT_NUMSTAT;
-	else if (!strcmp(arg, "--shortstat"))
-		options->output_format |= DIFF_FORMAT_SHORTSTAT;
-	else if (skip_prefix(arg, "-X", &arg) ||
+	if (skip_prefix(arg, "-X", &arg) ||
 		 skip_to_optional_arg(arg, "--dirstat", &arg))
 		return parse_dirstat_opt(options, arg);
 	else if (!strcmp(arg, "--cumulative"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 18/76] diff.c: convert --dirstat and friends
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (16 preceding siblings ...)
  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 ` 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
                   ` (58 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  7 ++++++
 diff.c                         | 39 +++++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 0711734b12..058d93ec4f 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,
 	number of modified files, as well as number of added and deleted
 	lines.
 
+-X<param1,param2,...>::
 --dirstat[=<param1,param2,...>]::
 	Output the distribution of relative amount of changes for each
 	sub-directory. The behavior of `--dirstat` can be customized by
@@ -192,6 +193,12 @@ directories with less than 10% of the total amount of changed files,
 and accumulating child directory counts in the parent directories:
 `--dirstat=files,10,cumulative`.
 
+--cumulative::
+	Synonym for --dirstat=cumulative
+
+--dirstat-by-file[=<param1,param2>...]::
+	Synonym for --dirstat=files,param1,param2...
+
 --summary::
 	Output a condensed summary of extended header information
 	such as creations, renames and mode changes.
diff --git a/diff.c b/diff.c
index 69a4d55e38..1cb410ed3a 100644
--- a/diff.c
+++ b/diff.c
@@ -4865,6 +4865,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_dirstat(const struct option *opt,
+			    const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!strcmp(opt->long_name, "cumulative")) {
+		if (arg)
+			BUG("how come --cumulative take a value?");
+		arg = "cumulative";
+	} else if (!strcmp(opt->long_name, "dirstat-by-file"))
+		parse_dirstat_opt(options, "files");
+	parse_dirstat_opt(options, arg ? arg : "");
+	return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -4909,6 +4925,18 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "shortstat", &options->output_format,
 			  N_("output only the last line of --stat"),
 			  DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
+		OPT_CALLBACK_F('X', "dirstat", options, N_("<param1,param2>..."),
+			       N_("output the distribution of relative amount of changes for each sub-directory"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_dirstat),
+		OPT_CALLBACK_F(0, "cumulative", options, NULL,
+			       N_("synonym for --dirstat=cumulative"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       diff_opt_dirstat),
+		OPT_CALLBACK_F(0, "dirstat-by-file", options, N_("<param1,param2>..."),
+			       N_("synonym for --dirstat=files,param1,param2..."),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_dirstat),
 		OPT_END()
 	};
 
@@ -4937,16 +4965,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (skip_prefix(arg, "-X", &arg) ||
-		 skip_to_optional_arg(arg, "--dirstat", &arg))
-		return parse_dirstat_opt(options, arg);
-	else if (!strcmp(arg, "--cumulative"))
-		return parse_dirstat_opt(options, "cumulative");
-	else if (skip_to_optional_arg(arg, "--dirstat-by-file", &arg)) {
-		parse_dirstat_opt(options, "files");
-		return parse_dirstat_opt(options, arg);
-	}
-	else if (!strcmp(arg, "--check"))
+	if (!strcmp(arg, "--check"))
 		options->output_format |= DIFF_FORMAT_CHECKDIFF;
 	else if (!strcmp(arg, "--summary"))
 		options->output_format |= DIFF_FORMAT_SUMMARY;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 19/76] diff.c: convert --check
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (17 preceding siblings ...)
  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 ` 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
                   ` (57 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 1cb410ed3a..07b495b686 100644
--- a/diff.c
+++ b/diff.c
@@ -4937,6 +4937,9 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("synonym for --dirstat=files,param1,param2..."),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_dirstat),
+		OPT_BIT_F(0, "check", &options->output_format,
+			  N_("warn if changes introduce conflict markers or whitespace errors"),
+			  DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4965,9 +4968,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--check"))
-		options->output_format |= DIFF_FORMAT_CHECKDIFF;
-	else if (!strcmp(arg, "--summary"))
+	if (!strcmp(arg, "--summary"))
 		options->output_format |= DIFF_FORMAT_SUMMARY;
 	else if (!strcmp(arg, "--patch-with-stat")) {
 		enable_patch_output(&options->output_format);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 20/76] diff.c: convert --summary
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (18 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 19/76] diff.c: convert --check Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (56 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 07b495b686..73fbe5b265 100644
--- a/diff.c
+++ b/diff.c
@@ -4940,6 +4940,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "check", &options->output_format,
 			  N_("warn if changes introduce conflict markers or whitespace errors"),
 			  DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "summary", &options->output_format,
+			  N_("condensed summary such as creations, renames and mode changes"),
+			  DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4968,9 +4971,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--summary"))
-		options->output_format |= DIFF_FORMAT_SUMMARY;
-	else if (!strcmp(arg, "--patch-with-stat")) {
+	if (!strcmp(arg, "--patch-with-stat")) {
 		enable_patch_output(&options->output_format);
 		options->output_format |= DIFF_FORMAT_DIFFSTAT;
 	} else if (!strcmp(arg, "--name-only"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 21/76] diff.c: convert --patch-with-stat
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (19 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 20/76] diff.c: convert --summary Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (55 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index 73fbe5b265..2ab3d68d9c 100644
--- a/diff.c
+++ b/diff.c
@@ -4919,6 +4919,10 @@ static void prep_parse_options(struct diff_options *options)
 			  N_("synonym for '-p --raw'"),
 			  DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,
 			  DIFF_FORMAT_NO_OUTPUT),
+		OPT_BITOP(0, "patch-with-stat", &options->output_format,
+			  N_("synonym for '-p --stat'"),
+			  DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT,
+			  DIFF_FORMAT_NO_OUTPUT),
 		OPT_BIT_F(0, "numstat", &options->output_format,
 			  N_("machine friendly --stat"),
 			  DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),
@@ -4971,10 +4975,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--patch-with-stat")) {
-		enable_patch_output(&options->output_format);
-		options->output_format |= DIFF_FORMAT_DIFFSTAT;
-	} else if (!strcmp(arg, "--name-only"))
+	if (!strcmp(arg, "--name-only"))
 		options->output_format |= DIFF_FORMAT_NAME;
 	else if (!strcmp(arg, "--name-status"))
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 22/76] diff.c: convert --name-only
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (20 preceding siblings ...)
  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 ` 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
                   ` (54 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 2ab3d68d9c..056b766264 100644
--- a/diff.c
+++ b/diff.c
@@ -4947,6 +4947,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "summary", &options->output_format,
 			  N_("condensed summary such as creations, renames and mode changes"),
 			  DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "name-only", &options->output_format,
+			  N_("show only names of changed files"),
+			  DIFF_FORMAT_NAME, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4975,9 +4978,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--name-only"))
-		options->output_format |= DIFF_FORMAT_NAME;
-	else if (!strcmp(arg, "--name-status"))
+	if (!strcmp(arg, "--name-status"))
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
 	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 23/76] diff.c: convert --name-status
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (21 preceding siblings ...)
  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 ` 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
                   ` (53 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 056b766264..e685356e3e 100644
--- a/diff.c
+++ b/diff.c
@@ -4950,6 +4950,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "name-only", &options->output_format,
 			  N_("show only names of changed files"),
 			  DIFF_FORMAT_NAME, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "name-status", &options->output_format,
+			  N_("show only names and status of changed files"),
+			  DIFF_FORMAT_NAME_STATUS, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 
@@ -4978,9 +4981,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--name-status"))
-		options->output_format |= DIFF_FORMAT_NAME_STATUS;
-	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
+	if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
 	else if (starts_with(arg, "--stat"))
 		/* --stat, --stat-width, --stat-name-width, or --stat-count */
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 24/76] diff.c: convert -s|--no-patch
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (22 preceding siblings ...)
  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 ` 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
                   ` (52 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index e685356e3e..4398b30f47 100644
--- a/diff.c
+++ b/diff.c
@@ -4904,6 +4904,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BITOP('p', "patch", &options->output_format,
 			  N_("generate patch"),
 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
+		OPT_BIT_F('s', "no-patch", &options->output_format,
+			  N_("suppress diff output"),
+			  DIFF_FORMAT_NO_OUTPUT, PARSE_OPT_NONEG),
 		OPT_BITOP('u', NULL, &options->output_format,
 			  N_("generate patch"),
 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
@@ -4981,9 +4984,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
-		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
-	else if (starts_with(arg, "--stat"))
+	if (starts_with(arg, "--stat"))
 		/* --stat, --stat-width, --stat-name-width, or --stat-count */
 		return stat_opt(options, av);
 	else if (!strcmp(arg, "--compact-summary")) {
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 25/76] diff.c: convert --stat*
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (23 preceding siblings ...)
  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 ` 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
                   ` (51 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 113 ++++++++++++++++++++++++++-------------------------------
 1 file changed, 52 insertions(+), 61 deletions(-)

diff --git a/diff.c b/diff.c
index 4398b30f47..1b01b36507 100644
--- a/diff.c
+++ b/diff.c
@@ -4660,77 +4660,56 @@ int parse_long_opt(const char *opt, const char **argv,
 	return 2;
 }
 
-static int stat_opt(struct diff_options *options, const char **av)
+static int diff_opt_stat(const struct option *opt, const char *value, int unset)
 {
-	const char *arg = av[0];
-	char *end;
+	struct diff_options *options = opt->value;
 	int width = options->stat_width;
 	int name_width = options->stat_name_width;
 	int graph_width = options->stat_graph_width;
 	int count = options->stat_count;
-	int argcount = 1;
+	char *end;
 
-	if (!skip_prefix(arg, "--stat", &arg))
-		BUG("stat option does not begin with --stat: %s", arg);
-	end = (char *)arg;
+	BUG_ON_OPT_NEG(unset);
 
-	switch (*arg) {
-	case '-':
-		if (skip_prefix(arg, "-width", &arg)) {
-			if (*arg == '=')
-				width = strtoul(arg + 1, &end, 10);
-			else if (!*arg && !av[1])
-				die_want_option("--stat-width");
-			else if (!*arg) {
-				width = strtoul(av[1], &end, 10);
-				argcount = 2;
-			}
-		} else if (skip_prefix(arg, "-name-width", &arg)) {
-			if (*arg == '=')
-				name_width = strtoul(arg + 1, &end, 10);
-			else if (!*arg && !av[1])
-				die_want_option("--stat-name-width");
-			else if (!*arg) {
-				name_width = strtoul(av[1], &end, 10);
-				argcount = 2;
-			}
-		} else if (skip_prefix(arg, "-graph-width", &arg)) {
-			if (*arg == '=')
-				graph_width = strtoul(arg + 1, &end, 10);
-			else if (!*arg && !av[1])
-				die_want_option("--stat-graph-width");
-			else if (!*arg) {
-				graph_width = strtoul(av[1], &end, 10);
-				argcount = 2;
-			}
-		} else if (skip_prefix(arg, "-count", &arg)) {
-			if (*arg == '=')
-				count = strtoul(arg + 1, &end, 10);
-			else if (!*arg && !av[1])
-				die_want_option("--stat-count");
-			else if (!*arg) {
-				count = strtoul(av[1], &end, 10);
-				argcount = 2;
-			}
+	if (!strcmp(opt->long_name, "stat")) {
+		if (value) {
+			width = strtoul(value, &end, 10);
+			if (*end == ',')
+				name_width = strtoul(end+1, &end, 10);
+			if (*end == ',')
+				count = strtoul(end+1, &end, 10);
+			if (*end)
+				return error(_("invalid --stat value: %s"), value);
 		}
-		break;
-	case '=':
-		width = strtoul(arg+1, &end, 10);
-		if (*end == ',')
-			name_width = strtoul(end+1, &end, 10);
-		if (*end == ',')
-			count = strtoul(end+1, &end, 10);
-	}
+	} else if (!strcmp(opt->long_name, "stat-width")) {
+		width = strtoul(value, &end, 10);
+		if (*end)
+			return error(_("%s expects a numerical value"),
+				     opt->long_name);
+	} else if (!strcmp(opt->long_name, "stat-name-width")) {
+		name_width = strtoul(value, &end, 10);
+		if (*end)
+			return error(_("%s expects a numerical value"),
+				     opt->long_name);
+	} else if (!strcmp(opt->long_name, "stat-graph-width")) {
+		graph_width = strtoul(value, &end, 10);
+		if (*end)
+			return error(_("%s expects a numerical value"),
+				     opt->long_name);
+	} else if (!strcmp(opt->long_name, "stat-count")) {
+		count = strtoul(value, &end, 10);
+		if (*end)
+			return error(_("%s expects a numerical value"),
+				     opt->long_name);
+	} else
+		BUG("%s should not get here", opt->long_name);
 
-	/* Important! This checks all the error cases! */
-	if (*end)
-		return 0;
 	options->output_format |= DIFF_FORMAT_DIFFSTAT;
 	options->stat_name_width = name_width;
 	options->stat_graph_width = graph_width;
 	options->stat_width = width;
 	options->stat_count = count;
-	return argcount;
+	return 0;
 }
 
 static int parse_dirstat_opt(struct diff_options *options, const char *params)
@@ -4956,6 +4935,21 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "name-status", &options->output_format,
 			  N_("show only names and status of changed files"),
 			  DIFF_FORMAT_NAME_STATUS, PARSE_OPT_NONEG),
+		OPT_CALLBACK_F(0, "stat", options, N_("<width>[,<name-width>[,<count>]]"),
+			       N_("generate diffstat"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_stat),
+		OPT_CALLBACK_F(0, "stat-width", options, N_("<width>"),
+			       N_("generate diffstat with a given width"),
+			       PARSE_OPT_NONEG, diff_opt_stat),
+		OPT_CALLBACK_F(0, "stat-name-width", options, N_("<width>"),
+			       N_("generate diffstat with a given name width"),
+			       PARSE_OPT_NONEG, diff_opt_stat),
+		OPT_CALLBACK_F(0, "stat-graph-width", options, N_("<width>"),
+			       N_("generate diffstat with a given graph width"),
+			       PARSE_OPT_NONEG, diff_opt_stat),
+		OPT_CALLBACK_F(0, "stat-count", options, N_("<count>"),
+			       N_("generate diffstat with limited lines"),
+			       PARSE_OPT_NONEG, diff_opt_stat),
 		OPT_END()
 	};
 
@@ -4984,10 +4978,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (starts_with(arg, "--stat"))
-		/* --stat, --stat-width, --stat-name-width, or --stat-count */
-		return stat_opt(options, av);
-	else if (!strcmp(arg, "--compact-summary")) {
+	if (!strcmp(arg, "--compact-summary")) {
 		 options->flags.stat_with_summary = 1;
 		 options->output_format |= DIFF_FORMAT_DIFFSTAT;
 	} else if (!strcmp(arg, "--no-compact-summary"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 26/76] diff.c: convert --[no-]compact-summary
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (24 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 25/76] diff.c: convert --stat* Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (50 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 1b01b36507..48659a10c0 100644
--- a/diff.c
+++ b/diff.c
@@ -4844,6 +4844,21 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_compact_summary(const struct option *opt,
+				    const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_ARG(arg);
+	if (unset) {
+		options->flags.stat_with_summary = 0;
+	} else {
+		options->flags.stat_with_summary = 1;
+		options->output_format |= DIFF_FORMAT_DIFFSTAT;
+	}
+	return 0;
+}
+
 static int diff_opt_dirstat(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -4950,6 +4965,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "stat-count", options, N_("<count>"),
 			       N_("generate diffstat with limited lines"),
 			       PARSE_OPT_NONEG, diff_opt_stat),
+		OPT_CALLBACK_F(0, "compact-summary", options, NULL,
+			       N_("generate compact summary in diffstat"),
+			       PARSE_OPT_NOARG, diff_opt_compact_summary),
 		OPT_END()
 	};
 
@@ -4978,12 +4996,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (!strcmp(arg, "--compact-summary")) {
-		 options->flags.stat_with_summary = 1;
-		 options->output_format |= DIFF_FORMAT_DIFFSTAT;
-	} else if (!strcmp(arg, "--no-compact-summary"))
-		 options->flags.stat_with_summary = 0;
-	else if (skip_prefix(arg, "--output-indicator-new=", &arg))
+	if (skip_prefix(arg, "--output-indicator-new=", &arg))
 		options->output_indicators[OUTPUT_INDICATOR_NEW] = arg[0];
 	else if (skip_prefix(arg, "--output-indicator-old=", &arg))
 		options->output_indicators[OUTPUT_INDICATOR_OLD] = arg[0];
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 27/76] diff.c: convert --output-*
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (25 preceding siblings ...)
  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 ` 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
                   ` (49 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This also validates that the user specifies a single character in
--output-indicator-*, not a string.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt | 10 +++++
 diff.c                         | 71 +++++++++++++++++++++++++---------
 2 files changed, 63 insertions(+), 18 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 058d93ec4f..d3e8d634b2 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -41,6 +41,16 @@ ifndef::git-format-patch[]
 	Implies `-p`.
 endif::git-format-patch[]
 
+--output=<file>::
+	Output to a specific file instead of stdout.
+
+--output-indicator-new=<char>::
+--output-indicator-old=<char>::
+--output-indicator-context=<char>::
+	Specify the character used to indicate new, old or context
+	lines in the generated patch. Normally they are '+', '-' and
+	' ' respectively.
+
 ifndef::git-format-patch[]
 --raw::
 ifndef::git-log[]
diff --git a/diff.c b/diff.c
index 48659a10c0..c70de7f358 100644
--- a/diff.c
+++ b/diff.c
@@ -4844,6 +4844,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_char(const struct option *opt,
+			 const char *arg, int unset)
+{
+	char *value = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (arg[1])
+		return error(_("%s expects a character, got '%s'"),
+			     opt->long_name, arg);
+	*value = arg[0];
+	return 0;
+}
+
 static int diff_opt_compact_summary(const struct option *opt,
 				    const char *arg, int unset)
 {
@@ -4875,6 +4888,23 @@ static int diff_opt_dirstat(const struct option *opt,
 	return 0;
 }
 
+static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
+					     const struct option *opt,
+					     const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+	char *path;
+
+	BUG_ON_OPT_NEG(unset);
+	path = prefix_filename(ctx->prefix, arg);
+	options->file = xfopen(path, "w");
+	options->close_file = 1;
+	if (options->use_color != GIT_COLOR_ALWAYS)
+		options->use_color = GIT_COLOR_NEVER;
+	free(path);
+	return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -4968,6 +4998,27 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "compact-summary", options, NULL,
 			       N_("generate compact summary in diffstat"),
 			       PARSE_OPT_NOARG, diff_opt_compact_summary),
+		OPT_CALLBACK_F(0, "output-indicator-new",
+			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
+			       N_("<char>"),
+			       N_("specify the character to indicate a new line instead of '+'"),
+			       PARSE_OPT_NONEG, diff_opt_char),
+		OPT_CALLBACK_F(0, "output-indicator-old",
+			       &options->output_indicators[OUTPUT_INDICATOR_OLD],
+			       N_("<char>"),
+			       N_("specify the character to indicate an old line instead of '-'"),
+			       PARSE_OPT_NONEG, diff_opt_char),
+		OPT_CALLBACK_F(0, "output-indicator-context",
+			       &options->output_indicators[OUTPUT_INDICATOR_CONTEXT],
+			       N_("<char>"),
+			       N_("specify the character to indicate a context instead of ' '"),
+			       PARSE_OPT_NONEG, diff_opt_char),
+
+		OPT_GROUP(N_("Diff other options")),
+		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
+		  N_("Output to a specific file"),
+		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
+
 		OPT_END()
 	};
 
@@ -4995,16 +5046,8 @@ int diff_opt_parse(struct diff_options *options,
 	if (ac)
 		return ac;
 
-	/* Output format options */
-	if (skip_prefix(arg, "--output-indicator-new=", &arg))
-		options->output_indicators[OUTPUT_INDICATOR_NEW] = arg[0];
-	else if (skip_prefix(arg, "--output-indicator-old=", &arg))
-		options->output_indicators[OUTPUT_INDICATOR_OLD] = arg[0];
-	else if (skip_prefix(arg, "--output-indicator-context=", &arg))
-		options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = arg[0];
-
 	/* renames options */
-	else if (starts_with(arg, "-B") ||
+	if (starts_with(arg, "-B") ||
 		 skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
 		if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
 			return error("invalid argument to -B: %s", arg+2);
@@ -5245,15 +5288,7 @@ int diff_opt_parse(struct diff_options *options,
 	else if (opt_arg(arg, '\0', "inter-hunk-context",
 			 &options->interhunkcontext))
 		;
-	else if ((argcount = parse_long_opt("output", av, &optarg))) {
-		char *path = prefix_filename(prefix, optarg);
-		options->file = xfopen(path, "w");
-		options->close_file = 1;
-		if (options->use_color != GIT_COLOR_ALWAYS)
-			options->use_color = GIT_COLOR_NEVER;
-		free(path);
-		return argcount;
-	} else
+	else
 		return 0;
 	return 1;
 }
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 28/76] diff.c: convert -B|--break-rewrites
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (26 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 27/76] diff.c: convert --output-* Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (48 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index c70de7f358..d4c378e836 100644
--- a/diff.c
+++ b/diff.c
@@ -4844,6 +4844,31 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_break_rewrites(const struct option *opt,
+				   const char *arg, int unset)
+{
+	int *break_opt = opt->value;
+	int opt1, opt2;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg)
+		arg = "";
+	opt1 = parse_rename_score(&arg);
+	switch (*arg) {
+	case '\0':
+		opt2 = 0;
+		break;
+	case '/':
+		arg++;
+		opt2 = parse_rename_score(&arg);
+		break;
+	}
+	if (*arg != 0)
+		return error(_("%s expects <n>/<m> form"), opt->long_name);
+	*break_opt = opt1 | (opt2 << 16);
+	return 0;
+}
+
 static int diff_opt_char(const struct option *opt,
 			 const char *arg, int unset)
 {
@@ -5014,6 +5039,12 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("specify the character to indicate a context instead of ' '"),
 			       PARSE_OPT_NONEG, diff_opt_char),
 
+		OPT_GROUP(N_("Diff rename options")),
+		OPT_CALLBACK_F('B', "break-rewrites", &options->break_opt, N_("<n>[/<m>]"),
+			       N_("break complete rewrite changes into pairs of delete and create"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_break_rewrites),
+
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
@@ -5047,12 +5078,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* renames options */
-	if (starts_with(arg, "-B") ||
-		 skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
-		if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
-			return error("invalid argument to -B: %s", arg+2);
-	}
-	else if (starts_with(arg, "-M") ||
+	if (starts_with(arg, "-M") ||
 		 skip_to_optional_arg(arg, "--find-renames", NULL)) {
 		if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
 			return error("invalid argument to -M: %s", arg+2);
@@ -5331,17 +5357,14 @@ int parse_rename_score(const char **cp_p)
 
 static int diff_scoreopt_parse(const char *opt)
 {
-	int opt1, opt2, cmd;
+	int opt1, cmd;
 
 	if (*opt++ != '-')
 		return -1;
 	cmd = *opt++;
 	if (cmd == '-') {
 		/* convert the long-form arguments into short-form versions */
-		if (skip_prefix(opt, "break-rewrites", &opt)) {
-			if (*opt == 0 || *opt++ == '=')
-				cmd = 'B';
-		} else if (skip_prefix(opt, "find-copies", &opt)) {
+		if (skip_prefix(opt, "find-copies", &opt)) {
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'C';
 		} else if (skip_prefix(opt, "find-renames", &opt)) {
@@ -5349,25 +5372,13 @@ static int diff_scoreopt_parse(const char *opt)
 				cmd = 'M';
 		}
 	}
-	if (cmd != 'M' && cmd != 'C' && cmd != 'B')
-		return -1; /* that is not a -M, -C, or -B option */
+	if (cmd != 'M' && cmd != 'C')
+		return -1; /* that is not a -M, or -C option */
 
 	opt1 = parse_rename_score(&opt);
-	if (cmd != 'B')
-		opt2 = 0;
-	else {
-		if (*opt == 0)
-			opt2 = 0;
-		else if (*opt != '/')
-			return -1; /* we expect -B80/99 or -B80 */
-		else {
-			opt++;
-			opt2 = parse_rename_score(&opt);
-		}
-	}
 	if (*opt != 0)
 		return -1;
-	return opt1 | (opt2 << 16);
+	return opt1;
 }
 
 struct diff_queue_struct diff_queued_diff;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 29/76] diff.c: convert -M|--find-renames
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (27 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 28/76] diff.c: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (47 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/diff.c b/diff.c
index d4c378e836..6397d7a606 100644
--- a/diff.c
+++ b/diff.c
@@ -4913,6 +4913,22 @@ static int diff_opt_dirstat(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_find_renames(const struct option *opt,
+				 const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg)
+		arg = "";
+	options->rename_score = parse_rename_score(&arg);
+	if (*arg != 0)
+		return error(_("invalid argument to %s"), opt->long_name);
+
+	options->detect_rename = DIFF_DETECT_RENAME;
+	return 0;
+}
+
 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 					     const struct option *opt,
 					     const char *arg, int unset)
@@ -5044,6 +5060,10 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("break complete rewrite changes into pairs of delete and create"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_break_rewrites),
+		OPT_CALLBACK_F('M', "find-renames", options, N_("<n>"),
+			       N_("detect renames"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_find_renames),
 
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5078,13 +5098,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* renames options */
-	if (starts_with(arg, "-M") ||
-		 skip_to_optional_arg(arg, "--find-renames", NULL)) {
-		if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
-			return error("invalid argument to -M: %s", arg+2);
-		options->detect_rename = DIFF_DETECT_RENAME;
-	}
-	else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
+	if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
 		options->irreversible_delete = 1;
 	}
 	else if (starts_with(arg, "-C") ||
@@ -5367,13 +5381,10 @@ static int diff_scoreopt_parse(const char *opt)
 		if (skip_prefix(opt, "find-copies", &opt)) {
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'C';
-		} else if (skip_prefix(opt, "find-renames", &opt)) {
-			if (*opt == 0 || *opt++ == '=')
-				cmd = 'M';
 		}
 	}
-	if (cmd != 'M' && cmd != 'C')
-		return -1; /* that is not a -M, or -C option */
+	if (cmd != 'C')
+		return -1; /* that is not a -M option */
 
 	opt1 = parse_rename_score(&opt);
 	if (*opt != 0)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 30/76] diff.c: convert -D|--irreversible-delete
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (28 preceding siblings ...)
  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 ` 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
                   ` (46 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 6397d7a606..e12b7ae101 100644
--- a/diff.c
+++ b/diff.c
@@ -5064,6 +5064,9 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("detect renames"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_find_renames),
+		OPT_SET_INT_F('D', "irreversible-delete", &options->irreversible_delete,
+			      N_("omit the preimage for deletes"),
+			      1, PARSE_OPT_NONEG),
 
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5098,10 +5101,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* renames options */
-	if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
-		options->irreversible_delete = 1;
-	}
-	else if (starts_with(arg, "-C") ||
+	if (starts_with(arg, "-C") ||
 		 skip_to_optional_arg(arg, "--find-copies", NULL)) {
 		if (options->detect_rename == DIFF_DETECT_COPY)
 			options->flags.find_copies_harder = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 31/76] diff.c: convert -C|--find-copies
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (29 preceding siblings ...)
  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 ` 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
                   ` (45 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 59 +++++++++++++++++++++++++---------------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)

diff --git a/diff.c b/diff.c
index e12b7ae101..3b05e03284 100644
--- a/diff.c
+++ b/diff.c
@@ -4621,8 +4621,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
 	return 1;
 }
 
-static int diff_scoreopt_parse(const char *opt);
-
 static inline int short_opt(char opt, const char **argv,
 			    const char **optarg)
 {
@@ -4913,6 +4911,26 @@ static int diff_opt_dirstat(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_find_copies(const struct option *opt,
+				const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg)
+		arg = "";
+	options->rename_score = parse_rename_score(&arg);
+	if (*arg != 0)
+		return error(_("invalid argument to %s"), opt->long_name);
+
+	if (options->detect_rename == DIFF_DETECT_COPY)
+		options->flags.find_copies_harder = 1;
+	else
+		options->detect_rename = DIFF_DETECT_COPY;
+
+	return 0;
+}
+
 static int diff_opt_find_renames(const struct option *opt,
 				 const char *arg, int unset)
 {
@@ -5067,6 +5085,10 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_SET_INT_F('D', "irreversible-delete", &options->irreversible_delete,
 			      N_("omit the preimage for deletes"),
 			      1, PARSE_OPT_NONEG),
+		OPT_CALLBACK_F('C', "find-copies", options, N_("<n>"),
+			       N_("detect copies"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_find_copies),
 
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5101,15 +5123,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* renames options */
-	if (starts_with(arg, "-C") ||
-		 skip_to_optional_arg(arg, "--find-copies", NULL)) {
-		if (options->detect_rename == DIFF_DETECT_COPY)
-			options->flags.find_copies_harder = 1;
-		if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
-			return error("invalid argument to -C: %s", arg+2);
-		options->detect_rename = DIFF_DETECT_COPY;
-	}
-	else if (!strcmp(arg, "--no-renames"))
+	if (!strcmp(arg, "--no-renames"))
 		options->detect_rename = 0;
 	else if (!strcmp(arg, "--rename-empty"))
 		options->flags.rename_empty = 1;
@@ -5369,29 +5383,6 @@ int parse_rename_score(const char **cp_p)
 	return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));
 }
 
-static int diff_scoreopt_parse(const char *opt)
-{
-	int opt1, cmd;
-
-	if (*opt++ != '-')
-		return -1;
-	cmd = *opt++;
-	if (cmd == '-') {
-		/* convert the long-form arguments into short-form versions */
-		if (skip_prefix(opt, "find-copies", &opt)) {
-			if (*opt == 0 || *opt++ == '=')
-				cmd = 'C';
-		}
-	}
-	if (cmd != 'C')
-		return -1; /* that is not a -M option */
-
-	opt1 = parse_rename_score(&opt);
-	if (*opt != 0)
-		return -1;
-	return opt1;
-}
-
 struct diff_queue_struct diff_queued_diff;
 
 void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 32/76] diff.c: convert --find-copies-harder
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (30 preceding siblings ...)
  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 ` 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
                   ` (44 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

--no-find-copies-harder is also added on purpose (because I don't see
why we should not have the --no- version for this)

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

diff --git a/diff.c b/diff.c
index 3b05e03284..0756612eb0 100644
--- a/diff.c
+++ b/diff.c
@@ -5089,6 +5089,8 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("detect copies"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_find_copies),
+		OPT_BOOL(0, "find-copies-harder", &options->flags.find_copies_harder,
+			 N_("use unmodified files as source to find copies")),
 
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5195,8 +5197,6 @@ int diff_opt_parse(struct diff_options *options,
 		options->flags.text = 1;
 	else if (!strcmp(arg, "-R"))
 		options->flags.reverse_diff = 1;
-	else if (!strcmp(arg, "--find-copies-harder"))
-		options->flags.find_copies_harder = 1;
 	else if (!strcmp(arg, "--follow"))
 		options->flags.follow_renames = 1;
 	else if (!strcmp(arg, "--no-follow")) {
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 33/76] diff.c: convert --no-renames|--[no--rename-empty
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (31 preceding siblings ...)
  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 ` 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
                   ` (43 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

For --rename-empty, see 90d43b0768 (teach diffcore-rename to
optionally ignore empty content - 2012-03-22) for more information.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  3 +++
 diff.c                         | 13 ++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index d3e8d634b2..4c0d40881b 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -392,6 +392,9 @@ endif::git-format-patch[]
 	Turn off rename detection, even when the configuration
 	file gives the default to do so.
 
+--[no-]rename-empty::
+	Whether to use empty blobs as rename source.
+
 ifndef::git-format-patch[]
 --check::
 	Warn if changes introduce conflict markers or whitespace errors.
diff --git a/diff.c b/diff.c
index 0756612eb0..fa666ced61 100644
--- a/diff.c
+++ b/diff.c
@@ -5091,6 +5091,11 @@ static void prep_parse_options(struct diff_options *options)
 			       diff_opt_find_copies),
 		OPT_BOOL(0, "find-copies-harder", &options->flags.find_copies_harder,
 			 N_("use unmodified files as source to find copies")),
+		OPT_SET_INT_F(0, "no-renames", &options->detect_rename,
+			      N_("disable rename detection"),
+			      0, PARSE_OPT_NONEG),
+		OPT_BOOL(0, "rename-empty", &options->flags.rename_empty,
+			 N_("use empty blobs as rename source")),
 
 		OPT_GROUP(N_("Diff other options")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5125,13 +5130,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* renames options */
-	if (!strcmp(arg, "--no-renames"))
-		options->detect_rename = 0;
-	else if (!strcmp(arg, "--rename-empty"))
-		options->flags.rename_empty = 1;
-	else if (!strcmp(arg, "--no-rename-empty"))
-		options->flags.rename_empty = 0;
-	else if (skip_to_optional_arg_default(arg, "--relative", &arg, NULL)) {
+	if (skip_to_optional_arg_default(arg, "--relative", &arg, NULL)) {
 		options->flags.relative_name = 1;
 		if (arg)
 			options->prefix = arg;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 34/76] diff.c: convert --relative
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (32 preceding siblings ...)
  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 ` 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
                   ` (42 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/diff.c b/diff.c
index fa666ced61..66a9f2ef48 100644
--- a/diff.c
+++ b/diff.c
@@ -4964,6 +4964,18 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
+static int diff_opt_relative(const struct option *opt,
+			     const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->flags.relative_name = 1;
+	if (arg)
+		options->prefix = arg;
+	return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -5098,6 +5110,10 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("use empty blobs as rename source")),
 
 		OPT_GROUP(N_("Diff other options")),
+		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
+			       N_("when run from subdir, exclude changes outside and show relative paths"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_relative),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5129,15 +5145,8 @@ int diff_opt_parse(struct diff_options *options,
 	if (ac)
 		return ac;
 
-	/* renames options */
-	if (skip_to_optional_arg_default(arg, "--relative", &arg, NULL)) {
-		options->flags.relative_name = 1;
-		if (arg)
-			options->prefix = arg;
-	}
-
 	/* xdiff options */
-	else if (!strcmp(arg, "--minimal"))
+	if (!strcmp(arg, "--minimal"))
 		DIFF_XDL_SET(options, NEED_MINIMAL);
 	else if (!strcmp(arg, "--no-minimal"))
 		DIFF_XDL_CLR(options, NEED_MINIMAL);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 35/76] diff.c: convert --[no-]minimal
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (33 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 34/76] diff.c: convert --relative Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (41 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 66a9f2ef48..67b701d522 100644
--- a/diff.c
+++ b/diff.c
@@ -5109,6 +5109,11 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BOOL(0, "rename-empty", &options->flags.rename_empty,
 			 N_("use empty blobs as rename source")),
 
+		OPT_GROUP(N_("Diff algorithm options")),
+		OPT_BIT(0, "minimal", &options->xdl_opts,
+			N_("produce the smallest possible diff"),
+			XDF_NEED_MINIMAL),
+
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
 			       N_("when run from subdir, exclude changes outside and show relative paths"),
@@ -5146,11 +5151,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if (!strcmp(arg, "--minimal"))
-		DIFF_XDL_SET(options, NEED_MINIMAL);
-	else if (!strcmp(arg, "--no-minimal"))
-		DIFF_XDL_CLR(options, NEED_MINIMAL);
-	else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
+	if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE);
 	else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 36/76] diff.c: convert --ignore-some-changes
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (34 preceding siblings ...)
  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 ` 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
                   ` (40 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/diff.c b/diff.c
index 67b701d522..d8b5c7b7d8 100644
--- a/diff.c
+++ b/diff.c
@@ -5113,6 +5113,21 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT(0, "minimal", &options->xdl_opts,
 			N_("produce the smallest possible diff"),
 			XDF_NEED_MINIMAL),
+		OPT_BIT_F('w', "ignore-all-space", &options->xdl_opts,
+			  N_("ignore whitespace when comparing lines"),
+			  XDF_IGNORE_WHITESPACE, PARSE_OPT_NONEG),
+		OPT_BIT_F('b', "ignore-space-change", &options->xdl_opts,
+			  N_("ignore changes in amount of whitespace"),
+			  XDF_IGNORE_WHITESPACE_CHANGE, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "ignore-space-at-eol", &options->xdl_opts,
+			  N_("ignore changes in whitespace at EOL"),
+			  XDF_IGNORE_WHITESPACE_AT_EOL, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "ignore-cr-at-eol", &options->xdl_opts,
+			  N_("ignore carrier-return at the end of line"),
+			  XDF_IGNORE_CR_AT_EOL, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "ignore-blank-lines", &options->xdl_opts,
+			  N_("ignore changes whose lines are all blank"),
+			  XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5151,17 +5166,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
-		DIFF_XDL_SET(options, IGNORE_WHITESPACE);
-	else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
-		DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
-	else if (!strcmp(arg, "--ignore-space-at-eol"))
-		DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
-	else if (!strcmp(arg, "--ignore-cr-at-eol"))
-		DIFF_XDL_SET(options, IGNORE_CR_AT_EOL);
-	else if (!strcmp(arg, "--ignore-blank-lines"))
-		DIFF_XDL_SET(options, IGNORE_BLANK_LINES);
-	else if (!strcmp(arg, "--indent-heuristic"))
+	if (!strcmp(arg, "--indent-heuristic"))
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 	else if (!strcmp(arg, "--no-indent-heuristic"))
 		DIFF_XDL_CLR(options, INDENT_HEURISTIC);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 37/76] diff.c: convert --[no-]indent-heuristic
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (35 preceding siblings ...)
  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 ` 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
                   ` (39 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index d8b5c7b7d8..166ac8b6e5 100644
--- a/diff.c
+++ b/diff.c
@@ -5128,6 +5128,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "ignore-blank-lines", &options->xdl_opts,
 			  N_("ignore changes whose lines are all blank"),
 			  XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG),
+		OPT_BIT(0, "indent-heuristic", &options->xdl_opts,
+			N_("heuristic to shift diff hunk boundaries for easy reading"),
+			XDF_INDENT_HEURISTIC),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5166,11 +5169,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if (!strcmp(arg, "--indent-heuristic"))
-		DIFF_XDL_SET(options, INDENT_HEURISTIC);
-	else if (!strcmp(arg, "--no-indent-heuristic"))
-		DIFF_XDL_CLR(options, INDENT_HEURISTIC);
-	else if (!strcmp(arg, "--patience")) {
+	if (!strcmp(arg, "--patience")) {
 		int i;
 		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
 		/*
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 38/76] diff.c: convert --patience
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (36 preceding siblings ...)
  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 ` 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
                   ` (38 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/diff.c b/diff.c
index 166ac8b6e5..67a88dcbd1 100644
--- a/diff.c
+++ b/diff.c
@@ -4964,6 +4964,26 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 	return 0;
 }
 
+static int diff_opt_patience(const struct option *opt,
+			     const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+	int i;
+
+	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
+	options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
+	/*
+	 * Both --patience and --anchored use PATIENCE_DIFF
+	 * internally, so remove any anchors previously
+	 * specified.
+	 */
+	for (i = 0; i < options->anchors_nr; i++)
+		free(options->anchors[i]);
+	options->anchors_nr = 0;
+	return 0;
+}
+
 static int diff_opt_relative(const struct option *opt,
 			     const char *arg, int unset)
 {
@@ -5131,6 +5151,10 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT(0, "indent-heuristic", &options->xdl_opts,
 			N_("heuristic to shift diff hunk boundaries for easy reading"),
 			XDF_INDENT_HEURISTIC),
+		OPT_CALLBACK_F(0, "patience", options, NULL,
+			       N_("generate diff using the \"patience diff\" algorithm"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       diff_opt_patience),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5169,18 +5193,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if (!strcmp(arg, "--patience")) {
-		int i;
-		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
-		/*
-		 * Both --patience and --anchored use PATIENCE_DIFF
-		 * internally, so remove any anchors previously
-		 * specified.
-		 */
-		for (i = 0; i < options->anchors_nr; i++)
-			free(options->anchors[i]);
-		options->anchors_nr = 0;
-	} else if (!strcmp(arg, "--histogram"))
+	if (!strcmp(arg, "--histogram"))
 		options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
 	else if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
 		long value = parse_algorithm_value(optarg);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 39/76] diff.c: convert --histogram
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (37 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 38/76] diff.c: convert --patience Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (37 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 67a88dcbd1..ca3f448a8d 100644
--- a/diff.c
+++ b/diff.c
@@ -5155,6 +5155,9 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("generate diff using the \"patience diff\" algorithm"),
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
 			       diff_opt_patience),
+		OPT_BITOP(0, "histogram", &options->xdl_opts,
+			  N_("generate diff using the \"histogram diff\" algorithm"),
+			  XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5193,9 +5196,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if (!strcmp(arg, "--histogram"))
-		options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
-	else if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
+	if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
 		long value = parse_algorithm_value(optarg);
 		if (value < 0)
 			return error("option diff-algorithm accepts \"myers\", "
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 40/76] diff.c: convert --diff-algorithm
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (38 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 39/76] diff.c: convert --histogram Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (36 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/diff.c b/diff.c
index ca3f448a8d..2b93f08958 100644
--- a/diff.c
+++ b/diff.c
@@ -4895,6 +4895,24 @@ static int diff_opt_compact_summary(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_diff_algorithm(const struct option *opt,
+				   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+	long value = parse_algorithm_value(arg);
+
+	BUG_ON_OPT_NEG(unset);
+	if (value < 0)
+		return error(_("option diff-algorithm accepts \"myers\", "
+			       "\"minimal\", \"patience\" and \"histogram\""));
+
+	/* clear out previous settings */
+	DIFF_XDL_CLR(options, NEED_MINIMAL);
+	options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
+	options->xdl_opts |= value;
+	return 0;
+}
+
 static int diff_opt_dirstat(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -5158,6 +5176,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BITOP(0, "histogram", &options->xdl_opts,
 			  N_("generate diff using the \"histogram diff\" algorithm"),
 			  XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),
+		OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
+			       N_("choose a diff algorithm"),
+			       PARSE_OPT_NONEG, diff_opt_diff_algorithm),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5196,17 +5217,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* xdiff options */
-	if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
-		long value = parse_algorithm_value(optarg);
-		if (value < 0)
-			return error("option diff-algorithm accepts \"myers\", "
-				     "\"minimal\", \"patience\" and \"histogram\"");
-		/* clear out previous settings */
-		DIFF_XDL_CLR(options, NEED_MINIMAL);
-		options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
-		options->xdl_opts |= value;
-		return argcount;
-	} else if (skip_prefix(arg, "--anchored=", &arg)) {
+	if (skip_prefix(arg, "--anchored=", &arg)) {
 		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
 		ALLOC_GROW(options->anchors, options->anchors_nr + 1,
 			   options->anchors_alloc);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 41/76] diff.c: convert --anchored
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (39 preceding siblings ...)
  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 ` 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
                   ` (35 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 2b93f08958..bee36fb276 100644
--- a/diff.c
+++ b/diff.c
@@ -4842,6 +4842,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_anchored(const struct option *opt,
+			     const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
+	ALLOC_GROW(options->anchors, options->anchors_nr + 1,
+		   options->anchors_alloc);
+	options->anchors[options->anchors_nr++] = xstrdup(arg);
+	return 0;
+}
+
 static int diff_opt_break_rewrites(const struct option *opt,
 				   const char *arg, int unset)
 {
@@ -5179,6 +5192,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
 			       N_("choose a diff algorithm"),
 			       PARSE_OPT_NONEG, diff_opt_diff_algorithm),
+		OPT_CALLBACK_F(0, "anchored", options, N_("<text>"),
+			       N_("generate diff using the \"anchored diff\" algorithm"),
+			       PARSE_OPT_NONEG, diff_opt_anchored),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5216,16 +5232,8 @@ int diff_opt_parse(struct diff_options *options,
 	if (ac)
 		return ac;
 
-	/* xdiff options */
-	if (skip_prefix(arg, "--anchored=", &arg)) {
-		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
-		ALLOC_GROW(options->anchors, options->anchors_nr + 1,
-			   options->anchors_alloc);
-		options->anchors[options->anchors_nr++] = xstrdup(arg);
-	}
-
 	/* flags options */
-	else if (!strcmp(arg, "--binary")) {
+	if (!strcmp(arg, "--binary")) {
 		enable_patch_output(&options->output_format);
 		options->flags.binary = 1;
 	}
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 42/76] diff.c: convert --binary
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (40 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 41/76] diff.c: convert --anchored Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (34 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  2 +-
 diff.c                         | 21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 4c0d40881b..08edbff503 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -425,7 +425,7 @@ endif::git-format-patch[]
 
 --binary::
 	In addition to `--full-index`, output a binary diff that
-	can be applied with `git-apply`.
+	can be applied with `git-apply`. Implies `--patch`.
 
 --abbrev[=<n>]::
 	Instead of showing the full 40-byte hexadecimal object
diff --git a/diff.c b/diff.c
index bee36fb276..0e93025af4 100644
--- a/diff.c
+++ b/diff.c
@@ -4855,6 +4855,18 @@ static int diff_opt_anchored(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_binary(const struct option *opt,
+			   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
+	enable_patch_output(&options->output_format);
+	options->flags.binary = 1;
+	return 0;
+}
+
 static int diff_opt_break_rewrites(const struct option *opt,
 				   const char *arg, int unset)
 {
@@ -5120,6 +5132,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "compact-summary", options, NULL,
 			       N_("generate compact summary in diffstat"),
 			       PARSE_OPT_NOARG, diff_opt_compact_summary),
+		OPT_CALLBACK_F(0, "binary", options, NULL,
+			       N_("output a binary diff that can be applied"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5233,11 +5248,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--binary")) {
-		enable_patch_output(&options->output_format);
-		options->flags.binary = 1;
-	}
-	else if (!strcmp(arg, "--full-index"))
+	if (!strcmp(arg, "--full-index"))
 		options->flags.full_index = 1;
 	else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
 		options->flags.text = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 43/76] diff.c: convert --full-index
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (41 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 42/76] diff.c: convert --binary Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (33 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 0e93025af4..0b70def840 100644
--- a/diff.c
+++ b/diff.c
@@ -5135,6 +5135,8 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "binary", options, NULL,
 			       N_("output a binary diff that can be applied"),
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
+		OPT_BOOL(0, "full-index", &options->flags.full_index,
+			 N_("show full pre- and post-image object names on the \"index\" lines")),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5248,9 +5250,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--full-index"))
-		options->flags.full_index = 1;
-	else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
+	if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
 		options->flags.text = 1;
 	else if (!strcmp(arg, "-R"))
 		options->flags.reverse_diff = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 44/76] diff.c: convert -a|--text
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (42 preceding siblings ...)
  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 ` 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
                   ` (32 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 0b70def840..d342d06399 100644
--- a/diff.c
+++ b/diff.c
@@ -5218,6 +5218,8 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("when run from subdir, exclude changes outside and show relative paths"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_relative),
+		OPT_BOOL('a', "text", &options->flags.text,
+			 N_("treat all files as text")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5250,9 +5252,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
-		options->flags.text = 1;
-	else if (!strcmp(arg, "-R"))
+	if (!strcmp(arg, "-R"))
 		options->flags.reverse_diff = 1;
 	else if (!strcmp(arg, "--follow"))
 		options->flags.follow_renames = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 45/76] diff.c: convert -R
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (43 preceding siblings ...)
  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 ` 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
                   ` (31 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index d342d06399..13de6ea35c 100644
--- a/diff.c
+++ b/diff.c
@@ -5220,6 +5220,8 @@ static void prep_parse_options(struct diff_options *options)
 			       diff_opt_relative),
 		OPT_BOOL('a', "text", &options->flags.text,
 			 N_("treat all files as text")),
+		OPT_BOOL('R', NULL, &options->flags.reverse_diff,
+			 N_("swap two inputs, reverse the diff")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5252,9 +5254,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "-R"))
-		options->flags.reverse_diff = 1;
-	else if (!strcmp(arg, "--follow"))
+	if (!strcmp(arg, "--follow"))
 		options->flags.follow_renames = 1;
 	else if (!strcmp(arg, "--no-follow")) {
 		options->flags.follow_renames = 0;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 46/76] diff.c: convert --[no-]follow
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (44 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 45/76] diff.c: convert -R Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (30 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 13de6ea35c..13d9e5eb05 100644
--- a/diff.c
+++ b/diff.c
@@ -4990,6 +4990,21 @@ static int diff_opt_find_renames(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_follow(const struct option *opt,
+			   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_ARG(arg);
+	if (unset) {
+		options->flags.follow_renames = 0;
+		options->flags.default_follow_renames = 0;
+	} else {
+		options->flags.follow_renames = 1;
+	}
+	return 0;
+}
+
 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 					     const struct option *opt,
 					     const char *arg, int unset)
@@ -5176,6 +5191,9 @@ static void prep_parse_options(struct diff_options *options)
 			      0, PARSE_OPT_NONEG),
 		OPT_BOOL(0, "rename-empty", &options->flags.rename_empty,
 			 N_("use empty blobs as rename source")),
+		OPT_CALLBACK_F(0, "follow", options, NULL,
+			       N_("continue listing the history of a file beyond renames"),
+			       PARSE_OPT_NOARG, diff_opt_follow),
 
 		OPT_GROUP(N_("Diff algorithm options")),
 		OPT_BIT(0, "minimal", &options->xdl_opts,
@@ -5254,12 +5272,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--follow"))
-		options->flags.follow_renames = 1;
-	else if (!strcmp(arg, "--no-follow")) {
-		options->flags.follow_renames = 0;
-		options->flags.default_follow_renames = 0;
-	} else if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
+	if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
 		int value = git_config_colorbool(NULL, arg);
 		if (value < 0)
 			return error("option `color' expects \"always\", \"auto\", or \"never\"");
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 47/76] diff.c: convert --[no-]color
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (45 preceding siblings ...)
  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 ` 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
                   ` (29 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/diff.c b/diff.c
index 13d9e5eb05..0c7a100f84 100644
--- a/diff.c
+++ b/diff.c
@@ -5152,6 +5152,8 @@ static void prep_parse_options(struct diff_options *options)
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
 		OPT_BOOL(0, "full-index", &options->flags.full_index,
 			 N_("show full pre- and post-image object names on the \"index\" lines")),
+		OPT_COLOR_FLAG(0, "color", &options->use_color,
+			       N_("show colored diff")),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5272,15 +5274,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
-		int value = git_config_colorbool(NULL, arg);
-		if (value < 0)
-			return error("option `color' expects \"always\", \"auto\", or \"never\"");
-		options->use_color = value;
-	}
-	else if (!strcmp(arg, "--no-color"))
-		options->use_color = 0;
-	else if (!strcmp(arg, "--color-moved")) {
+	if (!strcmp(arg, "--color-moved")) {
 		if (diff_color_moved_default)
 			options->color_moved = diff_color_moved_default;
 		if (options->color_moved == COLOR_MOVED_NO)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 48/76] diff.c: convert --word-diff
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (46 preceding siblings ...)
  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 ` 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
                   ` (28 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/diff.c b/diff.c
index 0c7a100f84..b80eefe9bc 100644
--- a/diff.c
+++ b/diff.c
@@ -5070,6 +5070,32 @@ static int diff_opt_unified(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_word_diff(const struct option *opt,
+			      const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (arg) {
+		if (!strcmp(arg, "plain"))
+			options->word_diff = DIFF_WORDS_PLAIN;
+		else if (!strcmp(arg, "color")) {
+			options->use_color = 1;
+			options->word_diff = DIFF_WORDS_COLOR;
+		}
+		else if (!strcmp(arg, "porcelain"))
+			options->word_diff = DIFF_WORDS_PORCELAIN;
+		else if (!strcmp(arg, "none"))
+			options->word_diff = DIFF_WORDS_NONE;
+		else
+			return error(_("bad --word-diff argument: %s"), arg);
+	} else {
+		if (options->word_diff == DIFF_WORDS_NONE)
+			options->word_diff = DIFF_WORDS_PLAIN;
+	}
+	return 0;
+}
+
 static void prep_parse_options(struct diff_options *options)
 {
 	struct option parseopts[] = {
@@ -5232,6 +5258,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "anchored", options, N_("<text>"),
 			       N_("generate diff using the \"anchored diff\" algorithm"),
 			       PARSE_OPT_NONEG, diff_opt_anchored),
+		OPT_CALLBACK_F(0, "word-diff", options, N_("<mode>"),
+			       N_("show word diff, using <mode> to delimit changed words"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5295,24 +5324,6 @@ int diff_opt_parse(struct diff_options *options,
 		options->use_color = 1;
 		options->word_diff = DIFF_WORDS_COLOR;
 	}
-	else if (!strcmp(arg, "--word-diff")) {
-		if (options->word_diff == DIFF_WORDS_NONE)
-			options->word_diff = DIFF_WORDS_PLAIN;
-	}
-	else if (skip_prefix(arg, "--word-diff=", &arg)) {
-		if (!strcmp(arg, "plain"))
-			options->word_diff = DIFF_WORDS_PLAIN;
-		else if (!strcmp(arg, "color")) {
-			options->use_color = 1;
-			options->word_diff = DIFF_WORDS_COLOR;
-		}
-		else if (!strcmp(arg, "porcelain"))
-			options->word_diff = DIFF_WORDS_PORCELAIN;
-		else if (!strcmp(arg, "none"))
-			options->word_diff = DIFF_WORDS_NONE;
-		else
-			die("bad --word-diff argument: %s", arg);
-	}
 	else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
 		if (options->word_diff == DIFF_WORDS_NONE)
 			options->word_diff = DIFF_WORDS_PLAIN;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 49/76] diff.c: convert --word-diff-regex
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (47 preceding siblings ...)
  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 ` 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
                   ` (27 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index b80eefe9bc..3e55c2fd1f 100644
--- a/diff.c
+++ b/diff.c
@@ -5096,6 +5096,18 @@ static int diff_opt_word_diff(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_word_diff_regex(const struct option *opt,
+				    const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (options->word_diff == DIFF_WORDS_NONE)
+		options->word_diff = DIFF_WORDS_PLAIN;
+	options->word_regex = arg;
+	return 0;
+}
+
 static void prep_parse_options(struct diff_options *options)
 {
 	struct option parseopts[] = {
@@ -5261,6 +5273,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "word-diff", options, N_("<mode>"),
 			       N_("show word diff, using <mode> to delimit changed words"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),
+		OPT_CALLBACK_F(0, "word-diff-regex", options, N_("<regex>"),
+			       N_("use <regex> to decide what a word is"),
+			       PARSE_OPT_NONEG, diff_opt_word_diff_regex),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5324,12 +5339,6 @@ int diff_opt_parse(struct diff_options *options,
 		options->use_color = 1;
 		options->word_diff = DIFF_WORDS_COLOR;
 	}
-	else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
-		if (options->word_diff == DIFF_WORDS_NONE)
-			options->word_diff = DIFF_WORDS_PLAIN;
-		options->word_regex = optarg;
-		return argcount;
-	}
 	else if (!strcmp(arg, "--exit-code"))
 		options->flags.exit_with_status = 1;
 	else if (!strcmp(arg, "--quiet"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 50/76] diff.c: convert --color-words
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (48 preceding siblings ...)
  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 ` 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
                   ` (26 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index 3e55c2fd1f..49cbf14417 100644
--- a/diff.c
+++ b/diff.c
@@ -4905,6 +4905,18 @@ static int diff_opt_char(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_color_words(const struct option *opt,
+				const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->use_color = 1;
+	options->word_diff = DIFF_WORDS_COLOR;
+	options->word_regex = arg;
+	return 0;
+}
+
 static int diff_opt_compact_summary(const struct option *opt,
 				    const char *arg, int unset)
 {
@@ -5276,6 +5288,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "word-diff-regex", options, N_("<regex>"),
 			       N_("use <regex> to decide what a word is"),
 			       PARSE_OPT_NONEG, diff_opt_word_diff_regex),
+		OPT_CALLBACK_F(0, "color-words", options, N_("<regex>"),
+			       N_("equivalent to --word-diff=color --word-diff-regex=<regex>"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5335,11 +5350,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
-		options->use_color = 1;
-		options->word_diff = DIFF_WORDS_COLOR;
-	}
-	else if (!strcmp(arg, "--exit-code"))
+	} else if (!strcmp(arg, "--exit-code"))
 		options->flags.exit_with_status = 1;
 	else if (!strcmp(arg, "--quiet"))
 		options->flags.quick = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 51/76] diff.c: convert --exit-code
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (49 preceding siblings ...)
  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 ` 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
                   ` (25 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 49cbf14417..888a4a4975 100644
--- a/diff.c
+++ b/diff.c
@@ -5301,6 +5301,8 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("treat all files as text")),
 		OPT_BOOL('R', NULL, &options->flags.reverse_diff,
 			 N_("swap two inputs, reverse the diff")),
+		OPT_BOOL(0, "exit-code", &options->flags.exit_with_status,
+			 N_("exit with 1 if there were differences, 0 otherwise")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5350,9 +5352,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (!strcmp(arg, "--exit-code"))
-		options->flags.exit_with_status = 1;
-	else if (!strcmp(arg, "--quiet"))
+	} else if (!strcmp(arg, "--quiet"))
 		options->flags.quick = 1;
 	else if (!strcmp(arg, "--ext-diff"))
 		options->flags.allow_external = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 52/76] diff.c: convert --quiet
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (50 preceding siblings ...)
  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 ` 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
                   ` (24 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 888a4a4975..eb81a95e89 100644
--- a/diff.c
+++ b/diff.c
@@ -5303,6 +5303,8 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("swap two inputs, reverse the diff")),
 		OPT_BOOL(0, "exit-code", &options->flags.exit_with_status,
 			 N_("exit with 1 if there were differences, 0 otherwise")),
+		OPT_BOOL(0, "quiet", &options->flags.quick,
+			 N_("disable all output of the program")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5352,9 +5354,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (!strcmp(arg, "--quiet"))
-		options->flags.quick = 1;
-	else if (!strcmp(arg, "--ext-diff"))
+	} else if (!strcmp(arg, "--ext-diff"))
 		options->flags.allow_external = 1;
 	else if (!strcmp(arg, "--no-ext-diff"))
 		options->flags.allow_external = 0;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 53/76] diff.c: convert --ext-diff
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (51 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 52/76] diff.c: convert --quiet Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (23 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index eb81a95e89..78b5d93fa5 100644
--- a/diff.c
+++ b/diff.c
@@ -5305,6 +5305,8 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("exit with 1 if there were differences, 0 otherwise")),
 		OPT_BOOL(0, "quiet", &options->flags.quick,
 			 N_("disable all output of the program")),
+		OPT_BOOL(0, "ext-diff", &options->flags.allow_external,
+			 N_("allow an external diff helper to be executed")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5354,11 +5356,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (!strcmp(arg, "--ext-diff"))
-		options->flags.allow_external = 1;
-	else if (!strcmp(arg, "--no-ext-diff"))
-		options->flags.allow_external = 0;
-	else if (!strcmp(arg, "--textconv")) {
+	} else if (!strcmp(arg, "--textconv")) {
 		options->flags.allow_textconv = 1;
 		options->flags.textconv_set_via_cmdline = 1;
 	} else if (!strcmp(arg, "--no-textconv"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 54/76] diff.c: convert --textconv
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (52 preceding siblings ...)
  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 ` 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
                   ` (22 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 78b5d93fa5..611b73d06a 100644
--- a/diff.c
+++ b/diff.c
@@ -5066,6 +5066,21 @@ static int diff_opt_relative(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_textconv(const struct option *opt,
+			     const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_ARG(arg);
+	if (unset) {
+		options->flags.allow_textconv = 0;
+	} else {
+		options->flags.allow_textconv = 1;
+		options->flags.textconv_set_via_cmdline = 1;
+	}
+	return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -5307,6 +5322,9 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("disable all output of the program")),
 		OPT_BOOL(0, "ext-diff", &options->flags.allow_external,
 			 N_("allow an external diff helper to be executed")),
+		OPT_CALLBACK_F(0, "textconv", options, NULL,
+			       N_("run external text conversion filters when comparing binary files"),
+			       PARSE_OPT_NOARG, diff_opt_textconv),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5356,12 +5374,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (!strcmp(arg, "--textconv")) {
-		options->flags.allow_textconv = 1;
-		options->flags.textconv_set_via_cmdline = 1;
-	} else if (!strcmp(arg, "--no-textconv"))
-		options->flags.allow_textconv = 0;
-	else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
+	} else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
 		options->flags.override_submodule_config = 1;
 		handle_ignore_submodules_arg(options, arg);
 	} else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 55/76] diff.c: convert --ignore-submodules
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (53 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 54/76] diff.c: convert --textconv Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (21 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 611b73d06a..bf7d2afcce 100644
--- a/diff.c
+++ b/diff.c
@@ -5017,6 +5017,19 @@ static int diff_opt_follow(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_ignore_submodules(const struct option *opt,
+				      const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg)
+		arg = "all";
+	options->flags.override_submodule_config = 1;
+	handle_ignore_submodules_arg(options, arg);
+	return 0;
+}
+
 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 					     const struct option *opt,
 					     const char *arg, int unset)
@@ -5325,6 +5338,10 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "textconv", options, NULL,
 			       N_("run external text conversion filters when comparing binary files"),
 			       PARSE_OPT_NOARG, diff_opt_textconv),
+		OPT_CALLBACK_F(0, "ignore-submodules", options, N_("<when>"),
+			       N_("ignore changes to submodules in the diff generation"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_ignore_submodules),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5374,9 +5391,6 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
-		options->flags.override_submodule_config = 1;
-		handle_ignore_submodules_arg(options, arg);
 	} else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
 		return parse_submodule_opt(options, arg);
 	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 56/76] diff.c: convert --submodule
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (54 preceding siblings ...)
  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 ` 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
                   ` (20 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/diff.c b/diff.c
index bf7d2afcce..4d3eababe3 100644
--- a/diff.c
+++ b/diff.c
@@ -4725,14 +4725,6 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
 	return 1;
 }
 
-static int parse_submodule_opt(struct diff_options *options, const char *value)
-{
-	if (parse_submodule_params(options, value))
-		die(_("Failed to parse --submodule option parameter: '%s'"),
-			value);
-	return 1;
-}
-
 static const char diff_status_letters[] = {
 	DIFF_STATUS_ADDED,
 	DIFF_STATUS_COPIED,
@@ -5079,6 +5071,20 @@ static int diff_opt_relative(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_submodule(const struct option *opt,
+			      const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg)
+		arg = "log";
+	if (parse_submodule_params(options, arg))
+		return error(_("failed to parse --submodule option parameter: '%s'"),
+			     arg);
+	return 0;
+}
+
 static int diff_opt_textconv(const struct option *opt,
 			     const char *arg, int unset)
 {
@@ -5342,6 +5348,10 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("ignore changes to submodules in the diff generation"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_ignore_submodules),
+		OPT_CALLBACK_F(0, "submodule", options, N_("<format>"),
+			       N_("specify how differences in submodules are shown"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_submodule),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5391,9 +5401,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
-		return parse_submodule_opt(options, arg);
-	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
+	} else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
 		return parse_ws_error_highlight_opt(options, arg);
 	else if (!strcmp(arg, "--ita-invisible-in-index"))
 		options->ita_invisible_in_index = 1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 57/76] diff.c: convert --ws-error-highlight
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (55 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 56/76] diff.c: convert --submodule Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (19 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/diff.c b/diff.c
index 4d3eababe3..c60cfc80a4 100644
--- a/diff.c
+++ b/diff.c
@@ -4804,17 +4804,18 @@ static void enable_patch_output(int *fmt) {
 	*fmt |= DIFF_FORMAT_PATCH;
 }
 
-static int parse_ws_error_highlight_opt(struct diff_options *opt, const char *arg)
+static int diff_opt_ws_error_highlight(const struct option *option,
+				       const char *arg, int unset)
 {
+	struct diff_options *opt = option->value;
 	int val = parse_ws_error_highlight(arg);
 
-	if (val < 0) {
-		error("unknown value after ws-error-highlight=%.*s",
-		      -1 - val, arg);
-		return 0;
-	}
+	BUG_ON_OPT_NEG(unset);
+	if (val < 0)
+		return error("unknown value after ws-error-highlight=%.*s",
+			     -1 - val, arg);
 	opt->ws_error_highlight = val;
-	return 1;
+	return 0;
 }
 
 static int parse_objfind_opt(struct diff_options *opt, const char *arg)
@@ -5238,6 +5239,9 @@ static void prep_parse_options(struct diff_options *options)
 			 N_("show full pre- and post-image object names on the \"index\" lines")),
 		OPT_COLOR_FLAG(0, "color", &options->use_color,
 			       N_("show colored diff")),
+		OPT_CALLBACK_F(0, "ws-error-highlight", options, N_("<kind>"),
+			       N_("highlight whitespaces errors in the context, old or new lines in the diff"),
+			       PARSE_OPT_NONEG, diff_opt_ws_error_highlight),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5401,9 +5405,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
-		return parse_ws_error_highlight_opt(options, arg);
-	else if (!strcmp(arg, "--ita-invisible-in-index"))
+	} else if (!strcmp(arg, "--ita-invisible-in-index"))
 		options->ita_invisible_in_index = 1;
 	else if (!strcmp(arg, "--ita-visible-in-index"))
 		options->ita_invisible_in_index = 0;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 58/76] diff.c: convert --ita-[in]visible-in-index
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (56 preceding siblings ...)
  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 ` 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
                   ` (18 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index c60cfc80a4..0922937bab 100644
--- a/diff.c
+++ b/diff.c
@@ -5356,6 +5356,12 @@ static void prep_parse_options(struct diff_options *options)
 			       N_("specify how differences in submodules are shown"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
 			       diff_opt_submodule),
+		OPT_SET_INT_F(0, "ita-invisible-in-index", &options->ita_invisible_in_index,
+			      N_("hide 'git add -N' entries from the index"),
+			      1, PARSE_OPT_NONEG),
+		OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
+			      N_("treat 'git add -N' entries as real in the index"),
+			      0, PARSE_OPT_NONEG),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5405,10 +5411,7 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
 		options->color_moved_ws_handling = cm;
-	} else if (!strcmp(arg, "--ita-invisible-in-index"))
-		options->ita_invisible_in_index = 1;
-	else if (!strcmp(arg, "--ita-visible-in-index"))
-		options->ita_invisible_in_index = 0;
+	}
 
 	/* misc options */
 	else if (!strcmp(arg, "-z"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 59/76] diff.c: convert -z
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (57 preceding siblings ...)
  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 ` 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
                   ` (17 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/diff.c b/diff.c
index 0922937bab..e4495194d3 100644
--- a/diff.c
+++ b/diff.c
@@ -5242,6 +5242,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "ws-error-highlight", options, N_("<kind>"),
 			       N_("highlight whitespaces errors in the context, old or new lines in the diff"),
 			       PARSE_OPT_NONEG, diff_opt_ws_error_highlight),
+		OPT_SET_INT('z', NULL, &options->line_termination,
+			    N_("do not munge pathnames and use NULs as output field terminators in --raw or --numstat"),
+			    0),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5414,8 +5417,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (!strcmp(arg, "-z"))
-		options->line_termination = 0;
 	else if ((argcount = short_opt('l', av, &optarg))) {
 		options->rename_limit = strtoul(optarg, NULL, 10);
 		return argcount;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 60/76] diff.c: convert -l
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (58 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 59/76] diff.c: convert -z Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:05 ` 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
                   ` (16 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index e4495194d3..00a56a25e0 100644
--- a/diff.c
+++ b/diff.c
@@ -5287,6 +5287,8 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "follow", options, NULL,
 			       N_("continue listing the history of a file beyond renames"),
 			       PARSE_OPT_NOARG, diff_opt_follow),
+		OPT_INTEGER('l', NULL, &options->rename_limit,
+			    N_("prevent rename/copy detection if the number of rename/copy targets exceeds given limit")),
 
 		OPT_GROUP(N_("Diff algorithm options")),
 		OPT_BIT(0, "minimal", &options->xdl_opts,
@@ -5417,10 +5419,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = short_opt('l', av, &optarg))) {
-		options->rename_limit = strtoul(optarg, NULL, 10);
-		return argcount;
-	}
 	else if ((argcount = short_opt('S', av, &optarg))) {
 		options->pickaxe = optarg;
 		options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 61/76] diff.c: convert -S|-G
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (59 preceding siblings ...)
  2019-01-17 13:05 ` [PATCH 60/76] diff.c: convert -l Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:06 ` 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
                   ` (15 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/diff.c b/diff.c
index 00a56a25e0..832a5bcd31 100644
--- a/diff.c
+++ b/diff.c
@@ -5060,6 +5060,28 @@ static int diff_opt_patience(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_pickaxe_regex(const struct option *opt,
+				  const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->pickaxe = arg;
+	options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
+	return 0;
+}
+
+static int diff_opt_pickaxe_string(const struct option *opt,
+				   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->pickaxe = arg;
+	options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
+	return 0;
+}
+
 static int diff_opt_relative(const struct option *opt,
 			     const char *arg, int unset)
 {
@@ -5367,6 +5389,12 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
 			      N_("treat 'git add -N' entries as real in the index"),
 			      0, PARSE_OPT_NONEG),
+		OPT_CALLBACK_F('S', NULL, options, N_("<string>"),
+			       N_("look for differences that change the number of occurrences of the specified string"),
+			       0, diff_opt_pickaxe_string),
+		OPT_CALLBACK_F('G', NULL, options, N_("<regex>"),
+			       N_("look for differences that change the number of occurrences of the specified regex"),
+			       0, diff_opt_pickaxe_regex),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5419,15 +5447,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = short_opt('S', av, &optarg))) {
-		options->pickaxe = optarg;
-		options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
-		return argcount;
-	} else if ((argcount = short_opt('G', av, &optarg))) {
-		options->pickaxe = optarg;
-		options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
-		return argcount;
-	}
 	else if (!strcmp(arg, "--pickaxe-all"))
 		options->pickaxe_opts |= DIFF_PICKAXE_ALL;
 	else if (!strcmp(arg, "--pickaxe-regex"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 62/76] diff.c: convert --pickaxe-all|--pickaxe-regex
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (60 preceding siblings ...)
  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 ` 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
                   ` (14 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 832a5bcd31..ae993f5551 100644
--- a/diff.c
+++ b/diff.c
@@ -5395,6 +5395,12 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F('G', NULL, options, N_("<regex>"),
 			       N_("look for differences that change the number of occurrences of the specified regex"),
 			       0, diff_opt_pickaxe_regex),
+		OPT_BIT_F(0, "pickaxe-all", &options->pickaxe_opts,
+			  N_("show all changes in the changeset with -S or -G"),
+			  DIFF_PICKAXE_ALL, PARSE_OPT_NONEG),
+		OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
+			  N_("treat <string> in -S as extended POSIX regular expression"),
+			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5447,10 +5453,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (!strcmp(arg, "--pickaxe-all"))
-		options->pickaxe_opts |= DIFF_PICKAXE_ALL;
-	else if (!strcmp(arg, "--pickaxe-regex"))
-		options->pickaxe_opts |= DIFF_PICKAXE_REGEX;
 	else if ((argcount = short_opt('O', av, &optarg))) {
 		options->orderfile = prefix_filename(prefix, optarg);
 		return argcount;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 63/76] diff.c: convert -O
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (61 preceding siblings ...)
  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 ` 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
                   ` (13 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index ae993f5551..4e004a2195 100644
--- a/diff.c
+++ b/diff.c
@@ -5401,6 +5401,8 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
 			  N_("treat <string> in -S as extended POSIX regular expression"),
 			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
+		OPT_FILENAME('O', NULL, &options->orderfile,
+			     N_("override diff.orderFile configuration variable")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5453,10 +5455,7 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = short_opt('O', av, &optarg))) {
-		options->orderfile = prefix_filename(prefix, optarg);
-		return argcount;
-	} else if (skip_prefix(arg, "--find-object=", &arg))
+	else if (skip_prefix(arg, "--find-object=", &arg))
 		return parse_objfind_opt(options, arg);
 	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
 		int offending = parse_diff_filter_opt(optarg, options);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 64/76] diff.c: convert --find-object
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (62 preceding siblings ...)
  2019-01-17 13:06 ` [PATCH 63/76] diff.c: convert -O Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:06 ` 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
                   ` (12 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index 4e004a2195..2a943d47fd 100644
--- a/diff.c
+++ b/diff.c
@@ -4818,12 +4818,15 @@ static int diff_opt_ws_error_highlight(const struct option *option,
 	return 0;
 }
 
-static int parse_objfind_opt(struct diff_options *opt, const char *arg)
+static int diff_opt_find_object(const struct option *option,
+				const char *arg, int unset)
 {
+	struct diff_options *opt = option->value;
 	struct object_id oid;
 
+	BUG_ON_OPT_NEG(unset);
 	if (get_oid(arg, &oid))
-		return error("unable to resolve '%s'", arg);
+		return error(_("unable to resolve '%s'"), arg);
 
 	if (!opt->objfind)
 		opt->objfind = xcalloc(1, sizeof(*opt->objfind));
@@ -4832,7 +4835,7 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	opt->flags.recursive = 1;
 	opt->flags.tree_in_recursive = 1;
 	oidset_insert(opt->objfind, &oid);
-	return 1;
+	return 0;
 }
 
 static int diff_opt_anchored(const struct option *opt,
@@ -5403,6 +5406,9 @@ static void prep_parse_options(struct diff_options *options)
 			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
 		OPT_FILENAME('O', NULL, &options->orderfile,
 			     N_("override diff.orderFile configuration variable")),
+		OPT_CALLBACK_F(0, "find-object", options, N_("<object-id>"),
+			       N_("look for differences that change the number of occurrences of the specified object"),
+			       PARSE_OPT_NONEG, diff_opt_find_object),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5455,8 +5461,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (skip_prefix(arg, "--find-object=", &arg))
-		return parse_objfind_opt(options, arg);
 	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
 		int offending = parse_diff_filter_opt(optarg, options);
 		if (offending)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 65/76] diff.c: convert --diff-filter
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (63 preceding siblings ...)
  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 ` 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
                   ` (11 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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

diff --git a/diff.c b/diff.c
index 2a943d47fd..fee45c5066 100644
--- a/diff.c
+++ b/diff.c
@@ -4756,10 +4756,13 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)
 	return opt->filter & filter_bit[(int) status];
 }
 
-static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)
+static int diff_opt_diff_filter(const struct option *option,
+				const char *optarg, int unset)
 {
+	struct diff_options *opt = option->value;
 	int i, optch;
 
+	BUG_ON_OPT_NEG(unset);
 	prepare_filter_bits();
 
 	/*
@@ -4790,7 +4793,8 @@ static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)
 
 		bit = (0 <= optch && optch <= 'Z') ? filter_bit[optch] : 0;
 		if (!bit)
-			return optarg[i];
+			return error(_("unknown change class '%c' in --diff-filter=%s"),
+				     optarg[i], optarg);
 		if (negate)
 			opt->filter &= ~bit;
 		else
@@ -5409,6 +5413,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "find-object", options, N_("<object-id>"),
 			       N_("look for differences that change the number of occurrences of the specified object"),
 			       PARSE_OPT_NONEG, diff_opt_find_object),
+		OPT_CALLBACK_F(0, "diff-filter", options, N_("[(A|C|D|M|R|T|U|X|B)...[*]]"),
+			       N_("select files by diff type"),
+			       PARSE_OPT_NONEG, diff_opt_diff_filter),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5461,13 +5468,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
-		int offending = parse_diff_filter_opt(optarg, options);
-		if (offending)
-			die("unknown change class '%c' in --diff-filter=%s",
-			    offending, optarg);
-		return argcount;
-	}
 	else if (!strcmp(arg, "--no-abbrev"))
 		options->abbrev = 0;
 	else if (!strcmp(arg, "--abbrev"))
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 66/76] diff.c: convert --[no-]abbrev
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (64 preceding siblings ...)
  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 ` 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
                   ` (10 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c             | 12 +-----------
 parse-options-cb.c |  4 ++--
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/diff.c b/diff.c
index fee45c5066..f137b7f442 100644
--- a/diff.c
+++ b/diff.c
@@ -5274,6 +5274,7 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_SET_INT('z', NULL, &options->line_termination,
 			    N_("do not munge pathnames and use NULs as output field terminators in --raw or --numstat"),
 			    0),
+		OPT__ABBREV(&options->abbrev),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5468,17 +5469,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (!strcmp(arg, "--no-abbrev"))
-		options->abbrev = 0;
-	else if (!strcmp(arg, "--abbrev"))
-		options->abbrev = DEFAULT_ABBREV;
-	else if (skip_prefix(arg, "--abbrev=", &arg)) {
-		options->abbrev = strtoul(arg, NULL, 10);
-		if (options->abbrev < MINIMUM_ABBREV)
-			options->abbrev = MINIMUM_ABBREV;
-		else if (the_hash_algo->hexsz < options->abbrev)
-			options->abbrev = the_hash_algo->hexsz;
-	}
 	else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
 		options->a_prefix = optarg;
 		return argcount;
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 2733393546..6e2e8d6273 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -22,8 +22,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
 				     opt->long_name);
 		if (v && v < MINIMUM_ABBREV)
 			v = MINIMUM_ABBREV;
-		else if (v > 40)
-			v = 40;
+		else if (v > the_hash_algo->hexsz)
+			v = the_hash_algo->hexsz;
 	}
 	*(int *)(opt->value) = v;
 	return 0;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 67/76] diff.c: convert --[src|dst]-prefix
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (65 preceding siblings ...)
  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 ` 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
                   ` (9 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c          | 14 ++++++--------
 parse-options.h |  3 ++-
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/diff.c b/diff.c
index f137b7f442..0d66497851 100644
--- a/diff.c
+++ b/diff.c
@@ -5275,6 +5275,12 @@ static void prep_parse_options(struct diff_options *options)
 			    N_("do not munge pathnames and use NULs as output field terminators in --raw or --numstat"),
 			    0),
 		OPT__ABBREV(&options->abbrev),
+		OPT_STRING_F(0, "src-prefix", &options->a_prefix, N_("<prefix>"),
+			     N_("show the given source prefix instead of \"a/\""),
+			     PARSE_OPT_NONEG),
+		OPT_STRING_F(0, "dst-prefix", &options->b_prefix, N_("<prefix>"),
+			     N_("show the given source prefix instead of \"b/\""),
+			     PARSE_OPT_NONEG),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5469,20 +5475,12 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
-		options->a_prefix = optarg;
-		return argcount;
-	}
 	else if ((argcount = parse_long_opt("line-prefix", av, &optarg))) {
 		options->line_prefix = optarg;
 		options->line_prefix_length = strlen(options->line_prefix);
 		graph_setup_line_prefix(options);
 		return argcount;
 	}
-	else if ((argcount = parse_long_opt("dst-prefix", av, &optarg))) {
-		options->b_prefix = optarg;
-		return argcount;
-	}
 	else if (!strcmp(arg, "--no-prefix"))
 		options->a_prefix = options->b_prefix = "";
 	else if (opt_arg(arg, '\0', "inter-hunk-context",
diff --git a/parse-options.h b/parse-options.h
index 7d83e2971d..c95cbe26f0 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -136,6 +136,7 @@ struct option {
 #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f)
 #define OPT_CALLBACK_F(s, l, v, a, h, f, cb)			\
 	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
+#define OPT_STRING_F(s, l, v, a, h, f)   { OPTION_STRING,  (s), (l), (v), (a), (h), (f) }
 
 #define OPT_END()                   { OPTION_END }
 #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -157,7 +158,7 @@ struct option {
 #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
 #define OPT_MAGNITUDE(s, l, v, h)   { OPTION_MAGNITUDE, (s), (l), (v), \
 				      N_("n"), (h), PARSE_OPT_NONEG }
-#define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
+#define OPT_STRING(s, l, v, a, h)   OPT_STRING_F(s, l, v, a, h, 0)
 #define OPT_STRING_LIST(s, l, v, a, h) \
 				    { OPTION_CALLBACK, (s), (l), (v), (a), \
 				      (h), 0, &parse_opt_string_list }
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 68/76] diff.c: convert --line-prefix
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (66 preceding siblings ...)
  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 ` 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
                   ` (8 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/diff.c b/diff.c
index 0d66497851..25c386b04c 100644
--- a/diff.c
+++ b/diff.c
@@ -5030,6 +5030,18 @@ static int diff_opt_ignore_submodules(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_line_prefix(const struct option *opt,
+				const char *optarg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	options->line_prefix = optarg;
+	options->line_prefix_length = strlen(options->line_prefix);
+	graph_setup_line_prefix(options);
+	return 0;
+}
+
 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 					     const struct option *opt,
 					     const char *arg, int unset)
@@ -5281,6 +5293,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_STRING_F(0, "dst-prefix", &options->b_prefix, N_("<prefix>"),
 			     N_("show the given source prefix instead of \"b/\""),
 			     PARSE_OPT_NONEG),
+		OPT_CALLBACK_F(0, "line-prefix", options, N_("<prefix>"),
+			       N_("prepend an additional prefix to every line of output"),
+			       PARSE_OPT_NONEG, diff_opt_line_prefix),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5438,8 +5453,6 @@ int diff_opt_parse(struct diff_options *options,
 		   const char **av, int ac, const char *prefix)
 {
 	const char *arg = av[0];
-	const char *optarg;
-	int argcount;
 
 	if (!prefix)
 		prefix = "";
@@ -5475,12 +5488,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = parse_long_opt("line-prefix", av, &optarg))) {
-		options->line_prefix = optarg;
-		options->line_prefix_length = strlen(options->line_prefix);
-		graph_setup_line_prefix(options);
-		return argcount;
-	}
 	else if (!strcmp(arg, "--no-prefix"))
 		options->a_prefix = options->b_prefix = "";
 	else if (opt_arg(arg, '\0', "inter-hunk-context",
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 69/76] diff.c: convert --no-prefix
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (67 preceding siblings ...)
  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 ` 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
                   ` (7 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/diff.c b/diff.c
index 25c386b04c..3e7c36524d 100644
--- a/diff.c
+++ b/diff.c
@@ -5042,6 +5042,18 @@ static int diff_opt_line_prefix(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_no_prefix(const struct option *opt,
+			      const char *optarg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(optarg);
+	options->a_prefix = "";
+	options->b_prefix = "";
+	return 0;
+}
+
 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
 					     const struct option *opt,
 					     const char *arg, int unset)
@@ -5296,6 +5308,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "line-prefix", options, N_("<prefix>"),
 			       N_("prepend an additional prefix to every line of output"),
 			       PARSE_OPT_NONEG, diff_opt_line_prefix),
+		OPT_CALLBACK_F(0, "no-prefix", options, NULL,
+			       N_("no not show any source or destination prefix"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5488,8 +5503,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (!strcmp(arg, "--no-prefix"))
-		options->a_prefix = options->b_prefix = "";
 	else if (opt_arg(arg, '\0', "inter-hunk-context",
 			 &options->interhunkcontext))
 		;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 70/76] diff.c: convert --inter-hunk-context
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (68 preceding siblings ...)
  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 ` 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
                   ` (6 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c          | 6 +++---
 parse-options.h | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index 3e7c36524d..cc10b27df0 100644
--- a/diff.c
+++ b/diff.c
@@ -5311,6 +5311,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "no-prefix", options, NULL,
 			       N_("no not show any source or destination prefix"),
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),
+		OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext,
+			      N_("show context between diff hunks up to the specified number of lines"),
+			      PARSE_OPT_NONEG),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5503,9 +5506,6 @@ int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if (opt_arg(arg, '\0', "inter-hunk-context",
-			 &options->interhunkcontext))
-		;
 	else
 		return 0;
 	return 1;
diff --git a/parse-options.h b/parse-options.h
index c95cbe26f0..cca64d04cb 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -137,6 +137,7 @@ struct option {
 #define OPT_CALLBACK_F(s, l, v, a, h, f, cb)			\
 	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
 #define OPT_STRING_F(s, l, v, a, h, f)   { OPTION_STRING,  (s), (l), (v), (a), (h), (f) }
+#define OPT_INTEGER_F(s, l, v, h, f)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
 
 #define OPT_END()                   { OPTION_END }
 #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -155,7 +156,7 @@ struct option {
 				      (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
 #define OPT_CMDMODE(s, l, v, h, i)  { OPTION_CMDMODE, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
-#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
+#define OPT_INTEGER(s, l, v, h)     OPT_INTEGER_F(s, l, v, h, 0)
 #define OPT_MAGNITUDE(s, l, v, h)   { OPTION_MAGNITUDE, (s), (l), (v), \
 				      N_("n"), (h), PARSE_OPT_NONEG }
 #define OPT_STRING(s, l, v, a, h)   OPT_STRING_F(s, l, v, a, h, 0)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 71/76] diff.c: convert --color-moved
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (69 preceding siblings ...)
  2019-01-17 13:06 ` [PATCH 70/76] diff.c: convert --inter-hunk-context Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:06 ` 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
                   ` (5 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/diff.c b/diff.c
index cc10b27df0..5403351466 100644
--- a/diff.c
+++ b/diff.c
@@ -4905,6 +4905,27 @@ static int diff_opt_char(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_color_moved(const struct option *opt,
+				const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	if (unset) {
+		options->color_moved = COLOR_MOVED_NO;
+	} else if (!arg) {
+		if (diff_color_moved_default)
+			options->color_moved = diff_color_moved_default;
+		if (options->color_moved == COLOR_MOVED_NO)
+			options->color_moved = COLOR_MOVED_DEFAULT;
+	} else {
+		int cm = parse_color_moved(arg);
+		if (cm < 0)
+			return error("bad --color-moved argument: %s", arg);
+		options->color_moved = cm;
+	}
+	return 0;
+}
+
 static int diff_opt_color_words(const struct option *opt,
 				const char *arg, int unset)
 {
@@ -5403,6 +5424,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "color-words", options, N_("<regex>"),
 			       N_("equivalent to --word-diff=color --word-diff-regex=<regex>"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),
+		OPT_CALLBACK_F(0, "color-moved", options, N_("<mode>"),
+			       N_("move lines of code are colored differently"),
+			       PARSE_OPT_OPTARG, diff_opt_color_moved),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5486,19 +5510,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--color-moved")) {
-		if (diff_color_moved_default)
-			options->color_moved = diff_color_moved_default;
-		if (options->color_moved == COLOR_MOVED_NO)
-			options->color_moved = COLOR_MOVED_DEFAULT;
-	} else if (!strcmp(arg, "--no-color-moved"))
-		options->color_moved = COLOR_MOVED_NO;
-	else if (skip_prefix(arg, "--color-moved=", &arg)) {
-		int cm = parse_color_moved(arg);
-		if (cm < 0)
-			return error("bad --color-moved argument: %s", arg);
-		options->color_moved = cm;
-	} else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
+	if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
 		unsigned cm = parse_color_moved_ws(arg);
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 72/76] diff.c: convert --color-moved-ws
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (70 preceding siblings ...)
  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 ` 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
                   ` (4 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/diff.c b/diff.c
index 5403351466..e79a72cde9 100644
--- a/diff.c
+++ b/diff.c
@@ -4926,6 +4926,20 @@ static int diff_opt_color_moved(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_color_moved_ws(const struct option *opt,
+				   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+	unsigned cm;
+
+	BUG_ON_OPT_NEG(unset);
+	cm = parse_color_moved_ws(arg);
+	if (cm & COLOR_MOVED_WS_ERROR)
+		return error(_("invalid mode '%s' in --color-moved-ws"), arg);
+	options->color_moved_ws_handling = cm;
+	return 0;
+}
+
 static int diff_opt_color_words(const struct option *opt,
 				const char *arg, int unset)
 {
@@ -5427,6 +5441,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "color-moved", options, N_("<mode>"),
 			       N_("move lines of code are colored differently"),
 			       PARSE_OPT_OPTARG, diff_opt_color_moved),
+		OPT_CALLBACK_F(0, "color-moved-ws", options, N_("<mode>"),
+			       N_("how white spaces are ignored in --color-moved"),
+			       PARSE_OPT_NONEG, diff_opt_color_moved_ws),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5494,8 +5511,6 @@ 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)
 {
-	const char *arg = av[0];
-
 	if (!prefix)
 		prefix = "";
 
@@ -5506,21 +5521,7 @@ int diff_opt_parse(struct diff_options *options,
 			   PARSE_OPT_ONE_SHOT |
 			   PARSE_OPT_STOP_AT_NON_OPTION);
 
-	if (ac)
-		return ac;
-
-	/* flags options */
-	if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
-		unsigned cm = parse_color_moved_ws(arg);
-		if (cm & COLOR_MOVED_WS_ERROR)
-			return -1;
-		options->color_moved_ws_handling = cm;
-	}
-
-	/* misc options */
-	else
-		return 0;
-	return 1;
+	return ac;
 }
 
 int parse_rename_score(const char **cp_p)
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 73/76] diff.c: allow --no-color-moved-ws
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (71 preceding siblings ...)
  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 ` Nguyễn Thái Ngọc Duy
  2019-01-17 13:06 ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
                   ` (3 subsequent siblings)
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This option is added in commit b73bcbac4a (diff: allow
--no-color-moved-ws - 2018-11-23) in pw/diff-color-moved-ws-fix. To ease
merge conflict resolution, re-implement the option handling here so that
the conflict could be resolved by taking this side of change.

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

diff --git a/diff.c b/diff.c
index e79a72cde9..daccc8226f 100644
--- a/diff.c
+++ b/diff.c
@@ -4932,7 +4932,11 @@ static int diff_opt_color_moved_ws(const struct option *opt,
 	struct diff_options *options = opt->value;
 	unsigned cm;
 
-	BUG_ON_OPT_NEG(unset);
+	if (unset) {
+		options->color_moved_ws_handling = 0;
+		return 0;
+	}
+
 	cm = parse_color_moved_ws(arg);
 	if (cm & COLOR_MOVED_WS_ERROR)
 		return error(_("invalid mode '%s' in --color-moved-ws"), arg);
@@ -5443,7 +5447,7 @@ static void prep_parse_options(struct diff_options *options)
 			       PARSE_OPT_OPTARG, diff_opt_color_moved),
 		OPT_CALLBACK_F(0, "color-moved-ws", options, N_("<mode>"),
 			       N_("how white spaces are ignored in --color-moved"),
-			       PARSE_OPT_NONEG, diff_opt_color_moved_ws),
+			       0, diff_opt_color_moved_ws),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (72 preceding siblings ...)
  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
  2019-01-17 19:46   ` Stefan Beller
  2019-01-17 13:06 ` [PATCH 75/76] diff --no-index: " Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 75/76] diff --no-index: use parse_options() instead of diff_opt_parse()
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (73 preceding siblings ...)
  2019-01-17 13:06 ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:06 ` 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 14:32 ` [PATCH 00/76] Convert diff opt parser to parse_options() Ævar Arnfjörð Bjarmason
  76 siblings, 0 replies; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

While at there, move exit() back to the caller. It's easier to see the
flow that way than burying it in diff-no-index.c

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/diff.c           | 21 +++--------------
 diff-no-index.c          | 49 ++++++++++++++++++++++++----------------
 diff.h                   |  3 ++-
 t/t4053-diff-no-index.sh |  3 +--
 4 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/builtin/diff.c b/builtin/diff.c
index f0393bba23..52dc3e136f 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -320,26 +320,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 
 	repo_init_revisions(the_repository, &rev, prefix);
 
-	if (no_index && argc != i + 2) {
-		if (no_index == DIFF_NO_INDEX_IMPLICIT) {
-			/*
-			 * There was no --no-index and there were not two
-			 * paths. It is possible that the user intended
-			 * to do an inside-repository operation.
-			 */
-			fprintf(stderr, "Not a git repository\n");
-			fprintf(stderr,
-				"To compare two paths outside a working tree:\n");
-		}
-		/* Give the usage message for non-repository usage and exit. */
-		usagef("git diff %s <path> <path>",
-		       no_index == DIFF_NO_INDEX_EXPLICIT ?
-		       "--no-index" : "[--no-index]");
-
-	}
 	if (no_index)
 		/* If this is a no-index diff, just run it and exit there. */
-		diff_no_index(the_repository, &rev, argc, argv);
+		exit(diff_no_index(the_repository, &rev,
+				   no_index == DIFF_NO_INDEX_IMPLICIT,
+				   argc, argv));
 
 	/* Otherwise, we are doing the usual "git" diff */
 	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
diff --git a/diff-no-index.c b/diff-no-index.c
index 9414e922d1..a879f45862 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -14,6 +14,7 @@
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
+#include "parse-options.h"
 #include "string-list.h"
 #include "dir.h"
 
@@ -233,35 +234,43 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
 	}
 }
 
-void diff_no_index(struct repository *r,
-		   struct rev_info *revs,
-		   int argc, const char **argv)
+static const char * const diff_no_index_usage[] = {
+	N_("git diff --no-index [<options>] <path> <path>"),
+	NULL
+};
+
+int diff_no_index(struct repository *r,
+		  struct rev_info *revs,
+		  int implicit_no_index,
+		  int argc, const char **argv)
 {
-	int i;
+	int i, no_index;
 	const char *paths[2];
 	struct strbuf replacement = STRBUF_INIT;
 	const char *prefix = revs->prefix;
+	struct option no_index_options[] = {
+		OPT_BOOL_F(0, "no-index", &no_index, "",
+			   PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),
+		OPT_END(),
+	};
+	struct option *options;
 
 	/*
 	 * FIXME: --no-index should not look at index and we should be
 	 * able to pass NULL repo. Maybe later.
 	 */
 	repo_diff_setup(r, &revs->diffopt);
-	for (i = 1; i < argc - 2; ) {
-		int j;
-		if (!strcmp(argv[i], "--no-index"))
-			i++;
-		else if (!strcmp(argv[i], "--"))
-			i++;
-		else {
-			j = diff_opt_parse(&revs->diffopt, argv + i, argc - i,
-					   revs->prefix);
-			if (j <= 0)
-				die("invalid diff option/value: %s", argv[i]);
-			i += j;
-		}
+	options = parse_options_concat(no_index_options,
+				       revs->diffopt.parseopts);
+	argc = parse_options(argc, argv, revs->prefix, options,
+			     diff_no_index_usage, 0);
+	if (argc != 2) {
+		if (implicit_no_index)
+			warning(_("Not a git repository. Use --no-index to "
+				  "compare two paths outside a working tree"));
+		usage_with_options(diff_no_index_usage, options);
 	}
-
+	FREE_AND_NULL(options);
 	for (i = 0; i < 2; i++) {
 		const char *p = argv[argc - 2 + i];
 		if (!strcmp(p, "-"))
@@ -293,7 +302,7 @@ void diff_no_index(struct repository *r,
 	revs->diffopt.flags.exit_with_status = 1;
 
 	if (queue_diff(&revs->diffopt, paths[0], paths[1]))
-		exit(1);
+		return 1;
 	diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
 	diffcore_std(&revs->diffopt);
 	diff_flush(&revs->diffopt);
@@ -304,5 +313,5 @@ void diff_no_index(struct repository *r,
 	 * The return code for --no-index imitates diff(1):
 	 * 0 = no changes, 1 = changes, else error
 	 */
-	exit(diff_result_code(&revs->diffopt, 0));
+	return diff_result_code(&revs->diffopt, 0);
 }
diff --git a/diff.h b/diff.h
index d9ad73f0e1..03c6afda22 100644
--- a/diff.h
+++ b/diff.h
@@ -437,7 +437,8 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 
 int diff_result_code(struct diff_options *, int);
 
-void diff_no_index(struct repository *, struct rev_info *, int, const char **);
+int diff_no_index(struct repository *, struct rev_info *,
+		  int implicit_no_index, int, const char **);
 
 int index_differs_from(struct repository *r, const char *def,
 		       const struct diff_flags *flags,
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 6e0dd6f9e5..fb25cdb789 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -50,8 +50,7 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err
 		export GIT_CEILING_DIRECTORIES &&
 		cd non/git &&
 		test_must_fail git diff --no-index a 2>actual.err &&
-		echo "usage: git diff --no-index <path> <path>" >expect.err &&
-		test_cmp expect.err actual.err
+		test_i18ngrep "usage: git diff --no-index" actual.err
 	)
 '
 
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* [PATCH 76/76] am: avoid diff_opt_parse()
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (74 preceding siblings ...)
  2019-01-17 13:06 ` [PATCH 75/76] diff --no-index: " Nguyễn Thái Ngọc Duy
@ 2019-01-17 13:06 ` Nguyễn Thái Ngọc Duy
  2019-01-17 20:10   ` Johannes Schindelin
  2019-01-17 14:32 ` [PATCH 00/76] Convert diff opt parser to parse_options() Ævar Arnfjörð Bjarmason
  76 siblings, 1 reply; 88+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-17 13:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

diff_opt_parse() is a heavy hammer to just set diff filter. But it's
the only way because of the diff_status_letters[] mapping. Add a new
API to set diff filter and use it in git-am. diff_opt_parse()'s only
remaining call site in revision.c will be gone soon and having it here
just because of git-am does not make sense.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/am.c | 4 ++--
 diff.c       | 6 ++++++
 diff.h       | 2 ++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 95370313b6..0cbf285459 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		 * review them with extra care to spot mismerges.
 		 */
 		struct rev_info rev_info;
-		const char *diff_filter_str = "--diff-filter=AM";
 
 		repo_init_revisions(the_repository, &rev_info, NULL);
 		rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
-		diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
+		rev_info.diffopt.filter |= diff_filter_bit('A');
+		rev_info.diffopt.filter |= diff_filter_bit('M');
 		add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
 		diff_setup_done(&rev_info.diffopt);
 		run_diff_index(&rev_info, 1);
diff --git a/diff.c b/diff.c
index daccc8226f..b8e58e817b 100644
--- a/diff.c
+++ b/diff.c
@@ -4756,6 +4756,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)
 	return opt->filter & filter_bit[(int) status];
 }
 
+unsigned diff_filter_bit(char status)
+{
+	prepare_filter_bits();
+	return filter_bit[(int) status];
+}
+
 static int diff_opt_diff_filter(const struct option *option,
 				const char *optarg, int unset)
 {
diff --git a/diff.h b/diff.h
index 03c6afda22..f88482705c 100644
--- a/diff.h
+++ b/diff.h
@@ -233,6 +233,8 @@ struct diff_options {
 	struct option *parseopts;
 };
 
+unsigned diff_filter_bit(char status);
+
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
 void diff_emit_submodule_add(struct diff_options *o, const char *line);
 void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
-- 
2.20.0.482.g66447595a7


^ permalink raw reply related	[flat|nested] 88+ messages in thread

* Re: [PATCH 00/76] Convert diff opt parser to parse_options()
  2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
                   ` (75 preceding siblings ...)
  2019-01-17 13:06 ` [PATCH 76/76] am: avoid diff_opt_parse() Nguyễn Thái Ngọc Duy
@ 2019-01-17 14:32 ` Ævar Arnfjörð Bjarmason
  2019-01-17 19:50   ` Stefan Beller
  76 siblings, 1 reply; 88+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-01-17 14:32 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git


On Thu, Jan 17 2019, Nguyễn Thái Ngọc Duy wrote:

> This series converts diff option parsing to using parse-options. There
> are a couple benefits of using parse-options, including "git <cmd> -h"
> output, completion and less duplicate work.
>
> This is the first half. The second one would be converting the option
> parser in revision.c.  After that, the end game is, any command can
> take a 'struct option[]' somewhere from diff/rev code, remove the
> options they are not interested, then merge with their own options and
> do parse_options() just once. There will be no separate parse phase
> for revision/diff anymore.
>
> I sent a sneak peek [1] last year and got two good comments. I take it
> people at least did not oppose to this. The most interesting parts are
> at the top and bottom. The middle is just boring conversion, usually
> one option per patch.

I'm very much for this, and have skimmed it (but not stress tested) and
it looks good to me. I have some WIP patches to --abbrev that conflict,
but which will be simpler as a result of this.

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination
  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
  0 siblings, 0 replies; 88+ messages in thread
From: Stefan Beller @ 2019-01-17 18:33 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, René Scharfe; +Cc: git

On Thu, Jan 17, 2019 at 5:06 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>
> These two are orthogonal. One is about unknown _option_ while the
> other non-option.

Though 0d260f9a09 ("parseopt: prevent KEEP_UNKNOWN and
STOP_AT_NON_OPTION from being used together", 2009-03-09)
seemed convincing to have this?

Maybe we only need this BUG in case of !PARSE_OPT_ONE_SHOT?

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  parse-options.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index eb5de0da29..678b263897 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -427,9 +427,6 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
>         ctx->prefix = prefix;
>         ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
>         ctx->flags = flags;
> -       if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
> -           (flags & PARSE_OPT_STOP_AT_NON_OPTION))
> -               BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
>         if ((flags & PARSE_OPT_ONE_SHOT) &&
>             (flags & PARSE_OPT_KEEP_ARGV0))
>                 BUG("Can't keep argv0 if you don't have it");
> --
> 2.20.0.482.g66447595a7
>

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()
  2019-01-17 13:06 ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
@ 2019-01-17 19:46   ` Stefan Beller
  2019-01-18  9:30     ` Duy Nguyen
  0 siblings, 1 reply; 88+ messages in thread
From: Stefan Beller @ 2019-01-17 19:46 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Thu, Jan 17, 2019 at 5:12 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>
> 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,

Cool. I like the series up to here.

I skipped most of the conversion
patches, but looked at some and they seem to be very regularly
constructed, as a later step we might want to move all the diff parsing
out of diff.c into diff-options.{c,h,} or such.

> and we get a
> looong 'git range-diff -h'

This is an interesting tidbit to put into the commit message.

range-diff is interesting in that in it is unclear where the options
should take effect. My mental model of range-diff is

    diff --inner-options-1 <range1> >tmp1
    diff --inner-options-2 <range2> >tmp2
    diff --outer-options tmp 1 tmp2

and for most operations we would want to have the inner
options to be the same. However there are cases of changing
one of the inner options, example at
https://public-inbox.org/git/20180810001010.58870-1-sbeller@google.com/

But even when we assume this to be a corner case for
weird research of our own options, it is unclear to me
if the options should apply to the inner diffs or to the
outer diff or both.

As far as I read the patch, the options are applied to both
inner and outer, which may be ok?

I would think that sometimes you want to control only the
inner options, e.g. file copy/rename/move detection
thresholds. And sometimes you want to control the outer
options only (white space error highlighting?)

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 00/76] Convert diff opt parser to parse_options()
  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
  0 siblings, 0 replies; 88+ messages in thread
From: Stefan Beller @ 2019-01-17 19:50 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Nguyễn Thái Ngọc Duy, git

On Thu, Jan 17, 2019 at 6:33 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:

> > I sent a sneak peek [1] last year and got two good comments. I take it
> > people at least did not oppose to this. The most interesting parts are
> > at the top and bottom. The middle is just boring conversion, usually
> > one option per patch.
>
> I'm very much for this, and have skimmed it (but not stress tested) and
> it looks good to me. I have some WIP patches to --abbrev that conflict,
> but which will be simpler as a result of this.

I like the series a lot.

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 76/76] am: avoid diff_opt_parse()
  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
  0 siblings, 1 reply; 88+ messages in thread
From: Johannes Schindelin @ 2019-01-17 20:10 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 3340 bytes --]

Hi Duy,

the change itself looks good, but...

On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:

> diff_opt_parse() is a heavy hammer to just set diff filter. But it's
> the only way because of the diff_status_letters[] mapping. Add a new
> API to set diff filter and use it in git-am. diff_opt_parse()'s only
> remaining call site in revision.c will be gone soon and having it here

... "will be gone soon"? Does that mean that you mail-bomb another mega
patch series iteration once you did that, now sending 77 or 78 patches?

I don't know about others, but I can only afford to spend a fraction of my
waking hours on reviews, and even back when Christian sent the built-in am
as a loooong patch series it was *already* a big problem. Thankfully he
seems to have decided to never do that again.

It would probably make sense to break your 76-strong patch series down
into at least four separate patch series, they would still be as long as
my Azure Pipelines one (which is longer than I am actually comfortable
with, but in my case, it was necessary, while your patch series consists
of many, mostly independent patches that could even be wrapped into
individual patch series of 1 or 2). It's just way too much to review if
you present it in the current manner.

Ciao,
Johannes

> just because of git-am does not make sense.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/am.c | 4 ++--
>  diff.c       | 6 ++++++
>  diff.h       | 2 ++
>  3 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/am.c b/builtin/am.c
> index 95370313b6..0cbf285459 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
>  		 * review them with extra care to spot mismerges.
>  		 */
>  		struct rev_info rev_info;
> -		const char *diff_filter_str = "--diff-filter=AM";
>  
>  		repo_init_revisions(the_repository, &rev_info, NULL);
>  		rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
> -		diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
> +		rev_info.diffopt.filter |= diff_filter_bit('A');
> +		rev_info.diffopt.filter |= diff_filter_bit('M');
>  		add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
>  		diff_setup_done(&rev_info.diffopt);
>  		run_diff_index(&rev_info, 1);
> diff --git a/diff.c b/diff.c
> index daccc8226f..b8e58e817b 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4756,6 +4756,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)
>  	return opt->filter & filter_bit[(int) status];
>  }
>  
> +unsigned diff_filter_bit(char status)
> +{
> +	prepare_filter_bits();
> +	return filter_bit[(int) status];
> +}
> +
>  static int diff_opt_diff_filter(const struct option *option,
>  				const char *optarg, int unset)
>  {
> diff --git a/diff.h b/diff.h
> index 03c6afda22..f88482705c 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -233,6 +233,8 @@ struct diff_options {
>  	struct option *parseopts;
>  };
>  
> +unsigned diff_filter_bit(char status);
> +
>  void diff_emit_submodule_del(struct diff_options *o, const char *line);
>  void diff_emit_submodule_add(struct diff_options *o, const char *line);
>  void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
> -- 
> 2.20.0.482.g66447595a7
> 
> 

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 76/76] am: avoid diff_opt_parse()
  2019-01-17 20:10   ` Johannes Schindelin
@ 2019-01-18  0:19     ` Duy Nguyen
  0 siblings, 0 replies; 88+ messages in thread
From: Duy Nguyen @ 2019-01-18  0:19 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List

On Fri, Jan 18, 2019 at 3:10 AM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi Duy,
>
> the change itself looks good, but...
>
> On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:
>
> > diff_opt_parse() is a heavy hammer to just set diff filter. But it's
> > the only way because of the diff_status_letters[] mapping. Add a new
> > API to set diff filter and use it in git-am. diff_opt_parse()'s only
> > remaining call site in revision.c will be gone soon and having it here
>
> ... "will be gone soon"? Does that mean that you mail-bomb another mega
> patch series iteration once you did that, now sending 77 or 78 patches?

That's another 75 patches.

> I don't know about others, but I can only afford to spend a fraction of my
> waking hours on reviews, and even back when Christian sent the built-in am
> as a loooong patch series it was *already* a big problem. Thankfully he
> seems to have decided to never do that again.
>
> It would probably make sense to break your 76-strong patch series down
> into at least four separate patch series, they would still be as long as
> my Azure Pipelines one (which is longer than I am actually comfortable
> with, but in my case, it was necessary, while your patch series consists
> of many, mostly independent patches that could even be wrapped into
> individual patch series of 1 or 2). It's just way too much to review if
> you present it in the current manner.

Sorry somehow I forgot about breaking down the series. Part of the
reason though was I wanted to show that we got somewhere in the end,
it's not just random restructuring patches that may end up getting
reverted.

If there are lots of changes in this series, I'll resend in smaller
series. For the revision.c conversion I'll make sure to send in small
series.

> Ciao,
> Johannes
>


-- 
Duy

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()
  2019-01-17 19:46   ` Stefan Beller
@ 2019-01-18  9:30     ` Duy Nguyen
  0 siblings, 0 replies; 88+ messages in thread
From: Duy Nguyen @ 2019-01-18  9:30 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

nOn Fri, Jan 18, 2019 at 2:46 AM Stefan Beller <sbeller@google.com> wrote:
> > and we get a
> > looong 'git range-diff -h'
>
> This is an interesting tidbit to put into the commit message.
>
> range-diff is interesting in that in it is unclear where the options
> should take effect. My mental model of range-diff is
>
>     diff --inner-options-1 <range1> >tmp1
>     diff --inner-options-2 <range2> >tmp2
>     diff --outer-options tmp 1 tmp2

This outer/inner refer to the first and second +/- column in
range-diff output, right?

> and for most operations we would want to have the inner
> options to be the same. However there are cases of changing
> one of the inner options, example at
> https://public-inbox.org/git/20180810001010.58870-1-sbeller@google.com/
>
> But even when we assume this to be a corner case for
> weird research of our own options, it is unclear to me
> if the options should apply to the inner diffs or to the
> outer diff or both.
>
> As far as I read the patch, the options are applied to both
> inner and outer, which may be ok?

As far as I can tell, I'm not changing the behavior of this command.
Whatever options accepted before are accepted now. I'm simply exposing
the problem. So no I don't know if it's really ok.

This is not restricted to range-diff either. "git diff" uses
revision.c parser which accepts a whole lot of options that only make
sense with "git log" and friends. Even the "log-tree" command family
has separate set of options for each command, see the "ifdef" in
rev-list-options.txt.

That, I think, would be the next step. To somehow filter options by
command, remove unused ones. Frankly I only have a vague idea how to
do it now ('struct option[]' manipulation).


>
> I would think that sometimes you want to control only the
> inner options, e.g. file copy/rename/move detection
> thresholds. And sometimes you want to control the outer
> options only (white space error highlighting?)



--
Duy

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 70/76] diff.c: convert --inter-hunk-context
  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
  0 siblings, 0 replies; 88+ messages in thread
From: SZEDER Gábor @ 2019-01-19  1:18 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Thu, Jan 17, 2019 at 08:06:09PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  diff.c          | 6 +++---
>  parse-options.h | 3 ++-
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/diff.c b/diff.c
> index 3e7c36524d..cc10b27df0 100644
> --- a/diff.c
> +++ b/diff.c

> @@ -5503,9 +5506,6 @@ int diff_opt_parse(struct diff_options *options,
>  	}
>  
>  	/* misc options */
> -	else if (opt_arg(arg, '\0', "inter-hunk-context",
> -			 &options->interhunkcontext))
> -		;

This hunk removes the last remaining callsite of the static opt_arg()
function:

  diff.c:4581:12: error: ‘opt_arg’ defined but not used [-Werror=unused-function]
   static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
              ^
  cc1: all warnings being treated as errors


>  	else
>  		return 0;
>  	return 1;

^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 25/76] diff.c: convert --stat*
  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
  0 siblings, 0 replies; 88+ messages in thread
From: SZEDER Gábor @ 2019-01-19  1:21 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Thu, Jan 17, 2019 at 08:05:24PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  diff.c | 113 ++++++++++++++++++++++++++-------------------------------
>  1 file changed, 52 insertions(+), 61 deletions(-)
> 
> diff --git a/diff.c b/diff.c
> index 4398b30f47..1b01b36507 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4660,77 +4660,56 @@ int parse_long_opt(const char *opt, const char **argv,
>  	return 2;
>  }
>  
> -static int stat_opt(struct diff_options *options, const char **av)
> +static int diff_opt_stat(const struct option *opt, const char *value, int unset)
>  {
> -	const char *arg = av[0];
> -	char *end;
> +	struct diff_options *options = opt->value;
>  	int width = options->stat_width;
>  	int name_width = options->stat_name_width;
>  	int graph_width = options->stat_graph_width;
>  	int count = options->stat_count;
> -	int argcount = 1;
> +	char *end;
>  
> -	if (!skip_prefix(arg, "--stat", &arg))
> -		BUG("stat option does not begin with --stat: %s", arg);
> -	end = (char *)arg;
> +	BUG_ON_OPT_NEG(unset);
>  
> -	switch (*arg) {
> -	case '-':
> -		if (skip_prefix(arg, "-width", &arg)) {
> -			if (*arg == '=')
> -				width = strtoul(arg + 1, &end, 10);
> -			else if (!*arg && !av[1])
> -				die_want_option("--stat-width");
> -			else if (!*arg) {
> -				width = strtoul(av[1], &end, 10);
> -				argcount = 2;
> -			}
> -		} else if (skip_prefix(arg, "-name-width", &arg)) {
> -			if (*arg == '=')
> -				name_width = strtoul(arg + 1, &end, 10);
> -			else if (!*arg && !av[1])
> -				die_want_option("--stat-name-width");
> -			else if (!*arg) {
> -				name_width = strtoul(av[1], &end, 10);
> -				argcount = 2;
> -			}
> -		} else if (skip_prefix(arg, "-graph-width", &arg)) {
> -			if (*arg == '=')
> -				graph_width = strtoul(arg + 1, &end, 10);
> -			else if (!*arg && !av[1])
> -				die_want_option("--stat-graph-width");
> -			else if (!*arg) {
> -				graph_width = strtoul(av[1], &end, 10);
> -				argcount = 2;
> -			}
> -		} else if (skip_prefix(arg, "-count", &arg)) {
> -			if (*arg == '=')
> -				count = strtoul(arg + 1, &end, 10);
> -			else if (!*arg && !av[1])
> -				die_want_option("--stat-count");
> -			else if (!*arg) {
> -				count = strtoul(av[1], &end, 10);
> -				argcount = 2;
> -			}

This hunk removes the last couple of callsites of the static
die_want_option() function, and building this commit fails with:

  diff.c:107:22: error: ‘die_want_option’ defined but not used [-Werror=unused-function]
   static NORETURN void die_want_option(const char *option_name)
                        ^~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors




^ permalink raw reply	[flat|nested] 88+ messages in thread

* Re: [PATCH 28/76] diff.c: convert -B|--break-rewrites
  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
  0 siblings, 0 replies; 88+ messages in thread
From: Johannes Schindelin @ 2019-01-21 12:07 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 4654 bytes --]

Hi Duy,

On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:

> +static int diff_opt_break_rewrites(const struct option *opt,
> +				   const char *arg, int unset)
> +{
> +	int *break_opt = opt->value;
> +	int opt1, opt2;
> +
> +	BUG_ON_OPT_NEG(unset);
> +	if (!arg)
> +		arg = "";
> +	opt1 = parse_rename_score(&arg);
> +	switch (*arg) {
> +	case '\0':
> +		opt2 = 0;
> +		break;
> +	case '/':
> +		arg++;
> +		opt2 = parse_rename_score(&arg);
> +		break;
> +	}

This code snippet is anywhere in the spectrum between smart, cute, clever,
hard to reason about, and difficult to validate. Granted, Git for Windows
SDK's GCC v7.3.0 seems to be able to figure out (somehow...) that this
does not leave `opt2` uninitialized. But Ubuntu 16.04's default GCC
version (which I believe is v5.3.1) is not.

And likewise, human readers have to spend way too much time thinking about
this. So I would strongly suggest to save everybody and their compiler
some time by squashing this in:

-- snip --
t a/diff.c b/diff.c
index 381259e987a5..855e6ddcb2b9 100644
--- a/diff.c
+++ b/diff.c
@@ -4949,16 +4949,13 @@ static int diff_opt_break_rewrites(const struct option *opt,
 				   const char *arg, int unset)
 {
 	int *break_opt = opt->value;
-	int opt1, opt2;
+	int opt1, opt2 = 0;
 
 	BUG_ON_OPT_NEG(unset);
 	if (!arg)
 		arg = "";
 	opt1 = parse_rename_score(&arg);
 	switch (*arg) {
-	case '\0':
-		opt2 = 0;
-		break;
 	case '/':
 		arg++;
 		opt2 = parse_rename_score(&arg);
-- snap --

Not only is the result a lot easier to understand and to reason about, it also
saves 3 lines.

Ciao,
Johannes

P.S.: Please do not send the entire 78 "re-rolled" patches my way, should
you choose to send another iteration of this unsplit patch series, but
just this one. TIA

> +	if (*arg != 0)
> +		return error(_("%s expects <n>/<m> form"), opt->long_name);
> +	*break_opt = opt1 | (opt2 << 16);
> +	return 0;
> +}
> +
>  static int diff_opt_char(const struct option *opt,
>  			 const char *arg, int unset)
>  {
> @@ -5014,6 +5039,12 @@ static void prep_parse_options(struct diff_options *options)
>  			       N_("specify the character to indicate a context instead of ' '"),
>  			       PARSE_OPT_NONEG, diff_opt_char),
>  
> +		OPT_GROUP(N_("Diff rename options")),
> +		OPT_CALLBACK_F('B', "break-rewrites", &options->break_opt, N_("<n>[/<m>]"),
> +			       N_("break complete rewrite changes into pairs of delete and create"),
> +			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
> +			       diff_opt_break_rewrites),
> +
>  		OPT_GROUP(N_("Diff other options")),
>  		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
>  		  N_("Output to a specific file"),
> @@ -5047,12 +5078,7 @@ int diff_opt_parse(struct diff_options *options,
>  		return ac;
>  
>  	/* renames options */
> -	if (starts_with(arg, "-B") ||
> -		 skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
> -		if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
> -			return error("invalid argument to -B: %s", arg+2);
> -	}
> -	else if (starts_with(arg, "-M") ||
> +	if (starts_with(arg, "-M") ||
>  		 skip_to_optional_arg(arg, "--find-renames", NULL)) {
>  		if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
>  			return error("invalid argument to -M: %s", arg+2);
> @@ -5331,17 +5357,14 @@ int parse_rename_score(const char **cp_p)
>  
>  static int diff_scoreopt_parse(const char *opt)
>  {
> -	int opt1, opt2, cmd;
> +	int opt1, cmd;
>  
>  	if (*opt++ != '-')
>  		return -1;
>  	cmd = *opt++;
>  	if (cmd == '-') {
>  		/* convert the long-form arguments into short-form versions */
> -		if (skip_prefix(opt, "break-rewrites", &opt)) {
> -			if (*opt == 0 || *opt++ == '=')
> -				cmd = 'B';
> -		} else if (skip_prefix(opt, "find-copies", &opt)) {
> +		if (skip_prefix(opt, "find-copies", &opt)) {
>  			if (*opt == 0 || *opt++ == '=')
>  				cmd = 'C';
>  		} else if (skip_prefix(opt, "find-renames", &opt)) {
> @@ -5349,25 +5372,13 @@ static int diff_scoreopt_parse(const char *opt)
>  				cmd = 'M';
>  		}
>  	}
> -	if (cmd != 'M' && cmd != 'C' && cmd != 'B')
> -		return -1; /* that is not a -M, -C, or -B option */
> +	if (cmd != 'M' && cmd != 'C')
> +		return -1; /* that is not a -M, or -C option */
>  
>  	opt1 = parse_rename_score(&opt);
> -	if (cmd != 'B')
> -		opt2 = 0;
> -	else {
> -		if (*opt == 0)
> -			opt2 = 0;
> -		else if (*opt != '/')
> -			return -1; /* we expect -B80/99 or -B80 */
> -		else {
> -			opt++;
> -			opt2 = parse_rename_score(&opt);
> -		}
> -	}
>  	if (*opt != 0)
>  		return -1;
> -	return opt1 | (opt2 << 16);
> +	return opt1;
>  }
>  
>  struct diff_queue_struct diff_queued_diff;
> -- 
> 2.20.0.482.g66447595a7
> 
> 
> 

^ permalink raw reply related	[flat|nested] 88+ messages in thread

* Re: [PATCH 63/76] diff.c: convert -O
  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
  0 siblings, 0 replies; 88+ messages in thread
From: Johannes Schindelin @ 2019-01-21 12:14 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2343 bytes --]

Hi Duy,

On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:

> diff --git a/diff.c b/diff.c
> index ae993f5551..4e004a2195 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -5401,6 +5401,8 @@ static void prep_parse_options(struct diff_options *options)
>  		OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
>  			  N_("treat <string> in -S as extended POSIX regular expression"),
>  			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
> +		OPT_FILENAME('O', NULL, &options->orderfile,
> +			     N_("override diff.orderFile configuration variable")),
>  		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
>  		  N_("Output to a specific file"),
>  		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
> @@ -5453,10 +5455,7 @@ int diff_opt_parse(struct diff_options *options,
>  	}
>  
>  	/* misc options */
> -	else if ((argcount = short_opt('O', av, &optarg))) {
> -		options->orderfile = prefix_filename(prefix, optarg);
> -		return argcount;
> -	} else if (skip_prefix(arg, "--find-object=", &arg))
> +	else if (skip_prefix(arg, "--find-object=", &arg))

You probably used GCC and therefore missed that this patch removes the
last user of `short_opt()`, and therefore leaves `short_opt()` unused.
Apparently Clang v9.1.0 (which is used in Azure Pipelines' macOS builds)
is smart enough to notice that, though. So please squash this in when you
send another iteration of this patch (in a hopefully smaller package than
that six-and-a-half-dozen patch series):

-- snip --
diff --git a/diff.c b/diff.c
index 381259e987a5..5e1ab7daec44 100644
--- a/diff.c
+++ b/diff.c
@@ -4692,22 +4692,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
 }
 #endif
 
-static inline int short_opt(char opt, const char **argv,
-			    const char **optarg)
-{
-	const char *arg = argv[0];
-	if (arg[0] != '-' || arg[1] != opt)
-		return 0;
-	if (arg[2] != '\0') {
-		*optarg = arg + 2;
-		return 1;
-	}
-	if (!argv[1])
-		die("Option '%c' requires a value", opt);
-	*optarg = argv[1];
-	return 2;
-}
-
 int parse_long_opt(const char *opt, const char **argv,
 		   const char **optarg)
 {
-- snap --

Ciao,
Johannes

>  		return parse_objfind_opt(options, arg);
>  	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
>  		int offending = parse_diff_filter_opt(optarg, options);
> -- 
> 2.20.0.482.g66447595a7
> 
> 
> 

^ permalink raw reply related	[flat|nested] 88+ messages in thread

end of thread, other threads:[~2019-01-21 12:14 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
2019-01-17 19:46   ` 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

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).