@@ -24,6 +24,7 @@ static int diff_suppress_blank_empty;
2424int diff_use_color_default = -1 ;
2525static const char * external_diff_cmd_cfg ;
2626int diff_auto_refresh_index = 1 ;
27+ static int diff_mnemonic_prefix ;
2728
2829static char diff_colors [][COLOR_MAXLEN ] = {
2930 "\033[m" , /* reset */
@@ -150,6 +151,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
150151 diff_auto_refresh_index = git_config_bool (var , value );
151152 return 0 ;
152153 }
154+ if (!strcmp (var , "diff.mnemonicprefix" )) {
155+ diff_mnemonic_prefix = git_config_bool (var , value );
156+ return 0 ;
157+ }
153158 if (!strcmp (var , "diff.external" ))
154159 return git_config_string (& external_diff_cmd_cfg , var , value );
155160 if (!prefixcmp (var , "diff." )) {
@@ -312,6 +317,15 @@ static void emit_rewrite_diff(const char *name_a,
312317 const char * new = diff_get_color (color_diff , DIFF_FILE_NEW );
313318 const char * reset = diff_get_color (color_diff , DIFF_RESET );
314319 static struct strbuf a_name = STRBUF_INIT , b_name = STRBUF_INIT ;
320+ const char * a_prefix , * b_prefix ;
321+
322+ if (diff_mnemonic_prefix && DIFF_OPT_TST (o , REVERSE_DIFF )) {
323+ a_prefix = o -> b_prefix ;
324+ b_prefix = o -> a_prefix ;
325+ } else {
326+ a_prefix = o -> a_prefix ;
327+ b_prefix = o -> b_prefix ;
328+ }
315329
316330 name_a += (* name_a == '/' );
317331 name_b += (* name_b == '/' );
@@ -320,8 +334,8 @@ static void emit_rewrite_diff(const char *name_a,
320334
321335 strbuf_reset (& a_name );
322336 strbuf_reset (& b_name );
323- quote_two_c_style (& a_name , o -> a_prefix , name_a , 0 );
324- quote_two_c_style (& b_name , o -> b_prefix , name_b , 0 );
337+ quote_two_c_style (& a_name , a_prefix , name_a , 0 );
338+ quote_two_c_style (& b_name , b_prefix , name_b , 0 );
325339
326340 diff_populate_filespec (one , 0 );
327341 diff_populate_filespec (two , 0 );
@@ -1447,6 +1461,14 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
14471461 return NULL ;
14481462}
14491463
1464+ void diff_set_mnemonic_prefix (struct diff_options * options , const char * a , const char * b )
1465+ {
1466+ if (!options -> a_prefix )
1467+ options -> a_prefix = a ;
1468+ if (!options -> b_prefix )
1469+ options -> b_prefix = b ;
1470+ }
1471+
14501472static void builtin_diff (const char * name_a ,
14511473 const char * name_b ,
14521474 struct diff_filespec * one ,
@@ -1460,9 +1482,19 @@ static void builtin_diff(const char *name_a,
14601482 char * a_one , * b_two ;
14611483 const char * set = diff_get_color_opt (o , DIFF_METAINFO );
14621484 const char * reset = diff_get_color_opt (o , DIFF_RESET );
1485+ const char * a_prefix , * b_prefix ;
1486+
1487+ diff_set_mnemonic_prefix (o , "a/" , "b/" );
1488+ if (DIFF_OPT_TST (o , REVERSE_DIFF )) {
1489+ a_prefix = o -> b_prefix ;
1490+ b_prefix = o -> a_prefix ;
1491+ } else {
1492+ a_prefix = o -> a_prefix ;
1493+ b_prefix = o -> b_prefix ;
1494+ }
14631495
1464- a_one = quote_two (o -> a_prefix , name_a + (* name_a == '/' ));
1465- b_two = quote_two (o -> b_prefix , name_b + (* name_b == '/' ));
1496+ a_one = quote_two (a_prefix , name_a + (* name_a == '/' ));
1497+ b_two = quote_two (b_prefix , name_b + (* name_b == '/' ));
14661498 lbl [0 ] = DIFF_FILE_VALID (one ) ? a_one : "/dev/null" ;
14671499 lbl [1 ] = DIFF_FILE_VALID (two ) ? b_two : "/dev/null" ;
14681500 fprintf (o -> file , "%sdiff --git %s %s%s\n" , set , a_one , b_two , reset );
@@ -2319,8 +2351,10 @@ void diff_setup(struct diff_options *options)
23192351 DIFF_OPT_CLR (options , COLOR_DIFF );
23202352 options -> detect_rename = diff_detect_rename_default ;
23212353
2322- options -> a_prefix = "a/" ;
2323- options -> b_prefix = "b/" ;
2354+ if (!diff_mnemonic_prefix ) {
2355+ options -> a_prefix = "a/" ;
2356+ options -> b_prefix = "b/" ;
2357+ }
23242358}
23252359
23262360int diff_setup_done (struct diff_options * options )
0 commit comments