Convert diff opt parser to parse_options()
cover Convert diff opt parser to parse_options()
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/[email protected]/
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(-)
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 1/76 parse-options.h: remove extern on function prototypes
--- parse-options.h | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
parse-options.h +29 -29
@@ -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))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 2/76 parse-options: add one-shot mode
In reply to Nguyễn Thái Ngọc DuyThis 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.
--- parse-options.c | 23 ++++++++++++++++++++--- parse-options.h | 17 +++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-)
parse-options.c +20 -3
@@ -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;
parse-options.h +13 -4
@@ -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,
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 3/76 parse-options: allow keep-unknown + stop-at-non-opt combination
In reply to Nguyễn Thái Ngọc DuyThese two are orthogonal. One is about unknown _option_ while the other non-option.
--- parse-options.c | 3 --- 1 file changed, 3 deletions(-)
parse-options.c +0 -3
@@ -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" );
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination
Quoted 3 lines · Nguyễn Thái Ngọc Duy
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?
Quoted 22 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- parse-options.c | 3 --- 1 file changed, 3 deletions(-)parse-options.c +0
-4@@ -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
PATCH 4/76 parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
In reply to Nguyễn Thái Ngọc Duyparse-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.
--- parse-options.c | 3 ++- t/t7800-difftool.sh | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
parse-options.c +2 -1
@@ -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) {/*
t/t7800-difftool.sh +2 -2
@@ -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 '
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 5/76 parse-options: add OPT_BITOP()
In reply to Nguyễn Thái Ngọc DuyThis is needed for diff_opt_parse() where we do
value = (value & ~mask) | some_more;
--- parse-options.c | 7 +++++++ parse-options.h | 5 +++++ 2 files changed, 12 insertions(+)
parse-options.c +7 -0
@@ -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 ;
parse-options.h +5 -0
@@ -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)
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 6/76 parse-options: stop abusing 'callback' for lowlevel callbacks
In reply to Nguyễn Thái Ngọc DuyLowlevel callbacks have different function signatures. Add a new field in 'struct option' with the right type for lowlevel callbacks.
--- 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(-)
builtin/blame.c +1 -1
@@ -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")),
builtin/merge.c +1 -1
@@ -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")),
builtin/update-index.c +6 -5
@@ -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),
parse-options-cb.c +2 -1
@@ -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 ; }
parse-options.c +14 -1
@@ -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) */ }
parse-options.h +8 -4
@@ -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 );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 7/76 parse-options: avoid magic return codes
In reply to Nguyễn Thái Ngọc DuyGive 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).
--- 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(-)
builtin/merge.c +3 -2
@@ -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;
builtin/update-index.c +10 -10
@@ -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;
parse-options-cb.c +3 -3
@@ -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 ; }/**
parse-options.c +45 -24
154 lines not on this page · raw message
parse-options.h +7 -7
@@ -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 };
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 8/76 parse-options: allow ll_callback with OPTION_CALLBACK
In reply to Nguyễn Thái Ngọc DuyOPTION_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.
--- 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(-)
builtin/merge.c +2 -0
@@ -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" );
builtin/update-index.c +15 -5
@@ -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 ();
parse-options-cb.c +3 -1
@@ -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 ; }
parse-options.c +28 -14
68 lines not on this page · raw message
parse-options.h +3 -2
@@ -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 );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 9/76 diff.h: keep forward struct declarations sorted
In reply to Nguyễn Thái Ngọc Duy--- diff.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff.h +6 -6
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 10/76 diff.h: avoid bit fields in struct diff_flags
In reply to Nguyễn Thái Ngọc DuyBitfield 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.
--- diff.h | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-)
diff.h +33 -33
@@ -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,
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 11/76 diff.c: prepare to use parse_options() for parsing
In reply to Nguyễn Thái Ngọc DuyThis 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.
--- diff.c | 27 +++++++++++++++++++++++++++ diff.h | 2 ++ 2 files changed, 29 insertions(+)
diff.c +27 -0
@@ -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.h +2 -0
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 12/76 diff.c: convert -u|-p|--patch
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff.c +8 -2
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 13/76 diff.c: convert -U|--unified
In reply to Nguyễn Thái Ngọc Duy--- Documentation/diff-options.txt | 2 +- diff.c | 23 ++++++++++++++++++++--- parse-options.h | 5 +++-- 3 files changed, 24 insertions(+), 6 deletions(-)
Documentation/diff-options.txt +1 -1
@@ -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.c +20 -3
@@ -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);
parse-options.h +3 -2
@@ -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) }
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 14/76 diff.c: convert -W|--[no-]function-context
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff.c +2 -6
@@ -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" );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 15/76 diff.c: convert --raw
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 16/76 diff.c: convert --patch-with-raw
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff.c +5 -4
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 17/76 diff.c: convert --numstat and --shortstat
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff.c +7 -5
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 18/76 diff.c: convert --dirstat and friends
In reply to Nguyễn Thái Ngọc Duy--- Documentation/diff-options.txt | 7 ++++++ diff.c | 39 +++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-)
Documentation/diff-options.txt +7 -0
@@ -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.c +29 -10
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 19/76 diff.c: convert --check
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 20/76 diff.c: convert --summary
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 21/76 diff.c: convert --patch-with-stat
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff.c +5 -4
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 22/76 diff.c: convert --name-only
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 23/76 diff.c: convert --name-status
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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 */
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 24/76 diff.c: convert -s|--no-patch
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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" )) {
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 25/76 diff.c: convert --stat*
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 113 ++++++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 61 deletions(-)
diff.c +52 -61
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 25/76] diff.c: convert --stat*
Quoted 59 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- diff.c | 113 ++++++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 61 deletions(-)diff.c +4
-35@@ -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 ;
diff.c int parse_long_opt(const char *opt, const char **argv, · line 4714
Quoted 10 lines
diff.c +0
-10- } - }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
PATCH 26/76 diff.c: convert --[no-]compact-summary
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
diff.c +19 -6
@@ -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 ];
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 27/76 diff.c: convert --output-*
In reply to Nguyễn Thái Ngọc DuyThis also validates that the user specifies a single character in --output-indicator-*, not a string.
--- Documentation/diff-options.txt | 10 +++++ diff.c | 71 +++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 18 deletions(-)
Documentation/diff-options.txt +10 -0
@@ -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.c +53 -18
102 lines not on this page · raw message
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 28/76 diff.c: convert -B|--break-rewrites
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 63 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 26 deletions(-)
diff.c +37 -26
@@ -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;
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 28/76] diff.c: convert -B|--break-rewrites
Hi Duy,
Quoted 9 lines · Nguyễn Thái Ngọc Duy
(quoted diff) +9
-0+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 = "";
Review
Quoted 10 lines
(quoted diff) +10
-0+ 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
diff.c +1 -4
@@ -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
Quoted 90 lines
(quoted diff) +18
-26+ 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;Signature · 1 line
2.20.0.482.g66447595a7
PATCH 29/76 diff.c: convert -M|--find-renames
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
diff.c +23 -12
@@ -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 )
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 30/76 diff.c: convert -D|--irreversible-delete
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff.c +4 -4
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 31/76 diff.c: convert -C|--find-copies
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 59 +++++++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 34 deletions(-)
diff.c +25 -34
@@ -4621,8 +4621,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *vareturn 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)
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 32/76 diff.c: convert --find-copies-harder
In reply to 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)
--- diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff.c +2 -2
@@ -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")) {
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 33/76 diff.c: convert --no-renames|--[no--rename-empty
In reply to Nguyễn Thái Ngọc DuyFor --rename-empty, see 90d43b0768 (teach diffcore-rename to optionally ignore empty content - 2012-03-22) for more information.
--- Documentation/diff-options.txt | 3 +++ diff.c | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-)
Documentation/diff-options.txt +3 -0
@@ -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.c +6 -7
@@ -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;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 34/76 diff.c: convert --relative
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
diff.c +17 -8
@@ -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 );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 35/76 diff.c: convert --[no-]minimal
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
diff.c +6 -5
@@ -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 );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 36/76 diff.c: convert --ignore-some-changes
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
diff.c +16 -11
@@ -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 );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 37/76 diff.c: convert --[no-]indent-heuristic
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff.c +4 -5
@@ -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 );/*
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 38/76 diff.c: convert --patience
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
diff.c +25 -12
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 39/76 diff.c: convert --histogram
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff.c +4 -3
@@ -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\", "
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 40/76 diff.c: convert --diff-algorithm
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
diff.c +22 -11
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 41/76 diff.c: convert --anchored
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
diff.c +17 -9
@@ -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 ; }
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 42/76 diff.c: convert --binary
In reply to Nguyễn Thái Ngọc Duy--- Documentation/diff-options.txt | 2 +- diff.c | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-)
Documentation/diff-options.txt +1 -1
@@ -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.c +16 -5
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 43/76 diff.c: convert --full-index
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff.c +3 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 44/76 diff.c: convert -a|--text
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff.c +3 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 45/76 diff.c: convert -R
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff.c +3 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 46/76 diff.c: convert --[no-]follow
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
diff.c +19 -6
@@ -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\"" );
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 47/76 diff.c: convert --[no-]color
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
diff.c +3 -9
@@ -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 )
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 48/76 diff.c: convert --word-diff
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-)
diff.c +29 -18
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 49/76 diff.c: convert --word-diff-regex
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
diff.c +15 -6
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 50/76 diff.c: convert --color-words
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff.c +16 -5
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 51/76 diff.c: convert --exit-code
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff.c +3 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 52/76 diff.c: convert --quiet
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff.c +3 -3
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 53/76 diff.c: convert --ext-diff
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff.c +3 -5
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 54/76 diff.c: convert --textconv
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
diff.c +19 -6
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 55/76 diff.c: convert --ignore-submodules
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff.c +17 -3
@@ -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))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 56/76 diff.c: convert --submodule
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
diff.c +19 -11
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 57/76 diff.c: convert --ws-error-highlight
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
diff.c +12 -10
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 58/76 diff.c: convert --ita-[in]visible-in-index
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff.c +7 -4
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 59/76 diff.c: convert -z
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff.c +3 -2
@@ -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;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 60/76 diff.c: convert -l
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff.c +2 -4
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 61/76 diff.c: convert -S|-G
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
diff.c +28 -9
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 62/76 diff.c: convert --pickaxe-all|--pickaxe-regex
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff.c +6 -4
@@ -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;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 63/76 diff.c: convert -O
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff.c +3 -4
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 63/76] diff.c: convert -O
Hi Duy,
Quoted 14 lines · Nguyễn Thái Ngọc Duy
diff.c +2
-0@@ -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 },
diff.c int diff_opt_parse(struct diff_options *options, · line 5458
Quoted 8 lines
diff.c +1
-4@@ -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.c +0 -16
@@ -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
Quoted 8 lines
diff.c +0
-0return parse_objfind_opt (options, arg); else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {int offending =parse_diff_filter_opt (optarg, options);Signature · 1 line
2.20.0.482.g66447595a7
PATCH 64/76 diff.c: convert --find-object
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
diff.c +9 -5
@@ -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)
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 65/76 diff.c: convert --diff-filter
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff.c +9 -9
@@ -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" ))
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 66/76 diff.c: convert --[no-]abbrev
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 12 +----------- parse-options-cb.c | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-)
diff.c +1 -11
@@ -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;
parse-options-cb.c +2 -2
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 67/76 diff.c: convert --[src|dst]-prefix
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 14 ++++++-------- parse-options.h | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-)
diff.c +6 -8
@@ -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",
parse-options.h +2 -1
@@ -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 }
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 68/76 diff.c: convert --line-prefix
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
diff.c +15 -8
@@ -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",
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 69/76 diff.c: convert --no-prefix
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff.c +15 -2
@@ -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)) ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 70/76 diff.c: convert --inter-hunk-context
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 6 +++--- parse-options.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
diff.c +3 -3
@@ -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 ;
parse-options.h +2 -1
@@ -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)
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 70/76] diff.c: convert --inter-hunk-context
Quoted 12 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- diff.c | 6 +++--- parse-options.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)diff.c +0
-0
diff.c int diff_opt_parse(struct diff_options *options, · line 5508
Quoted 6 lines
diff.c +0
-3@@ -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
Quoted 3 lines
diff.c +0
-0else return 0 ;return 1 ;
PATCH 71/76 diff.c: convert --color-moved
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
diff.c +25 -13
@@ -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 ;
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 72/76 diff.c: convert --color-moved-ws
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
diff.c +18 -17
@@ -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)
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 73/76 diff.c: allow --no-color-moved-ws
In reply to Nguyễn Thái Ngọc DuyThis 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.
--- diff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff.c +6 -2
@@ -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>"),
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 74/76 range-diff: use parse_options() instead of diff_opt_parse()
In reply to Nguyễn Thái Ngọc DuyDiff'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'
--- builtin/range-diff.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-)
builtin/range-diff.c +6 -20
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()
Quoted 4 lines · 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,
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.
Quoted 2 lines
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 tmp2and 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/[email protected]/
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?)
Re: [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse()
Quoted 11 lines · Stefan Beller
Quoted 2 lines
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?
Quoted 5 lines
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/[email protected]/
Quoted 7 lines
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).
Quoted 5 lines
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
PATCH 75/76 diff --no-index: use parse_options() instead of diff_opt_parse()
In reply to Nguyễn Thái Ngọc DuyWhile 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
--- 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(-)
builtin/diff.c +3 -18
@@ -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-no-index.c +29 -20
82 lines not on this page · raw message
diff.h +2 -1
@@ -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,
t/t4053-diff-no-index.sh +1 -2
@@ -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 ) '
Signature · 1 line
2.20.0.482.g66447595a7
PATCH 76/76 am: avoid diff_opt_parse()
In reply to Nguyễn Thái Ngọc Duydiff_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.
--- builtin/am.c | 4 ++-- diff.c | 6 ++++++ diff.h | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-)
builtin/am.c +2 -2
@@ -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.c +6 -0
@@ -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.h +2 -0
@@ -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);
Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 76/76] am: avoid diff_opt_parse()
Hi Duy,
the change itself looks good, but...
Quoted 4 lines · 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 inrevision.cwill 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
Quoted 61 lines
just because of git-am does not make sense.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/am.c | 4 ++-- diff.c | 6 ++++++ diff.h | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-)builtin/am.c +2
-2@@ -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.c +6
-0@@ -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.h +2
-0@@ -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);Signature · 1 line
2.20.0.482.g66447595a7
Re: [PATCH 76/76] am: avoid diff_opt_parse()
Quoted 7 lines · Johannes Schindelin
Hi Duy,
the change itself looks good, but...
On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:
Quoted 7 lines
Quoted 4 lines
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 inrevision.cwill 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.
Quoted 5 lines
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.
Quoted 7 lines
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.
Quoted 3 lines
Ciao,
Johannes
Signature · 1 line
Duy
Quoted 11 lines · 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 doparse_options()just once. There will be no separate parse phase for revision/diff anymore.
Quoted 4 lines
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.
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines
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.