Michal Privoznik mpriv...@redhat.com writes:
Since command line options have higher priority than config file
variables and taking previous commit into account, we need a way
how to specify myers algorithm on command line.
Yes. We cannot stop at [2/3] without this patch.
However,
inventing `--myers` is not the right answer. We need far more
general option, and that is `--diff-algorithm`.
Yes, --diff-algorithm=default would let people defeat a configured
algo without knowing how exactly to spell myers.
The older options
(`--minimal`, `--patience` and `--histogram`) are kept for
backward compatibility.
That is phrasing it too strongly to be acceptable.
People who do not care any configuration can keep using --histogram
without having to retrain their fingers to type a much longer form
you introduced (i.e. --diff-algorithm=histogram). It is and will
always be just as valid a way to ask for --histogram as the new
longhand is.
Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
Documentation/diff-options.txt | 22 ++
contrib/completion/git-completion.bash | 11 +++
diff.c | 12 +++-
diff.h | 2 ++
merge-recursive.c | 6 ++
5 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 39f2c50..4091f52 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -45,6 +45,9 @@ ifndef::git-format-patch[]
Synonym for `-p --raw`.
endif::git-format-patch[]
+The next three options are kept for compatibility reason. You should use the
+`--diff-algorithm` option instead.
+
Drop this.
@@ -55,6 +58,25 @@ endif::git-format-patch[]
--histogram::
Generate a diff using the histogram diff algorithm.
+--diff-algorithm={patience|minimal|histogram|myers}::
+ Choose a diff algorithm. The variants are as follows:
++
+--
+`myers`;;
+ The basic greedy diff algorithm.
+`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.
+--
++
+You should prefer this option over the `--minimal`, `--patience` and
+`--histogram` which are kept just for backwards compatibility.
Drop the last one, and replace it with something like:
If you configured diff.algorithm to a non-default value and
want to use the default one, you have to use this form and
choose myers, i.e. --diff-algorithm=myers, as we do not have
a short-and-sweet --myers option.
(but the above is a bit too verbose, so please shorten it appropriately).
diff --git a/contrib/completion/git-completion.bash
b/contrib/completion/git-completion.bash
index 33e25dc..d592cf9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1021,6 +1021,8 @@ _git_describe ()
__gitcomp_nl $(__git_refs)
}
+__git_diff_algorithms=myers minimal patience histogram
+
__git_diff_common_options=--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
@@ -1035,6 +1037,7 @@ __git_diff_common_options=--stat --numstat --shortstat
--summary
--raw
--dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative
+ --diff-algorithm=
_git_diff ()
@@ -1042,6 +1045,10 @@ _git_diff ()
__git_has_doubledash return
case $cur in
+ --diff-algorithm=*)
+ __gitcomp $__git_diff_algorithms
${cur##--diff-algorithm=}
+ return
+ ;;
--*)
__gitcomp --cached --staged --pickaxe-all --pickaxe-regex
--base --ours --theirs --no-index
@@ -2114,6 +2121,10 @@ _git_show ()
${cur#*=}
return
;;
+ --diff-algorithm=*)
+ __gitcomp $__git_diff_algorithms
${cur##--diff-algorithm=}
+ return
+ ;;
--*)
__gitcomp --pretty= --format= --abbrev-commit --oneline
$__git_diff_common_options
diff --git a/diff.c b/diff.c
index ddae5c4..6418076 100644
--- a/diff.c
+++ b/diff.c
@@ -144,7 +144,7 @@ static int git_config_rename(const char *var, const char
*value)
return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0;
}
-static long parse_algorithm_value(const char *value)
+long parse_algorithm_value(const char *value)
{
if (!value || !strcasecmp(value, myers))
return 0;
@@ -3633,6 +3633,16 @@ int