23
int diff_use_color_default = -1;
24
static const char *external_diff_cmd_cfg;
25
int diff_auto_refresh_index = 1;
26
+static int diff_mnemonic_prefix;
27
28
static char diff_colors[][COLOR_MAXLEN] = {
29
"\033[m", /* reset */
150
diff_auto_refresh_index = git_config_bool(var, value);
151
return 0;
152
}
153
+ if (!strcmp(var, "diff.mnemonicprefix")) {
154
+ diff_mnemonic_prefix = git_config_bool(var, value);
155
+ return 0;
156
+ }
157
if (!strcmp(var, "diff.external"))
158
return git_config_string(&external_diff_cmd_cfg, var, value);
159
if (!prefixcmp(var, "diff.")) {
310
const char *new = diff_get_color(color_diff, DIFF_FILE_NEW);
311
const char *reset = diff_get_color(color_diff, DIFF_RESET);
312
static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
313
+ const char *a_prefix, *b_prefix;
314
+
315
+ if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
316
+ a_prefix = o->b_prefix;
317
+ b_prefix = o->a_prefix;
318
+ } else {
319
+ a_prefix = o->a_prefix;
320
+ b_prefix = o->b_prefix;
321
+ }
322
323
name_a += (*name_a == '/');
324
name_b += (*name_b == '/');
327
328
strbuf_reset(&a_name);
329
strbuf_reset(&b_name);
316
- quote_two_c_style(&a_name, o->a_prefix, name_a, 0);
317
- quote_two_c_style(&b_name, o->b_prefix, name_b, 0);
330
+ quote_two_c_style(&a_name, a_prefix, name_a, 0);
331
+ quote_two_c_style(&b_name, b_prefix, name_b, 0);
332
333
diff_populate_filespec(one, 0);
334
diff_populate_filespec(two, 0);
1446
return NULL;
1447
}
1448
1449
+void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b)
1450
+{
1451
+ if (!options->a_prefix)
1452
+ options->a_prefix = a;
1453
+ if (!options->b_prefix)
1454
+ options->b_prefix = b;
1455
+}
1456
+
1457
static void builtin_diff(const char *name_a,
1458
const char *name_b,
1459
struct diff_filespec *one,
1467
char *a_one, *b_two;
1468
const char *set = diff_get_color_opt(o, DIFF_METAINFO);
1469
const char *reset = diff_get_color_opt(o, DIFF_RESET);
1470
+ const char *a_prefix, *b_prefix;
1471
+
1472
+ diff_set_mnemonic_prefix(o, "a/", "b/");
1473
+ if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
1474
+ a_prefix = o->b_prefix;
1475
+ b_prefix = o->a_prefix;
1476
+ } else {
1477
+ a_prefix = o->a_prefix;
1478
+ b_prefix = o->b_prefix;
1479
+ }
1480
1449
- a_one = quote_two(o->a_prefix, name_a + (*name_a == '/'));
1450
- b_two = quote_two(o->b_prefix, name_b + (*name_b == '/'));
1481
+ a_one = quote_two(a_prefix, name_a + (*name_a == '/'));
1482
+ b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
1483
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
1484
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
1485
fprintf(o->file, "%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
2340
DIFF_OPT_CLR(options, COLOR_DIFF);
2341
options->detect_rename = diff_detect_rename_default;
2342
2311
- options->a_prefix = "a/";
2312
- options->b_prefix = "b/";
2343
+ if (!diff_mnemonic_prefix) {
2344
+ options->a_prefix = "a/";
2345
+ options->b_prefix = "b/";
2346
+ }
2347
}
2348
2349
int diff_setup_done(struct diff_options *options)