All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>,
	Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH] diff: add --no-indicators option
Date: Fri, 19 Dec 2025 08:17:44 +0000	[thread overview]
Message-ID: <pull.2133.git.git.1766132264231.gitgitgadget@gmail.com> (raw)

From: Harald Nordgren <haraldnordgren@gmail.com>

Add --no-indicators to replace '+', '-', and ' ' indicators in the
left margin with spaces. Colors are preserved, allowing diffs to be
distinguished by color alone.

This is useful when copy-pasting diff output, as the indicators no
longer need to be manually removed.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
    diff: add '--no-indicators' option

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2133%2FHaraldNordgren%2Fno-indicators-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2133/HaraldNordgren/no-indicators-v1
Pull-Request: https://github.com/git/git/pull/2133

 diff.c                 | 17 +++++++++++++++++
 t/t4000-diff-format.sh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/diff.c b/diff.c
index 436da250eb..668ba349fe 100644
--- a/diff.c
+++ b/diff.c
@@ -5290,6 +5290,20 @@ static int diff_opt_char(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_no_indicators(const struct option *opt,
+				  const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
+
+	options->output_indicators[OUTPUT_INDICATOR_NEW] = ' ';
+	options->output_indicators[OUTPUT_INDICATOR_OLD] = ' ';
+	options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = ' ';
+	return 0;
+}
+
 static int diff_opt_color_moved(const struct option *opt,
 				const char *arg, int unset)
 {
@@ -5828,6 +5842,9 @@ struct option *add_diff_options(const struct option *opts,
 		OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext,
 			      N_("show context between diff hunks up to the specified number of lines"),
 			      PARSE_OPT_NONEG),
+		OPT_CALLBACK_F(0, "no-indicators", options, NULL,
+			       N_("do not show '+', '-' and ' ' indicators in the left margin"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_indicators),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index 32b14e3a71..1863553056 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -95,6 +95,38 @@ test_expect_success 'git diff-files --patch --no-patch does not show the patch'
 	test_must_be_empty err
 '
 
+cat >expected_no_indicators <<\EOF
+diff --git a/path0 b/path0
+old mode 100644
+new mode 100755
+--- a/path0
++++ b/path0
+@@ -1,3 +1,3 @@
+ Line 1
+ Line 2
+ line 3
+ Line 3
+diff --git a/path1 b/path1
+deleted file mode 100755
+--- a/path1
++++ /dev/null
+@@ -1,3 +0,0 @@
+ Line 1
+ Line 2
+ line 3
+EOF
+
+test_expect_success 'git diff-files --no-indicators replaces +/- with spaces' '
+	git diff-files -p --no-indicators >actual &&
+	compare_diff_patch expected_no_indicators actual
+'
+
+test_expect_success 'git diff-files --no-indicators --color preserves colors' '
+	git diff-files -p --no-indicators --color --ws-error-highlight=none >actual.raw &&
+	test_decode_color <actual.raw >actual &&
+	grep -F "<RED> line 3<RESET>" actual &&
+	grep -F "<GREEN> Line 3<RESET>" actual
+'
 
 # Smudge path2/path3 so that dirstat has something to show
 date >path2/path3

base-commit: c4a0c8845e2426375ad257b6c221a3a7d92ecfda
-- 
gitgitgadget

             reply	other threads:[~2025-12-19  8:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19  8:17 Harald Nordgren via GitGitGadget [this message]
2025-12-19  8:57 ` [PATCH] diff: add --no-indicators option Collin Funk
2025-12-19 11:48   ` Harald Nordgren
2025-12-19 13:28     ` Ben Knoble
2025-12-19 18:53       ` Harald Nordgren
2025-12-19 10:33 ` Phillip Wood
2025-12-19 11:46   ` Harald Nordgren
2025-12-19 14:27     ` Phillip Wood
2025-12-19 14:40       ` Chris Torek
2025-12-19 14:54         ` Harald Nordgren
2025-12-19 15:02           ` Chris Torek
2025-12-19 15:23             ` Harald Nordgren
2025-12-19 14:50       ` Harald Nordgren
2025-12-20 13:14         ` Johannes Sixt
2025-12-19 11:58 ` Junio C Hamano
2025-12-19 19:08   ` Harald Nordgren
2025-12-20  6:03     ` Junio C Hamano
2025-12-20 10:52       ` Harald Nordgren

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=pull.2133.git.git.1766132264231.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=haraldnordgren@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.