Skip to content

Commit 2621ac5

Browse files
committed
Merge branch 'ec/diff-noprefix-config'
* ec/diff-noprefix-config: diff: add configuration option for disabling diff prefixes.
2 parents 880bd9d + f89504d commit 2621ac5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ diff.mnemonicprefix::
792792
standard "a/" and "b/" depending on what is being compared. When
793793
this configuration is in effect, reverse diff output also swaps
794794
the order of the prefixes:
795+
diff.noprefix::
796+
If set, 'git diff' does not show any source or destination prefix.
795797
`git diff`;;
796798
compares the (i)ndex and the (w)ork tree;
797799
`git diff HEAD`;;

diff.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static const char *diff_word_regex_cfg;
3030
static const char *external_diff_cmd_cfg;
3131
int diff_auto_refresh_index = 1;
3232
static int diff_mnemonic_prefix;
33+
static int diff_no_prefix;
3334

3435
static char diff_colors[][COLOR_MAXLEN] = {
3536
GIT_COLOR_RESET,
@@ -101,6 +102,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
101102
diff_mnemonic_prefix = git_config_bool(var, value);
102103
return 0;
103104
}
105+
if (!strcmp(var, "diff.noprefix")) {
106+
diff_no_prefix = git_config_bool(var, value);
107+
return 0;
108+
}
104109
if (!strcmp(var, "diff.external"))
105110
return git_config_string(&external_diff_cmd_cfg, var, value);
106111
if (!strcmp(var, "diff.wordregex"))
@@ -2625,7 +2630,9 @@ void diff_setup(struct diff_options *options)
26252630
DIFF_OPT_SET(options, COLOR_DIFF);
26262631
options->detect_rename = diff_detect_rename_default;
26272632

2628-
if (!diff_mnemonic_prefix) {
2633+
if (diff_no_prefix) {
2634+
options->a_prefix = options->b_prefix = "";
2635+
} else if (!diff_mnemonic_prefix) {
26292636
options->a_prefix = "a/";
26302637
options->b_prefix = "b/";
26312638
}

0 commit comments

Comments
 (0)