提交 abea4dc7 编写于 作者: J Junio C Hamano

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
...@@ -156,3 +156,20 @@ diff.tool:: ...@@ -156,3 +156,20 @@ diff.tool::
that a corresponding difftool.<tool>.cmd variable is defined. that a corresponding difftool.<tool>.cmd variable is defined.
include::mergetools-diff.txt[] include::mergetools-diff.txt[]
diff.algorithm::
Choose a diff algorithm. The variants are as follows:
+
--
`default`, `myers`;;
The basic greedy diff algorithm. Currently, this is the default.
`minimal`;;
Spend extra time to make sure the smallest possible diff is
produced.
`patience`;;
Use "patience diff" algorithm when generating patches.
`histogram`;;
This algorithm extends the patience algorithm to "support
low-occurrence common elements".
--
+
...@@ -55,6 +55,26 @@ endif::git-format-patch[] ...@@ -55,6 +55,26 @@ endif::git-format-patch[]
--histogram:: --histogram::
Generate a diff using the "histogram diff" algorithm. Generate a diff using the "histogram diff" algorithm.
--diff-algorithm={patience|minimal|histogram|myers}::
Choose a diff algorithm. The variants are as follows:
+
--
`default`, `myers`;;
The basic greedy diff algorithm. Currently, this is the default.
`minimal`;;
Spend extra time to make sure the smallest possible diff is
produced.
`patience`;;
Use "patience diff" algorithm when generating patches.
`histogram`;;
This algorithm extends the patience algorithm to "support
low-occurrence common elements".
--
+
For instance, if you configured diff.algorithm variable to a
non-default value and want to use the default one, then you
have to use `--diff-algorithm=default` option.
--stat[=<width>[,<name-width>[,<count>]]]:: --stat[=<width>[,<name-width>[,<count>]]]::
Generate a diffstat. By default, as much space as necessary Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for the graph will be used for the filename part, and the rest for the graph
......
...@@ -1232,6 +1232,8 @@ _git_describe () ...@@ -1232,6 +1232,8 @@ _git_describe ()
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
} }
__git_diff_algorithms="myers minimal patience histogram"
__git_diff_common_options="--stat --numstat --shortstat --summary __git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color --patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check --no-color --color-words --no-renames --check
...@@ -1242,10 +1244,11 @@ __git_diff_common_options="--stat --numstat --shortstat --summary ...@@ -1242,10 +1244,11 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
--no-ext-diff --no-ext-diff
--no-prefix --src-prefix= --dst-prefix= --no-prefix --src-prefix= --dst-prefix=
--inter-hunk-context= --inter-hunk-context=
--patience --patience --histogram --minimal
--raw --raw
--dirstat --dirstat= --dirstat-by-file --dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative --dirstat-by-file= --cumulative
--diff-algorithm=
" "
_git_diff () _git_diff ()
...@@ -1253,6 +1256,10 @@ _git_diff () ...@@ -1253,6 +1256,10 @@ _git_diff ()
__git_has_doubledash && return __git_has_doubledash && return
case "$cur" in case "$cur" in
--diff-algorithm=*)
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
return
;;
--*) --*)
__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
--base --ours --theirs --no-index --base --ours --theirs --no-index
...@@ -2058,6 +2065,7 @@ _git_config () ...@@ -2058,6 +2065,7 @@ _git_config ()
diff.suppressBlankEmpty diff.suppressBlankEmpty
diff.tool diff.tool
diff.wordRegex diff.wordRegex
diff.algorithm
difftool. difftool.
difftool.prompt difftool.prompt
fetch.recurseSubmodules fetch.recurseSubmodules
...@@ -2331,6 +2339,10 @@ _git_show () ...@@ -2331,6 +2339,10 @@ _git_show ()
" "" "${cur#*=}" " "" "${cur#*=}"
return return
;; ;;
--diff-algorithm=*)
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
return
;;
--*) --*)
__gitcomp "--pretty= --format= --abbrev-commit --oneline __gitcomp "--pretty= --format= --abbrev-commit --oneline
$__git_diff_common_options $__git_diff_common_options
......
...@@ -36,6 +36,7 @@ static int diff_no_prefix; ...@@ -36,6 +36,7 @@ static int diff_no_prefix;
static int diff_stat_graph_width; static int diff_stat_graph_width;
static int diff_dirstat_permille_default = 30; static int diff_dirstat_permille_default = 30;
static struct diff_options default_diff_options; static struct diff_options default_diff_options;
static long diff_algorithm;
static char diff_colors[][COLOR_MAXLEN] = { static char diff_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET, GIT_COLOR_RESET,
...@@ -143,6 +144,21 @@ static int git_config_rename(const char *var, const char *value) ...@@ -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; 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. * These are to give UI layer defaults.
* The core-level commands such as git-diff-files should * 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) ...@@ -196,6 +212,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
return 0; 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) if (git_color_config(var, value, cb) < 0)
return -1; return -1;
...@@ -3163,6 +3186,7 @@ void diff_setup(struct diff_options *options) ...@@ -3163,6 +3186,7 @@ void diff_setup(struct diff_options *options)
options->add_remove = diff_addremove; options->add_remove = diff_addremove;
options->use_color = diff_use_color_default; options->use_color = diff_use_color_default;
options->detect_rename = diff_detect_rename_default; options->detect_rename = diff_detect_rename_default;
options->xdl_opts |= diff_algorithm;
if (diff_no_prefix) { if (diff_no_prefix) {
options->a_prefix = options->b_prefix = ""; options->a_prefix = options->b_prefix = "";
...@@ -3560,6 +3584,16 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) ...@@ -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); options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
else if (!strcmp(arg, "--histogram")) else if (!strcmp(arg, "--histogram"))
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF); 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 */ /* flags options */
else if (!strcmp(arg, "--binary")) { else if (!strcmp(arg, "--binary")) {
......
...@@ -336,6 +336,8 @@ extern struct userdiff_driver *get_textconv(struct diff_filespec *one); ...@@ -336,6 +336,8 @@ extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
extern int parse_rename_score(const char **cp_p); extern int parse_rename_score(const char **cp_p);
extern long parse_algorithm_value(const char *value);
extern int print_stat_summary(FILE *fp, int files, extern int print_stat_summary(FILE *fp, int files,
int insertions, int deletions); int insertions, int deletions);
extern void setup_diff_pager(struct diff_options *); extern void setup_diff_pager(struct diff_options *);
......
...@@ -2068,6 +2068,15 @@ int parse_merge_opt(struct merge_options *o, const char *s) ...@@ -2068,6 +2068,15 @@ int parse_merge_opt(struct merge_options *o, const char *s)
o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF); o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
else if (!strcmp(s, "histogram")) else if (!strcmp(s, "histogram"))
o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF); o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
else if (!strcmp(s, "diff-algorithm=")) {
long value = parse_algorithm_value(s+15);
if (value < 0)
return -1;
/* clear out previous settings */
DIFF_XDL_CLR(o, NEED_MINIMAL);
o->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
o->xdl_opts |= value;
}
else if (!strcmp(s, "ignore-space-change")) else if (!strcmp(s, "ignore-space-change"))
o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE; o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
else if (!strcmp(s, "ignore-all-space")) else if (!strcmp(s, "ignore-all-space"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册