Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:12 +0300
committerJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:12 +0300
commitdcd6a8c09a36a500c4e612a52eba1c6c5e298951 (patch)
tree79ed79645190bf1c49996f2b9aec5e349eb96400
parent4284497396eb52b2c096c2f442b70a52138b6e1b (diff)
parentcdb5330a9baa64c28473fb0f446ca2242d6971fb (diff)
Merge branch 'nd/diff-parseopt-4'
Fourth batch to teach the diff machinery to use the parse-options API. * nd/diff-parseopt-4: am: avoid diff_opt_parse() diff --no-index: use parse_options() instead of diff_opt_parse() range-diff: use parse_options() instead of diff_opt_parse() diff.c: allow --no-color-moved-ws diff-parseopt: convert --color-moved-ws diff-parseopt: convert --[no-]color-moved diff-parseopt: convert --inter-hunk-context diff-parseopt: convert --no-prefix diff-parseopt: convert --line-prefix diff-parseopt: convert --[src|dst]-prefix diff-parseopt: convert --[no-]abbrev diff-parseopt: convert --diff-filter diff-parseopt: convert --find-object diff-parseopt: convert -O diff-parseopt: convert --pickaxe-all|--pickaxe-regex diff-parseopt: convert -S|-G diff-parseopt: convert -l diff-parseopt: convert -z diff-parseopt: convert --ita-[in]visible-in-index diff-parseopt: convert --ws-error-highlight
-rw-r--r--builtin/am.c4
-rw-r--r--builtin/diff.c22
-rw-r--r--builtin/range-diff.c26
-rw-r--r--diff-no-index.c49
-rw-r--r--diff.c339
-rw-r--r--diff.h5
-rw-r--r--parse-options-cb.c4
-rw-r--r--parse-options.h6
-rwxr-xr-xt/t4053-diff-no-index.sh3
9 files changed, 219 insertions, 239 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 4fb107a9d1..3ba5723c2c 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1501,11 +1501,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
* review them with extra care to spot mismerges.
*/
struct rev_info rev_info;
- const char *diff_filter_str = "--diff-filter=AM";
repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
- diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
+ rev_info.diffopt.filter |= diff_filter_bit('A');
+ rev_info.diffopt.filter |= diff_filter_bit('M');
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
diff_setup_done(&rev_info.diffopt);
run_diff_index(&rev_info, 1);
diff --git a/builtin/diff.c b/builtin/diff.c
index 53d4234ff4..42ac803091 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -321,24 +321,6 @@ 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]");
-
- }
-
/* Set up defaults that will apply to both no-index and regular diffs. */
rev.diffopt.stat_width = -1;
rev.diffopt.stat_graph_width = -1;
@@ -347,7 +329,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
/* If this is a no-index diff, just run it and exit there. */
if (no_index)
- diff_no_index(&rev, argc, argv);
+ exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT,
+ argc, argv));
+
/*
* Otherwise, we are doing the usual "git" diff; set up any
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index f01a0be851..784bd19321 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
struct diff_options diffopt = { NULL };
int simple_color = -1;
- struct option options[] = {
+ struct option range_diff_options[] = {
OPT_INTEGER(0, "creation-factor", &creation_factor,
N_("Percentage by which creation is weighted")),
OPT_BOOL(0, "no-dual-color", &simple_color,
N_("use simple diff colors")),
OPT_END()
};
- int i, j, res = 0;
+ struct option *options;
+ int res = 0;
struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
git_config(git_diff_ui_config, NULL);
repo_diff_setup(the_repository, &diffopt);
+ options = parse_options_concat(range_diff_options, diffopt.parseopts);
argc = parse_options(argc, argv, NULL, options,
- builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
- PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
-
- for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
- int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
+ builtin_range_diff_usage, 0);
- if (!c)
- argv[j++] = argv[i++];
- else
- i += c;
- }
- while (i < argc)
- argv[j++] = argv[i++];
- argc = j;
diff_setup_done(&diffopt);
- /* Make sure that there are no unparsed options */
- argc = parse_options(argc, argv, NULL,
- options + ARRAY_SIZE(options) - 1, /* OPT_END */
- builtin_range_diff_usage, 0);
-
/* force color when --dual-color was used */
if (!simple_color)
diffopt.use_color = 1;
@@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
error(_("need two commit ranges"));
usage_with_options(builtin_range_diff_usage, options);
}
+ FREE_AND_NULL(options);
res = show_range_diff(range1.buf, range2.buf, creation_factor,
simple_color < 1, &diffopt);
diff --git a/diff-no-index.c b/diff-no-index.c
index 6001baecd4..7814eabfe0 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -14,6 +14,7 @@
#include "revision.h"
#include "log-tree.h"
#include "builtin.h"
+#include "parse-options.h"
#include "string-list.h"
#include "dir.h"
@@ -233,29 +234,37 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
}
}
-void diff_no_index(struct rev_info *revs,
- int argc, const char **argv)
+static const char * const diff_no_index_usage[] = {
+ N_("git diff --no-index [<options>] <path> <path>"),
+ NULL
+};
+
+int diff_no_index(struct rev_info *revs,
+ int implicit_no_index,
+ int argc, const char **argv)
{
- int i;
+ int i, no_index;
const char *paths[2];
struct strbuf replacement = STRBUF_INIT;
const char *prefix = revs->prefix;
-
- for (i = 1; i < argc - 2; ) {
- int j;
- if (!strcmp(argv[i], "--no-index"))
- i++;
- else if (!strcmp(argv[i], "--"))
- i++;
- else {
- j = diff_opt_parse(&revs->diffopt, argv + i, argc - i,
- revs->prefix);
- if (j <= 0)
- die("invalid diff option/value: %s", argv[i]);
- i += j;
- }
+ struct option no_index_options[] = {
+ OPT_BOOL_F(0, "no-index", &no_index, "",
+ PARSE_OPT_NONEG | PARSE_OPT_HIDDEN),
+ OPT_END(),
+ };
+ struct option *options;
+
+ options = parse_options_concat(no_index_options,
+ revs->diffopt.parseopts);
+ argc = parse_options(argc, argv, revs->prefix, options,
+ diff_no_index_usage, 0);
+ if (argc != 2) {
+ if (implicit_no_index)
+ warning(_("Not a git repository. Use --no-index to "
+ "compare two paths outside a working tree"));
+ usage_with_options(diff_no_index_usage, options);
}
-
+ FREE_AND_NULL(options);
for (i = 0; i < 2; i++) {
const char *p = argv[argc - 2 + i];
if (!strcmp(p, "-"))
@@ -287,7 +296,7 @@ void diff_no_index(struct rev_info *revs,
revs->diffopt.flags.exit_with_status = 1;
if (queue_diff(&revs->diffopt, paths[0], paths[1]))
- exit(1);
+ return 1;
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
diffcore_std(&revs->diffopt);
diff_flush(&revs->diffopt);
@@ -298,5 +307,5 @@ void diff_no_index(struct rev_info *revs,
* The return code for --no-index imitates diff(1):
* 0 = no changes, 1 = changes, else error
*/
- exit(diff_result_code(&revs->diffopt, 0));
+ return diff_result_code(&revs->diffopt, 0);
}
diff --git a/diff.c b/diff.c
index 6dfad79f1d..e30a645d9e 100644
--- a/diff.c
+++ b/diff.c
@@ -4640,66 +4640,6 @@ void diff_setup_done(struct diff_options *options)
FREE_AND_NULL(options->parseopts);
}
-static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
-{
- char c, *eq;
- int len;
-
- if (*arg != '-')
- return 0;
- c = *++arg;
- if (!c)
- return 0;
- if (c == arg_short) {
- c = *++arg;
- if (!c)
- return 1;
- if (val && isdigit(c)) {
- char *end;
- int n = strtoul(arg, &end, 10);
- if (*end)
- return 0;
- *val = n;
- return 1;
- }
- return 0;
- }
- if (c != '-')
- return 0;
- arg++;
- eq = strchrnul(arg, '=');
- len = eq - arg;
- if (!len || strncmp(arg, arg_long, len))
- return 0;
- if (*eq) {
- int n;
- char *end;
- if (!isdigit(*++eq))
- return 0;
- n = strtoul(eq, &end, 10);
- if (*end)
- return 0;
- *val = n;
- }
- return 1;
-}
-
-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)
{
@@ -4819,10 +4759,19 @@ 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)
+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)
+{
+ struct diff_options *opt = option->value;
int i, optch;
+ BUG_ON_OPT_NEG(unset);
prepare_filter_bits();
/*
@@ -4853,7 +4802,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
@@ -4868,25 +4818,29 @@ 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)
+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));
@@ -4895,7 +4849,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,
@@ -4960,6 +4914,45 @@ 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_moved_ws(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct diff_options *options = opt->value;
+ unsigned cm;
+
+ 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);
+ options->color_moved_ws_handling = cm;
+ return 0;
+}
+
static int diff_opt_color_words(const struct option *opt,
const char *arg, int unset)
{
@@ -5085,6 +5078,30 @@ 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 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)
@@ -5122,6 +5139,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)
{
@@ -5301,6 +5340,28 @@ 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 whitespace 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__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, "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_("do 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>"),
@@ -5343,6 +5404,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,
@@ -5388,6 +5451,12 @@ 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_CALLBACK_F(0, "color-moved-ws", options, N_("<mode>"),
+ N_("how white spaces are ignored in --color-moved"),
+ 0, diff_opt_color_moved_ws),
OPT_GROUP(N_("Diff other options")),
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5415,6 +5484,32 @@ 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),
+ 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),
+ 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),
+ OPT_FILENAME('O', NULL, &options->orderfile,
+ N_("control the order in which files appear in the output")),
+ 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 },
@@ -5429,10 +5524,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];
- const char *optarg;
- int argcount;
-
if (!prefix)
prefix = "";
@@ -5443,101 +5534,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 (!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 (!strcmp(arg, "--no-color-moved-ws")) {
- options->color_moved_ws_handling = 0;
- } else 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;
- } 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;
- else if (!strcmp(arg, "--ita-visible-in-index"))
- options->ita_invisible_in_index = 0;
-
- /* 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;
- }
- 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"))
- options->pickaxe_opts |= DIFF_PICKAXE_REGEX;
- else if ((argcount = short_opt('O', av, &optarg))) {
- options->orderfile = prefix_filename(prefix, optarg);
- return argcount;
- } 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)
- 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"))
- 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;
- }
- 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",
- &options->interhunkcontext))
- ;
- else
- return 0;
- return 1;
+ return ac;
}
int parse_rename_score(const char **cp_p)
diff --git a/diff.h b/diff.h
index c9db9825bb..b20cbcc091 100644
--- a/diff.h
+++ b/diff.h
@@ -233,6 +233,8 @@ struct diff_options {
struct option *parseopts;
};
+unsigned diff_filter_bit(char status);
+
void diff_emit_submodule_del(struct diff_options *o, const char *line);
void diff_emit_submodule_add(struct diff_options *o, const char *line);
void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
@@ -438,7 +440,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 rev_info *, int, const char **);
+int diff_no_index(struct rev_info *,
+ int implicit_no_index, int, const char **);
int index_differs_from(struct repository *r, const char *def,
const struct diff_flags *flags,
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 2733393546..6e2e8d6273 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -22,8 +22,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
opt->long_name);
if (v && v < MINIMUM_ABBREV)
v = MINIMUM_ABBREV;
- else if (v > 40)
- v = 40;
+ else if (v > the_hash_algo->hexsz)
+ v = the_hash_algo->hexsz;
}
*(int *)(opt->value) = v;
return 0;
diff --git a/parse-options.h b/parse-options.h
index 74cce4e7fc..0f73787066 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -136,6 +136,8 @@ 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_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, \
@@ -154,10 +156,10 @@ 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) { 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 }
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 4331b3118a..0168946b63 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -50,8 +50,7 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err
export GIT_CEILING_DIRECTORIES &&
cd non/git &&
test_must_fail git diff --no-index a 2>actual.err &&
- echo "usage: git diff --no-index <path> <path>" >expect.err &&
- test_cmp expect.err actual.err
+ test_i18ngrep "usage: git diff --no-index" actual.err
)
'