@@ -4841,6 +4841,27 @@ static int diff_opt_char(const struct option *opt,
48414841 return 0 ;
48424842}
48434843
4844+ static int diff_opt_color_moved (const struct option * opt ,
4845+ const char * arg , int unset )
4846+ {
4847+ struct diff_options * options = opt -> value ;
4848+
4849+ if (unset ) {
4850+ options -> color_moved = COLOR_MOVED_NO ;
4851+ } else if (!arg ) {
4852+ if (diff_color_moved_default )
4853+ options -> color_moved = diff_color_moved_default ;
4854+ if (options -> color_moved == COLOR_MOVED_NO )
4855+ options -> color_moved = COLOR_MOVED_DEFAULT ;
4856+ } else {
4857+ int cm = parse_color_moved (arg );
4858+ if (cm < 0 )
4859+ return error (_ ("bad --color-moved argument: %s" ), arg );
4860+ options -> color_moved = cm ;
4861+ }
4862+ return 0 ;
4863+ }
4864+
48444865static int diff_opt_color_words (const struct option * opt ,
48454866 const char * arg , int unset )
48464867{
@@ -5339,6 +5360,9 @@ static void prep_parse_options(struct diff_options *options)
53395360 OPT_CALLBACK_F (0 , "color-words" , options , N_ ("<regex>" ),
53405361 N_ ("equivalent to --word-diff=color --word-diff-regex=<regex>" ),
53415362 PARSE_OPT_NONEG | PARSE_OPT_OPTARG , diff_opt_color_words ),
5363+ OPT_CALLBACK_F (0 , "color-moved" , options , N_ ("<mode>" ),
5364+ N_ ("move lines of code are colored differently" ),
5365+ PARSE_OPT_OPTARG , diff_opt_color_moved ),
53425366
53435367 OPT_GROUP (N_ ("Diff other options" )),
53445368 OPT_CALLBACK_F (0 , "relative" , options , N_ ("<prefix>" ),
@@ -5422,19 +5446,7 @@ int diff_opt_parse(struct diff_options *options,
54225446 return ac ;
54235447
54245448 /* flags options */
5425- if (!strcmp (arg , "--color-moved" )) {
5426- if (diff_color_moved_default )
5427- options -> color_moved = diff_color_moved_default ;
5428- if (options -> color_moved == COLOR_MOVED_NO )
5429- options -> color_moved = COLOR_MOVED_DEFAULT ;
5430- } else if (!strcmp (arg , "--no-color-moved" ))
5431- options -> color_moved = COLOR_MOVED_NO ;
5432- else if (skip_prefix (arg , "--color-moved=" , & arg )) {
5433- int cm = parse_color_moved (arg );
5434- if (cm < 0 )
5435- return error ("bad --color-moved argument: %s" , arg );
5436- options -> color_moved = cm ;
5437- } else if (skip_prefix (arg , "--color-moved-ws=" , & arg )) {
5449+ if (skip_prefix (arg , "--color-moved-ws=" , & arg )) {
54385450 unsigned cm = parse_color_moved_ws (arg );
54395451 if (cm & COLOR_MOVED_WS_ERROR )
54405452 return -1 ;
0 commit comments