@@ -3437,6 +3437,22 @@ static int diff_filepair_is_phoney(struct diff_filespec *one,
3437
3437
return !DIFF_FILE_VALID (one ) && !DIFF_FILE_VALID (two );
3438
3438
}
3439
3439
3440
+ static int set_diff_algorithm (struct diff_options * opts ,
3441
+ const char * alg )
3442
+ {
3443
+ long value = parse_algorithm_value (alg );
3444
+
3445
+ if (value < 0 )
3446
+ return -1 ;
3447
+
3448
+ /* clear out previous settings */
3449
+ DIFF_XDL_CLR (opts , NEED_MINIMAL );
3450
+ opts -> xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK ;
3451
+ opts -> xdl_opts |= value ;
3452
+
3453
+ return 0 ;
3454
+ }
3455
+
3440
3456
static void builtin_diff (const char * name_a ,
3441
3457
const char * name_b ,
3442
3458
struct diff_filespec * one ,
@@ -4440,15 +4456,13 @@ static void run_diff_cmd(const char *pgm,
4440
4456
const char * xfrm_msg = NULL ;
4441
4457
int complete_rewrite = (p -> status == DIFF_STATUS_MODIFIED ) && p -> score ;
4442
4458
int must_show_header = 0 ;
4459
+ struct userdiff_driver * drv = NULL ;
4443
4460
4444
-
4445
- if (o -> flags .allow_external ) {
4446
- struct userdiff_driver * drv ;
4447
-
4461
+ if (o -> flags .allow_external || !o -> ignore_driver_algorithm )
4448
4462
drv = userdiff_find_by_path (o -> repo -> index , attr_path );
4449
- if ( drv && drv -> external )
4450
- pgm = drv -> external ;
4451
- }
4463
+
4464
+ if ( o -> flags . allow_external && drv && drv -> external )
4465
+ pgm = drv -> external ;
4452
4466
4453
4467
if (msg ) {
4454
4468
/*
@@ -4465,12 +4479,16 @@ static void run_diff_cmd(const char *pgm,
4465
4479
run_external_diff (pgm , name , other , one , two , xfrm_msg , o );
4466
4480
return ;
4467
4481
}
4468
- if (one && two )
4482
+ if (one && two ) {
4483
+ if (!o -> ignore_driver_algorithm && drv && drv -> algorithm )
4484
+ set_diff_algorithm (o , drv -> algorithm );
4485
+
4469
4486
builtin_diff (name , other ? other : name ,
4470
4487
one , two , xfrm_msg , must_show_header ,
4471
4488
o , complete_rewrite );
4472
- else
4489
+ } else {
4473
4490
fprintf (o -> file , "* Unmerged path %s\n" , name );
4491
+ }
4474
4492
}
4475
4493
4476
4494
static void diff_fill_oid_info (struct diff_filespec * one , struct index_state * istate )
@@ -4567,6 +4585,14 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
4567
4585
const char * name ;
4568
4586
const char * other ;
4569
4587
4588
+ if (!o -> ignore_driver_algorithm ) {
4589
+ struct userdiff_driver * drv = userdiff_find_by_path (o -> repo -> index ,
4590
+ p -> one -> path );
4591
+
4592
+ if (drv && drv -> algorithm )
4593
+ set_diff_algorithm (o , drv -> algorithm );
4594
+ }
4595
+
4570
4596
if (DIFF_PAIR_UNMERGED (p )) {
4571
4597
/* unmerged */
4572
4598
builtin_diffstat (p -> one -> path , NULL , NULL , NULL ,
@@ -5107,17 +5133,32 @@ static int diff_opt_diff_algorithm(const struct option *opt,
5107
5133
const char * arg , int unset )
5108
5134
{
5109
5135
struct diff_options * options = opt -> value ;
5110
- long value = parse_algorithm_value (arg );
5111
5136
5112
5137
BUG_ON_OPT_NEG (unset );
5113
- if (value < 0 )
5138
+
5139
+ if (set_diff_algorithm (options , arg ))
5114
5140
return error (_ ("option diff-algorithm accepts \"myers\", "
5115
5141
"\"minimal\", \"patience\" and \"histogram\"" ));
5116
5142
5117
- /* clear out previous settings */
5118
- DIFF_XDL_CLR (options , NEED_MINIMAL );
5119
- options -> xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK ;
5120
- options -> xdl_opts |= value ;
5143
+ options -> ignore_driver_algorithm = 1 ;
5144
+
5145
+ return 0 ;
5146
+ }
5147
+
5148
+ static int diff_opt_diff_algorithm_no_arg (const struct option * opt ,
5149
+ const char * arg , int unset )
5150
+ {
5151
+ struct diff_options * options = opt -> value ;
5152
+
5153
+ BUG_ON_OPT_NEG (unset );
5154
+ BUG_ON_OPT_ARG (arg );
5155
+
5156
+ if (set_diff_algorithm (options , opt -> long_name ))
5157
+ BUG ("available diff algorithms include \"myers\", "
5158
+ "\"minimal\", \"patience\" and \"histogram\"" );
5159
+
5160
+ options -> ignore_driver_algorithm = 1 ;
5161
+
5121
5162
return 0 ;
5122
5163
}
5123
5164
@@ -5250,7 +5291,6 @@ static int diff_opt_patience(const struct option *opt,
5250
5291
5251
5292
BUG_ON_OPT_NEG (unset );
5252
5293
BUG_ON_OPT_ARG (arg );
5253
- options -> xdl_opts = DIFF_WITH_ALG (options , PATIENCE_DIFF );
5254
5294
/*
5255
5295
* Both --patience and --anchored use PATIENCE_DIFF
5256
5296
* internally, so remove any anchors previously
@@ -5259,7 +5299,9 @@ static int diff_opt_patience(const struct option *opt,
5259
5299
for (i = 0 ; i < options -> anchors_nr ; i ++ )
5260
5300
free (options -> anchors [i ]);
5261
5301
options -> anchors_nr = 0 ;
5262
- return 0 ;
5302
+ options -> ignore_driver_algorithm = 1 ;
5303
+
5304
+ return set_diff_algorithm (options , "patience" );
5263
5305
}
5264
5306
5265
5307
static int diff_opt_ignore_regex (const struct option * opt ,
@@ -5562,9 +5604,10 @@ struct option *add_diff_options(const struct option *opts,
5562
5604
N_ ("prevent rename/copy detection if the number of rename/copy targets exceeds given limit" )),
5563
5605
5564
5606
OPT_GROUP (N_ ("Diff algorithm options" )),
5565
- OPT_BIT (0 , "minimal" , & options -> xdl_opts ,
5566
- N_ ("produce the smallest possible diff" ),
5567
- XDF_NEED_MINIMAL ),
5607
+ OPT_CALLBACK_F (0 , "minimal" , options , NULL ,
5608
+ N_ ("produce the smallest possible diff" ),
5609
+ PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
5610
+ diff_opt_diff_algorithm_no_arg ),
5568
5611
OPT_BIT_F ('w' , "ignore-all-space" , & options -> xdl_opts ,
5569
5612
N_ ("ignore whitespace when comparing lines" ),
5570
5613
XDF_IGNORE_WHITESPACE , PARSE_OPT_NONEG ),
@@ -5590,9 +5633,10 @@ struct option *add_diff_options(const struct option *opts,
5590
5633
N_ ("generate diff using the \"patience diff\" algorithm" ),
5591
5634
PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
5592
5635
diff_opt_patience ),
5593
- OPT_BITOP (0 , "histogram" , & options -> xdl_opts ,
5594
- N_ ("generate diff using the \"histogram diff\" algorithm" ),
5595
- XDF_HISTOGRAM_DIFF , XDF_DIFF_ALGORITHM_MASK ),
5636
+ OPT_CALLBACK_F (0 , "histogram" , options , NULL ,
5637
+ N_ ("generate diff using the \"histogram diff\" algorithm" ),
5638
+ PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
5639
+ diff_opt_diff_algorithm_no_arg ),
5596
5640
OPT_CALLBACK_F (0 , "diff-algorithm" , options , N_ ("<algorithm>" ),
5597
5641
N_ ("choose a diff algorithm" ),
5598
5642
PARSE_OPT_NONEG , diff_opt_diff_algorithm ),
0 commit comments