@@ -36,6 +36,7 @@ static int diff_no_prefix;
3636static int diff_stat_graph_width ;
3737static int diff_dirstat_permille_default = 30 ;
3838static struct diff_options default_diff_options ;
39+ static long diff_algorithm ;
3940
4041static char diff_colors [][COLOR_MAXLEN ] = {
4142 GIT_COLOR_RESET ,
@@ -143,6 +144,21 @@ static int git_config_rename(const char *var, const char *value)
143144 return git_config_bool (var ,value ) ? DIFF_DETECT_RENAME : 0 ;
144145}
145146
147+ long parse_algorithm_value (const char * value )
148+ {
149+ if (!value )
150+ return -1 ;
151+ else if (!strcasecmp (value , "myers" ) || !strcasecmp (value , "default" ))
152+ return 0 ;
153+ else if (!strcasecmp (value , "minimal" ))
154+ return XDF_NEED_MINIMAL ;
155+ else if (!strcasecmp (value , "patience" ))
156+ return XDF_PATIENCE_DIFF ;
157+ else if (!strcasecmp (value , "histogram" ))
158+ return XDF_HISTOGRAM_DIFF ;
159+ return -1 ;
160+ }
161+
146162/*
147163 * These are to give UI layer defaults.
148164 * 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)
196212 return 0 ;
197213 }
198214
215+ if (!strcmp (var , "diff.algorithm" )) {
216+ diff_algorithm = parse_algorithm_value (value );
217+ if (diff_algorithm < 0 )
218+ return -1 ;
219+ return 0 ;
220+ }
221+
199222 if (git_color_config (var , value , cb ) < 0 )
200223 return -1 ;
201224
@@ -3163,6 +3186,7 @@ void diff_setup(struct diff_options *options)
31633186 options -> add_remove = diff_addremove ;
31643187 options -> use_color = diff_use_color_default ;
31653188 options -> detect_rename = diff_detect_rename_default ;
3189+ options -> xdl_opts |= diff_algorithm ;
31663190
31673191 if (diff_no_prefix ) {
31683192 options -> a_prefix = options -> b_prefix = "" ;
@@ -3560,6 +3584,16 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
35603584 options -> xdl_opts = DIFF_WITH_ALG (options , PATIENCE_DIFF );
35613585 else if (!strcmp (arg , "--histogram" ))
35623586 options -> xdl_opts = DIFF_WITH_ALG (options , HISTOGRAM_DIFF );
3587+ else if (!prefixcmp (arg , "--diff-algorithm=" )) {
3588+ long value = parse_algorithm_value (arg + 17 );
3589+ if (value < 0 )
3590+ return error ("option diff-algorithm accepts \"myers\", "
3591+ "\"minimal\", \"patience\" and \"histogram\"" );
3592+ /* clear out previous settings */
3593+ DIFF_XDL_CLR (options , NEED_MINIMAL );
3594+ options -> xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK ;
3595+ options -> xdl_opts |= value ;
3596+ }
35633597
35643598 /* flags options */
35653599 else if (!strcmp (arg , "--binary" )) {
0 commit comments