From: Peter Hutterer <peter.hutterer@who-t.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, David Heidelberg <david@ixit.cz>
Subject: [PATCH v2] diff: add diff.srcprefix and diff.dstprefix configuration variables
Date: Tue, 12 Mar 2024 10:57:56 +1000 [thread overview]
Message-ID: <20240312005756.GA3029606@quokka> (raw)
In-Reply-To: <xmqqplw0r6c3.fsf@gitster.g>
Allow the default prefixes "a/" and "b/" to be tweaked by the
diff.srcprefix and diff.dstprefix configuration variables.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
Changes to v1:
- note default in documentation
- drop the custom prefix function, change the defaults instead
- commit message: options -> configuration variables
Junio: all of your comments squashed in as requested, thanks for the
review and suggestions, much simpler now.
Documentation/config/diff.txt | 6 ++++++
diff.c | 12 ++++++++++--
t/t4013-diff-various.sh | 20 ++++++++++++++++++++
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
index 6c7e09a1ef5e..43d94df19876 100644
--- a/Documentation/config/diff.txt
+++ b/Documentation/config/diff.txt
@@ -111,6 +111,12 @@ diff.mnemonicPrefix::
diff.noprefix::
If set, 'git diff' does not show any source or destination prefix.
+diff.srcprefix::
+ If set, 'git diff' uses this source prefix. Defaults to 'a/'.
+
+diff.dstprefix::
+ If set, 'git diff' uses this destination prefix. Defaults to 'b/'.
+
diff.relative::
If set to 'true', 'git diff' does not show changes outside of the directory
and show pathnames relative to the current directory.
diff --git a/diff.c b/diff.c
index e50def45383e..4439b1a95864 100644
--- a/diff.c
+++ b/diff.c
@@ -62,6 +62,8 @@ static const char *diff_order_file_cfg;
int diff_auto_refresh_index = 1;
static int diff_mnemonic_prefix;
static int diff_no_prefix;
+static const char *diff_src_prefix = "a/";
+static const char *diff_dst_prefix = "b/";
static int diff_relative;
static int diff_stat_name_width;
static int diff_stat_graph_width;
@@ -408,6 +410,12 @@ int git_diff_ui_config(const char *var, const char *value,
diff_no_prefix = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "diff.srcprefix")) {
+ return git_config_string(&diff_src_prefix, var, value);
+ }
+ if (!strcmp(var, "diff.dstprefix")) {
+ return git_config_string(&diff_dst_prefix, var, value);
+ }
if (!strcmp(var, "diff.relative")) {
diff_relative = git_config_bool(var, value);
return 0;
@@ -3425,8 +3433,8 @@ void diff_set_noprefix(struct diff_options *options)
void diff_set_default_prefix(struct diff_options *options)
{
- options->a_prefix = "a/";
- options->b_prefix = "b/";
+ options->a_prefix = diff_src_prefix;
+ options->b_prefix = diff_dst_prefix;
}
struct userdiff_driver *get_textconv(struct repository *r,
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 1e3b2dbea484..86834186fdba 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -663,6 +663,26 @@ test_expect_success 'diff --default-prefix overrides diff.mnemonicprefix' '
check_prefix actual a/file0 b/file0
'
+test_expect_success 'diff respects diff.srcprefix' '
+ git -c diff.srcprefix=x/ diff >actual &&
+ check_prefix actual x/file0 b/file0
+'
+
+test_expect_success 'diff respects diff.dstprefix' '
+ git -c diff.dstprefix=y/ diff >actual &&
+ check_prefix actual a/file0 y/file0
+'
+
+test_expect_success 'diff src/dstprefix ignored with diff.noprefix' '
+ git -c diff.dstprefix=y/ -c diff.srcprefix=x/ -c diff.noprefix diff >actual &&
+ check_prefix actual file0 file0
+'
+
+test_expect_success 'diff src/dstprefix ignored with diff.mnemonicprefix' '
+ git -c diff.dstprefix=x/ -c diff.srcprefix=y/ -c diff.mnemonicprefix diff >actual &&
+ check_prefix actual i/file0 w/file0
+'
+
test_expect_success 'diff --no-renames cannot be abbreviated' '
test_expect_code 129 git diff --no-rename >actual 2>error &&
test_must_be_empty actual &&
--
2.44.0
next prev parent reply other threads:[~2024-03-12 0:58 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 2:32 [PATCH] diff: add diff.srcprefix and diff.dstprefix option support Peter Hutterer
2024-03-11 18:06 ` Junio C Hamano
2024-03-12 0:57 ` Peter Hutterer [this message]
2024-03-12 19:23 ` [PATCH v2] diff: add diff.srcprefix and diff.dstprefix configuration variables Junio C Hamano
2024-03-12 19:29 ` Dragan Simic
2024-03-12 23:15 ` [PATCH v3] diff: add diff.srcPrefix and diff.dstPrefix " Peter Hutterer
2024-03-13 2:15 ` Dragan Simic
2024-03-13 3:26 ` Dragan Simic
2024-03-13 15:06 ` Phillip Wood
2024-03-13 15:14 ` Dragan Simic
2024-03-13 15:24 ` Junio C Hamano
2024-03-13 15:28 ` Dragan Simic
2024-03-13 15:04 ` Phillip Wood
2024-03-13 15:29 ` Junio C Hamano
2024-03-13 16:18 ` Phillip Wood
2024-03-13 17:55 ` Junio C Hamano
2024-03-14 5:06 ` Peter Hutterer
2024-03-13 20:23 ` Dragan Simic
2024-03-15 1:03 ` [PATCH v4] " Peter Hutterer
2024-03-15 3:53 ` Dragan Simic
2024-03-15 5:54 ` [PATCH v5] " Peter Hutterer
2024-03-15 6:02 ` Dragan Simic
2024-03-15 17:00 ` Junio C Hamano
2024-03-15 19:13 ` Dragan Simic
2024-03-16 5:57 ` Junio C Hamano
2024-03-16 6:41 ` Dragan Simic
2024-03-18 3:49 ` Peter Hutterer
2024-03-18 4:39 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240312005756.GA3029606@quokka \
--to=peter.hutterer@who-t.net \
--cc=david@ixit.cz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).