Skip to content

Commit f89504d

Browse files
elicollinsgitster
authored andcommitted
diff: add configuration option for disabling diff prefixes.
With new configuration "diff.noprefix", "git diff" does not show a source or destination prefix ala "git diff --no-prefix". Signed-off-by: Eli Collins <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0e4607c commit f89504d

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
@@ -798,6 +798,8 @@ diff.mnemonicprefix::
798798
standard "a/" and "b/" depending on what is being compared. When
799799
this configuration is in effect, reverse diff output also swaps
800800
the order of the prefixes:
801+
diff.noprefix::
802+
If set, 'git diff' does not show any source or destination prefix.
801803
`git diff`;;
802804
compares the (i)ndex and the (w)ork tree;
803805
`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"))
@@ -2538,7 +2543,9 @@ void diff_setup(struct diff_options *options)
25382543
DIFF_OPT_SET(options, COLOR_DIFF);
25392544
options->detect_rename = diff_detect_rename_default;
25402545

2541-
if (!diff_mnemonic_prefix) {
2546+
if (diff_no_prefix) {
2547+
options->a_prefix = options->b_prefix = "";
2548+
} else if (!diff_mnemonic_prefix) {
25422549
options->a_prefix = "a/";
25432550
options->b_prefix = "b/";
25442551
}

0 commit comments

Comments
 (0)