Merge branch 'mp/diff-algo-config'
Add diff.algorithm configuration so that the user does not type "diff --histogram". * mp/diff-algo-config: diff: Introduce --diff-algorithm command line option config: Introduce diff.algorithm variable git-completion.bash: Autocomplete --minimal and --histogram for git-diff
This commit is contained in:
34
diff.c
34
diff.c
@ -36,6 +36,7 @@ static int diff_no_prefix;
|
||||
static int diff_stat_graph_width;
|
||||
static int diff_dirstat_permille_default = 30;
|
||||
static struct diff_options default_diff_options;
|
||||
static long diff_algorithm;
|
||||
|
||||
static char diff_colors[][COLOR_MAXLEN] = {
|
||||
GIT_COLOR_RESET,
|
||||
@ -143,6 +144,21 @@ static int git_config_rename(const char *var, const char *value)
|
||||
return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0;
|
||||
}
|
||||
|
||||
long parse_algorithm_value(const char *value)
|
||||
{
|
||||
if (!value)
|
||||
return -1;
|
||||
else if (!strcasecmp(value, "myers") || !strcasecmp(value, "default"))
|
||||
return 0;
|
||||
else if (!strcasecmp(value, "minimal"))
|
||||
return XDF_NEED_MINIMAL;
|
||||
else if (!strcasecmp(value, "patience"))
|
||||
return XDF_PATIENCE_DIFF;
|
||||
else if (!strcasecmp(value, "histogram"))
|
||||
return XDF_HISTOGRAM_DIFF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* These are to give UI layer defaults.
|
||||
* The core-level commands such as git-diff-files should
|
||||
@ -196,6 +212,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(var, "diff.algorithm")) {
|
||||
diff_algorithm = parse_algorithm_value(value);
|
||||
if (diff_algorithm < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (git_color_config(var, value, cb) < 0)
|
||||
return -1;
|
||||
|
||||
@ -3163,6 +3186,7 @@ void diff_setup(struct diff_options *options)
|
||||
options->add_remove = diff_addremove;
|
||||
options->use_color = diff_use_color_default;
|
||||
options->detect_rename = diff_detect_rename_default;
|
||||
options->xdl_opts |= diff_algorithm;
|
||||
|
||||
if (diff_no_prefix) {
|
||||
options->a_prefix = options->b_prefix = "";
|
||||
@ -3560,6 +3584,16 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
||||
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
|
||||
else if (!strcmp(arg, "--histogram"))
|
||||
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
|
||||
else if (!prefixcmp(arg, "--diff-algorithm=")) {
|
||||
long value = parse_algorithm_value(arg+17);
|
||||
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;
|
||||
}
|
||||
|
||||
/* flags options */
|
||||
else if (!strcmp(arg, "--binary")) {
|
||||
|
||||
Reference in New Issue
Block a user