Skip to contentSkip to conversation

Allow setting diff.worddiff=color via gitconfig

PATCH In review Olliver Schinagl 8 participants 17 messages Feb 28, 2024 – Mar 25, 2024 Documentation

lore
Share & tools
lore
#0 lore raw

Currently, the only way to set word-diff=color is through alias. It would be much nicer of course if we could do

[diff]
    worddiff=color

in git-config of course.

Thank you,

Olliver

#1 lore raw

cover Support diff.wordDiff config

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

The first patch is more of a preparatory patch, which makes it easier to add tests when the actual config is added in patch 2.

Karthik Nayak (2):
t4034: extract out diff_with_opts
diff: add 'diff.wordDiff' config option

 Documentation/config/diff.txt |  4 +++
 diff.c                        | 50 +++++++++++++++++++++------
 t/t4034-diff-words.sh         | 63 ++++++++++++++++++++---------------
 3 files changed, 80 insertions(+), 37 deletions(-)
Signature · 1 line
2.43.GIT
#2 lore raw

PATCH 1/2 t4034: extract out `diff_with_opts`

The current word_diff function in t4034 uses the arguments provided to obtain the diff and compare them.

Let's rename this to diff_with_opts and add a new function word_diff which is specific to the --word-diff= option. This function will act as a wrapper around diff_with_opts.

In the following commit, when we introduce a config option for --word-diff, we'd want to test the existing tests also with the config option and at this point we can expand word_diff to test both config and command line options.

---
 t/t4034-diff-words.sh | 54 +++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 25 deletions(-)
t/t4034-diff-words.sh +29 -25
index 74586f3813..4f70aa6e9f 100755
@@ -51,7 +51,7 @@ cat >expect.non-whitespace-is-word <<-EOF
 	<GREEN>aeff = aeff * ( aaa )<RESET>
 EOF
 
-word_diff () {
+diff_with_opts () {
 	pre=$(git rev-parse --short $(git hash-object pre)) &&
 	post=$(git rev-parse --short $(git hash-object post)) &&
 	test_must_fail git diff --no-index "$@" pre post >output &&
@@ -60,6 +60,10 @@ word_diff () {
 	test_cmp expected output.decrypted
 }
 
+word_diff () {
+	diff_with_opts "--word-diff=$1" $(echo "$@" | cut -d' ' -s -f 2-)
+}
+
 test_language_driver () {
 	lang=$1
 	test_expect_success "diff driver '$lang'" '
@@ -67,11 +71,11 @@ test_language_driver () {
 			"$TEST_DIRECTORY/t4034/'"$lang"'/post" \
 			"$TEST_DIRECTORY/t4034/'"$lang"'/expect" . &&
 		echo "* diff='"$lang"'" >.gitattributes &&
-		word_diff --color-words
+		diff_with_opts --color-words
 	'
 	test_expect_success "diff driver '$lang' in Islandic" '
 		LANG=is_IS.UTF-8 LANGUAGE=is LC_ALL="$is_IS_locale" \
-		word_diff --color-words
+		diff_with_opts --color-words
 	'
 }
 
@@ -81,7 +85,7 @@ test_expect_success setup '
 	git config diff.color.func magenta
 '
 
-test_expect_success 'set up pre and post with runs of whitespace' '
+test_expect_success 'setup pre and post with runs of whitespace' '
 	cp pre.simple pre &&
 	cp post.simple post
 '
@@ -101,9 +105,9 @@ test_expect_success 'word diff with runs of whitespace' '
 
 		<GREEN>aeff = aeff * ( aaa )<RESET>
 	EOF
-	word_diff --color-words &&
-	word_diff --word-diff=color &&
-	word_diff --color --word-diff=color
+	diff_with_opts --color-words &&
+	word_diff color &&
+	diff_with_opts --color --word-diff=color
 '
 
 test_expect_success '--word-diff=porcelain' '
@@ -127,7 +131,7 @@ test_expect_success '--word-diff=porcelain' '
 		+aeff = aeff * ( aaa )
 		~
 	EOF
-	word_diff --word-diff=porcelain
+	word_diff porcelain
 '
 
 test_expect_success '--word-diff=plain' '
@@ -145,8 +149,8 @@ test_expect_success '--word-diff=plain' '
 
 		{+aeff = aeff * ( aaa )+}
 	EOF
-	word_diff --word-diff=plain &&
-	word_diff --word-diff=plain --no-color
+	diff_with_opts --word-diff=plain &&
+	word_diff plain --no-color
 '
 
 test_expect_success '--word-diff=plain --color' '
@@ -164,7 +168,7 @@ test_expect_success '--word-diff=plain --color' '
 
 		<GREEN>{+aeff = aeff * ( aaa )+}<RESET>
 	EOF
-	word_diff --word-diff=plain --color
+	word_diff plain --color
 '
 
 test_expect_success 'word diff without context' '
@@ -181,17 +185,17 @@ test_expect_success 'word diff without context' '
 
 		<GREEN>aeff = aeff * ( aaa )<RESET>
 	EOF
-	word_diff --color-words --unified=0
+	diff_with_opts --color-words --unified=0
 '
 
 test_expect_success 'word diff with a regular expression' '
 	cp expect.letter-runs-are-words expect &&
-	word_diff --color-words="[a-z]+"
+	diff_with_opts --color-words="[a-z]+"
 '
 
 test_expect_success 'word diff with zero length matches' '
 	cp expect.letter-runs-are-words expect &&
-	word_diff --color-words="[a-z${LF}]*"
+	diff_with_opts --color-words="[a-z${LF}]*"
 '
 
 test_expect_success 'set up a diff driver' '
@@ -204,12 +208,12 @@ test_expect_success 'set up a diff driver' '
 
 test_expect_success 'option overrides .gitattributes' '
 	cp expect.letter-runs-are-words expect &&
-	word_diff --color-words="[a-z]+"
+	diff_with_opts --color-words="[a-z]+"
 '
 
 test_expect_success 'use regex supplied by driver' '
 	cp expect.non-whitespace-is-word expect &&
-	word_diff --color-words
+	diff_with_opts --color-words
 '
 
 test_expect_success 'set up diff.wordRegex option' '
@@ -218,7 +222,7 @@ test_expect_success 'set up diff.wordRegex option' '
 
 test_expect_success 'command-line overrides config' '
 	cp expect.letter-runs-are-words expect &&
-	word_diff --color-words="[a-z]+"
+	diff_with_opts --color-words="[a-z]+"
 '
 
 test_expect_success 'command-line overrides config: --word-diff-regex' '
@@ -236,12 +240,12 @@ test_expect_success 'command-line overrides config: --word-diff-regex' '
 
 		<GREEN>{+aeff = aeff * ( aaa+}<RESET> )
 	EOF
-	word_diff --color --word-diff-regex="[a-z]+"
+	diff_with_opts --color --word-diff-regex="[a-z]+"
 '
 
 test_expect_success '.gitattributes override config' '
 	cp expect.non-whitespace-is-word expect &&
-	word_diff --color-words
+	diff_with_opts --color-words
 '
 
 test_expect_success 'setup: remove diff driver regex' '
@@ -263,7 +267,7 @@ test_expect_success 'use configured regex' '
 
 		<GREEN>aeff = aeff * ( aaa<RESET> )
 	EOF
-	word_diff --color-words
+	diff_with_opts --color-words
 '
 
 test_expect_success 'test parsing words for newline' '
@@ -279,7 +283,7 @@ test_expect_success 'test parsing words for newline' '
 		<CYAN>@@ -1 +1 @@<RESET>
 		aaa (aaa) <GREEN>aaa<RESET>
 	EOF
-	word_diff --color-words="a+"
+	diff_with_opts --color-words="a+"
 '
 
 test_expect_success 'test when words are only removed at the end' '
@@ -295,7 +299,7 @@ test_expect_success 'test when words are only removed at the end' '
 		<CYAN>@@ -1 +1 @@<RESET>
 		(<RED>:<RESET>
 	EOF
-	word_diff --color-words=.
+	diff_with_opts --color-words=.
 '
 
 test_expect_success '--word-diff=none' '
@@ -312,7 +316,7 @@ test_expect_success '--word-diff=none' '
 		-(:
 		+(
 	EOF
-	word_diff --word-diff=plain --word-diff=none
+	word_diff plain --word-diff=none
 '
 
 test_expect_success 'unset default driver' '
@@ -363,7 +367,7 @@ test_expect_success 'word-diff with diff.sbe' '
 	[-b-]{+c+}
 	EOF
 	test_config diff.suppress-blank-empty true &&
-	word_diff --word-diff=plain
+	word_diff plain
 '
 
 test_expect_success 'word-diff with no newline at EOF' '
@@ -379,7 +383,7 @@ test_expect_success 'word-diff with no newline at EOF' '
 	@@ -1 +1 @@
 	a a [-a-]{+ab+} a a
 	EOF
-	word_diff --word-diff=plain
+	word_diff plain
 '
 
 test_expect_success 'setup history with two files' '
Signature · 1 line
2.43.GIT
#3 lore raw

PATCH 2/2 diff: add 'diff.wordDiff' config option

In reply to Karthik Nayak

The git-diff(1) command supports the --word-diff which allows the users to specify how to delimit word diffs. Provide this option also as a config param 'diff.wordDiff'.

---
 Documentation/config/diff.txt |  4 +++
 diff.c                        | 50 +++++++++++++++++++++++++++--------
 t/t4034-diff-words.sh         | 11 ++++++--
 3 files changed, 52 insertions(+), 13 deletions(-)
Documentation/config/diff.txt +4 -0
index bd5ae0c337..00459beee2 100644
@@ -225,3 +225,7 @@ diff.colorMovedWS::
 	When moved lines are colored using e.g. the `diff.colorMoved` setting,
 	this option controls the `<mode>` how spaces are treated
 	for details of valid modes see '--color-moved-ws' in linkgit:git-diff[1].
+
+diff.wordDiff::
+	Show a word diff, using the `<mode>` to delimit changed words.
+	For details of valid modes see '--word-diff' in linkgit:git-diff[1].
diff.c +39 -11

84 lines not on this page · raw message

t/t4034-diff-words.sh +9 -2
index 4f70aa6e9f..2cc391c339 100755
@@ -56,12 +56,19 @@ diff_with_opts () {
 	post=$(git rev-parse --short $(git hash-object post)) &&
 	test_must_fail git diff --no-index "$@" pre post >output &&
 	test_decode_color <output >output.decrypted &&
-	sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected
+	sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected &&
 	test_cmp expected output.decrypted
 }
 
 word_diff () {
-	diff_with_opts "--word-diff=$1" $(echo "$@" | cut -d' ' -s -f 2-)
+	# Capture the rest of the arguments to passthrough.
+	rest=$(echo "$@" | cut -d' ' -s -f 2-) &&
+	# Test via the config route.
+	git config diff.wordDiff $1 &&
+	diff_with_opts $rest &&
+	git config --unset diff.wordDiff &&
+	# Test via the command option route.
+	diff_with_opts "--word-diff=$1" $rest
 }
 
 test_language_driver () {
Signature · 1 line
2.43.GIT
#4 lore raw

Re: [PATCH 2/2] diff: add 'diff.wordDiff' config option

Quoted 14 lines · Karthik Nayak

The git-diff(1) command supports the --word-diff which allows the users to specify how to delimit word diffs. Provide this option also as a config param 'diff.wordDiff'.

---

diff.c +6 -0
@@ -209,6 +210,23 @@ int git_config_rename(const char *var, const char *value)
+static int parse_word_diff_value(const char *value)
+{
+       if (!value)
+               return -1;
+       else if (!strcmp(value, "plain"))
+               return DIFF_WORDS_PLAIN;

diff.c int git_config_rename(const char *var, const char *value) · line 225

Quoted 10 lines
diff.c +10 -0
+       else if (!strcmp(value, "color")) {
+               return DIFF_WORDS_COLOR;
+       }
+       else if (!strcmp(value, "porcelain"))
+               return DIFF_WORDS_PORCELAIN;
+       else if (!strcmp(value, "none"))
+               return DIFF_WORDS_NONE;
+
+       return -1;
+}

Why is one arm surrounded by curly braces when none of the others are?

#5 lore raw

Re: [PATCH 2/2] diff: add 'diff.wordDiff' config option

Quoted 20 lines · Eric Sunshine
Quoted 18 lines · Karthik Nayak

The git-diff(1) command supports the --word-diff which allows the users to specify how to delimit word diffs. Provide this option also as a config param 'diff.wordDiff'.

---

diff.c +10 -0
@@ -209,6 +210,23 @@ int git_config_rename(const char *var, const char *value)
+static int parse_word_diff_value(const char *value)
+{
+       if (!value)
+               return -1;
+       else if (!strcmp(value, "plain"))
+               return DIFF_WORDS_PLAIN;
+       else if (!strcmp(value, "color")) {
+               return DIFF_WORDS_COLOR;
+       }
+       else if (!strcmp(value, "porcelain"))
Quoted 8 lines

diff.c int git_config_rename(const char *var, const char *value) · line 228

Quoted 6 lines
diff.c +6 -0
+               return DIFF_WORDS_PORCELAIN;
+       else if (!strcmp(value, "none"))
+               return DIFF_WORDS_NONE;
+
+       return -1;
+}

Why is one arm surrounded by curly braces when none of the others are?

Seems like I missed that one, if the patch series is being taken forward, I will fix
it. Thanks

#6 lore raw

Re: [PATCH 2/2] diff: add 'diff.wordDiff' config option

In reply to Karthik Nayak

Hello,

Quoted 16 lines · On Saturday, 2 March 2024 10:57:51 CET Karthik Nayak wrote:

The git-diff(1) command supports the --word-diff which allows the users to specify how to delimit word diffs. Provide this option also as a config param 'diff.wordDiff'.

---
 Documentation/config/diff.txt |  4 +++
 diff.c                        | 50 +++++++++++++++++++++++++++--------
 t/t4034-diff-words.sh         | 11 ++++++--
 3 files changed, 52 insertions(+), 13 deletions(-)
Documentation/config/diff.txt +0 -0
index bd5ae0c337..00459beee2 100644

Documentation/config/diff.txt diff.colorMovedWS:: · line 225

Quoted 1 line
Documentation/config/diff.txt +0 -0
@@ -225,3 +225,7 @@ diff.colorMovedWS::
 	When moved lines are colored using e.g. the `diff.colorMoved` 

setting,

Documentation/config/diff.txt diff.colorMovedWS:: · line 227

Quoted 2 lines
Documentation/config/diff.txt +0 -0
 	this option controls the `<mode>` how spaces are treated
 	for details of valid modes see '--color-moved-ws' in linkgit:git-

diff[1].

Documentation/config/diff.txt diff.colorMovedWS:: · line 231

Quoted 4 lines
Documentation/config/diff.txt +4 -0
+
+diff.wordDiff::
+	Show a word diff, using the `<mode>` to delimit changed words.
+	For details of valid modes see '--word-diff' in linkgit:git-diff[1].

Let's enforce the new formatting rules: placeholders are _emphasized_ and options are verbatim

+
+diff.wordDiff::
+ Show a word diff, using the _<mode>_ to delimit changed words.
+ For details of valid modes see --word-diff in linkgit:git-diff[1].

diff.c int git_config_rename(const char *var, const char

Quoted 13 lines
diff.c +1 -0
index e50def4538..050d83ef85 100644
@@ -69,6 +69,7 @@ static int diff_dirstat_permille_default = 30;
 static struct diff_options default_diff_options;
 static long diff_algorithm;
 static unsigned ws_error_highlight_default = WSEH_NEW;
+static int diff_word_diff_default;
 
 static char diff_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RESET,
@@ -209,6 +210,23 @@ int git_config_rename(const char *var, const char 

*value)

diff.c int git_diff_ui_config(const char *var, const char

Quoted 24 lines
diff.c +17 -0
 	return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0;
 }
 
+static int parse_word_diff_value(const char *value)
+{
+	if (!value)
+		return -1;
+	else if (!strcmp(value, "plain"))
+		return DIFF_WORDS_PLAIN;
+	else if (!strcmp(value, "color")) {
+		return DIFF_WORDS_COLOR;
+	}
+	else if (!strcmp(value, "porcelain"))
+		return DIFF_WORDS_PORCELAIN;
+	else if (!strcmp(value, "none"))
+		return DIFF_WORDS_NONE;
+
+	return -1;
+}
+
 long parse_algorithm_value(const char *value)
 {
 	if (!value)
@@ -452,6 +470,18 @@ int git_diff_ui_config(const char *var, const char 

*value,

diff.c int git_diff_ui_config(const char *var, const char *value,

Quoted 9 lines
diff.c +6 -0
 		return 0;
 	}
 
+	if (!strcmp(var, "diff.worddiff")) {
+		if (!value)
+			return config_error_nonbool(var);
+		diff_word_diff_default = parse_word_diff_value(value);
+		if (diff_word_diff_default < 0)
+			return error(_("unknown value for config '%s': 

%s"),

Thanks for reusing already an already existing translatable string.

diff.c void repo_diff_setup(struct repository *r, struct

Quoted 10 lines
diff.c +6 -0
+				     var, value);
+		if (diff_word_diff_default == DIFF_WORDS_COLOR)
+			diff_use_color_default = 1;
+		return 0;
+	}
+
 	if (git_color_config(var, value, cb) < 0)
 		return -1;
 
@@ -4724,6 +4754,7 @@ void repo_diff_setup(struct repository *r, struct 

diff_options *options)

diff.c static int diff_opt_word_diff(const struct option

Quoted 8 lines
diff.c +1 -0
 	options->use_color = diff_use_color_default;
 	options->detect_rename = diff_detect_rename_default;
 	options->xdl_opts |= diff_algorithm;
+	options->word_diff |= diff_word_diff_default;
 	if (diff_indent_heuristic)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
@@ -5504,21 +5535,18 @@ static int diff_opt_word_diff(const struct option 

*opt,

Quoted 12 lines
diff.c +2 -4
 			      const char *arg, int unset)
 {
 	struct diff_options *options = opt->value;
+	int value;
 
 	BUG_ON_OPT_NEG(unset);
+
 	if (arg) {
-		if (!strcmp(arg, "plain"))
-			options->word_diff = DIFF_WORDS_PLAIN;
-		else if (!strcmp(arg, "color")) {
-			options->use_color = 1;

diff.c static int diff_opt_word_diff(const struct option *opt,

Quoted 10 lines
diff.c +2 -7
-			options->word_diff = DIFF_WORDS_COLOR;
-		}
-		else if (!strcmp(arg, "porcelain"))
-			options->word_diff = DIFF_WORDS_PORCELAIN;
-		else if (!strcmp(arg, "none"))
-			options->word_diff = DIFF_WORDS_NONE;
-		else
+		value = parse_word_diff_value(arg);
+		if (value < 0)
 			return error(_("bad --word-diff argument: 

%s"), arg);

Quoted 24 lines
diff.c +4 -0
+		if (value == DIFF_WORDS_COLOR)
+			options->use_color = 1;
+
+		options->word_diff = value;
 	} else {
 		if (options->word_diff == DIFF_WORDS_NONE)
 			options->word_diff = DIFF_WORDS_PLAIN;
t/t4034-diff-words.sh +2 -2
index 4f70aa6e9f..2cc391c339 100755
@@ -56,12 +56,19 @@ diff_with_opts () {
 	post=$(git rev-parse --short $(git hash-object post)) &&
 	test_must_fail git diff --no-index "$@" pre post >output &&
 	test_decode_color <output >output.decrypted &&
-	sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected
+	sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected &&
 	test_cmp expected output.decrypted
 }
 
 word_diff () {
-	diff_with_opts "--word-diff=$1" $(echo "$@" | cut -d' ' -s -f 2-)
+	# Capture the rest of the arguments to passthrough.

t/t4034-diff-words.sh diff_with_opts () { · line 74

Quoted 10 lines
t/t4034-diff-words.sh +7 -0
+	rest=$(echo "$@" | cut -d' ' -s -f 2-) &&
+	# Test via the config route.
+	git config diff.wordDiff $1 &&
+	diff_with_opts $rest &&
+	git config --unset diff.wordDiff &&
+	# Test via the command option route.
+	diff_with_opts "--word-diff=$1" $rest
 }
 
 test_language_driver () {

Thanks

#7 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

In reply to Karthik Nayak
Quoted 2 lines · Karthik Nayak

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

Is it even be sensible to introduce this configuration variable in the first place? What would this do to users who set this variable and use third-party or their own scripts that run "git diff" under the hood?

The usual answer is "these tools should be using the low-level plumbing commands like diff-files, diff-index, and diff-tree", so I am not worried about it too much myself, and the above is purely the devil's advocate comment.

Having said that, running

	$ git grep -e 'git diff '

in the collection of scripts I use [*] to work on this project, I am reminded that I may have to be a bit more conservative than I currently am about the risk of breaking scripts with the changes like the one being proposed.

The proposed feature also may break those who use the git-prompt and diff-highlight available in conrib/, even though I am not sure how badly they would break, because I only looked at the lines given by this command:

	$ git grep -e 'git diff ' -- \*.sh ':!t/'

and didn't check how the output from 'git diff' is used.

[Footnote]

* They can be seen in the 'todo' branch, if anybody is interested.

#8 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Karthik Nayak

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

Is it even be sensible to introduce this configuration variable in the first place? What would this do to users who set this variable and use third-party or their own scripts that run "git diff" under the hood?

This is definitely a good question to ask. I'm primarily not a user of this option, and this patch series was more of to start this discussion, based on the request. I'm comfortable dropping the patch series too if it doesn't make much sense.

Quoted 20 lines

The usual answer is "these tools should be using the low-level plumbing commands like diff-files, diff-index, and diff-tree", so I am not worried about it too much myself, and the above is purely the devil's advocate comment.

Having said that, running

        $ git grep -e 'git diff '

in the collection of scripts I use [*] to work on this project, I am reminded that I may have to be a bit more conservative than I currently am about the risk of breaking scripts with the changes like the one being proposed.

The proposed feature also may break those who use the git-prompt and diff-highlight available in conrib/, even though I am not sure how badly they would break, because I only looked at the lines given by this command:

Quoted 8 lines
        $ git grep -e 'git diff ' -- \*.sh ':!t/'

and didn't check how the output from 'git diff' is used.

[Footnote]

* They can be seen in the 'todo' branch, if anybody is interested.

Having said that, wouldn't this cause a problem only if the config is set up? Meaning the user must explicitly set diff.wordDiff for their scripts to potentially
break. In that sense, is it a breaking feature?

#9 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Hi

Quoted 12 lines · Karthik Nayak
Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Karthik Nayak

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

Is it even be sensible to introduce this configuration variable in the first place? What would this do to users who set this variable and use third-party or their own scripts that run "git diff" under the hood?

Quoted 4 lines

This is definitely a good question to ask. I'm primarily not a user of this option, and this patch series was more of to start this discussion, based on the request. I'm comfortable dropping the patch series too if it doesn't make much sense.

This looks similar to the discussion from a [stash] topic:

• Proposed introducing config variables which change how git stash push and git stash save behave (what they save)
• Concern about how that could break third-party scripts

Like here it would be opt-in. But the user might have no idea what kind of scripts/programs that they use that happen to use git-stash(1).

(That’s at least how I read the thread)

I guess the concern might be worse for git-stash(1) since it seems very natural to use that command in scripts in order to deal with a working tree that might be in a who-knows condition: just get these things out of the way so I can do what I want.

🔗 [stash]: https://lore.kernel.org/git/[email protected]/

Signature · 1 line
Kristoffer Haugsbakk
#10 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Continuing the digression a bit:

Quoted 5 lines · Kristoffer Haugsbakk

This looks similar to the discussion from a [stash] topic:

• Proposed introducing config variables which change how git stash push and git stash save behave (what they save)
• Concern about how that could break third-party scripts

[snippage]

Quoted 1 line

🔗 [stash]: https://lore.kernel.org/git/[email protected]/

As I see it, the general issue here is the tension between Git commands that are used for scripting -- which ideally should always be plumbing commands -- and those used by end-users.

This tension is relieved somewhat when there *are* separate plumbing commands, such as git diff-index and git diff-tree and so on, or git rev-list vs git log. Unfortunately there are some commands, including git log itself, that have options that are missing from the roughly-equivalent plumbing command, and there are commands (such as git stash and git status) that either do not have, or at one time lacked, plumbing command equivalents or options.

The git status command shows one way out of this problem:
we can *add* --porcelain options. Perhaps every command (or every non-plumbing-only one) should have --porcelain[=<version>].

This doesn't fix the situation today, but provides an obvious future-proofing path.

Chris

#11 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Quoted 8 lines · Chris Torek

This tension is relieved somewhat when there *are* separate plumbing commands, such as git diff-index and git diff-tree and so on, or git rev-list vs git log. Unfortunately there are some commands, including git log itself, that have options that are missing from the roughly-equivalent plumbing command, and there are commands (such as git stash and git status) that either do not have, or at one time lacked, plumbing command equivalents or options.

Yup. It is my pet peeve that more and more contributors got lazy and tweaked only Porcelain commands, without bothering to improve plumbing commands to match, while adding more features during the last decade. Unfortunately there is no easy remedy after such sins have been committed. Once people start using git log in their scripts, it is way too late to tell them to update their scripts to use git log --porcelain. The fact that you need to tell them is an admission that you already broke their scripts.

#12 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Chris Torek

This tension is relieved somewhat when there *are* separate plumbing commands, such as git diff-index and git diff-tree and so on, or git rev-list vs git log. Unfortunately there are some commands, including git log itself, that have options that are missing from the roughly-equivalent plumbing command, and there are commands (such as git stash and git status) that either do not have, or at one time lacked, plumbing command equivalents or options.

Quoted 9 lines

Yup. It is my pet peeve that more and more contributors got lazy and tweaked only Porcelain commands, without bothering to improve plumbing commands to match, while adding more features during the last decade. Unfortunately there is no easy remedy after such sins have been committed. Once people start using git log in their scripts, it is way too late to tell them to update their scripts to use git log --porcelain. The fact that you need to tell them is an admission that you already broke their scripts.

To avoid this request from dieing quietly, I will ask (complain) again. Who's the client for. How important is the human UX?

Even introducing a new cli, 'git-cli-for-humans' it will be abused again for sure. So what's a good way forward? Personally, as I mentioned before, it's in the docs to not script around non-plumbing commands, which gives an opening to the admission. And why is admitting things a bad thing, when it improves things for the human? Even if it hurts.

One could argue 'git3 will break things! Human and machine control is split. Use --porcelain (or plumbing commands) in your scripts or expect breakage from time to time. You have been warned!'

We do in the end want progress, do we not? :)

Olliver

#13 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

Quoted 31 lines · Olliver Schinagl
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Chris Torek

This tension is relieved somewhat when there *are* separate plumbing commands, such as git diff-index and git diff-tree and so on, or git rev-list vs git log. Unfortunately there are some commands, including git log itself, that have options that are missing from the roughly-equivalent plumbing command, and there are commands (such as git stash and git status) that either do not have, or at one time lacked, plumbing command equivalents or options.

Quoted 9 lines

Yup. It is my pet peeve that more and more contributors got lazy and tweaked only Porcelain commands, without bothering to improve plumbing commands to match, while adding more features during the last decade. Unfortunately there is no easy remedy after such sins have been committed. Once people start using git log in their scripts, it is way too late to tell them to update their scripts to use git log --porcelain. The fact that you need to tell them is an admission that you already broke their scripts.

To avoid this request from dieing quietly, I will ask (complain) again. Who's the client for. How important is the human UX?

Even introducing a new cli, 'git-cli-for-humans' it will be abused again for sure. So what's a good way forward? Personally, as I mentioned before, it's in the docs to not script around non-plumbing commands, which gives an opening to the admission. And why is admitting things a bad thing, when it improves things for the human? Even if it hurts.

Quoted 5 lines

One could argue 'git3 will break things! Human and machine control is split. Use --porcelain (or plumbing commands) in your scripts or expect breakage from time to time. You have been warned!'

We do in the end want progress, do we not? :)

Maybe, but just maybe, a possible solution for introducing such new configuration options could be introduce a new category of configuration options, which could be set in the user's git configuration only?

That way, a repository enabling some troublesome configuration option wouldn't cause the user's scripts to break.

#14 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

In reply to Chris Torek
Quoted 16 lines · Chris Torek

Continuing the digression a bit:

Quoted 5 lines · Kristoffer Haugsbakk

This looks similar to the discussion from a [stash] topic:

• Proposed introducing config variables which change how git stash push and git stash save behave (what they save)
• Concern about how that could break third-party scripts

[snippage]

Quoted 1 line

🔗 [stash]: https://lore.kernel.org/git/[email protected]/

As I see it, the general issue here is the tension between Git commands that are used for scripting -- which ideally should always be plumbing commands -- and those used by end-users.

Quoted 8 lines

This tension is relieved somewhat when there *are* separate plumbing commands, such as git diff-index and git diff-tree and so on, or git rev-list vs git log. Unfortunately there are some commands, including git log itself, that have options that are missing from the roughly-equivalent plumbing command, and there are commands (such as git stash and git status) that either do not have, or at one time lacked, plumbing command equivalents or options.

I think you are spot on; and as I mentioned earlier, who is git for? Which commands are for whom. Human or machine. I suppose you can never avoid commands being abused, but should we favor machine abuse for very poor UX for the human? I would say 'absolutly not' but up until now, this has always been the case.

Maybe it comes from Linus's strict 'never break userspace'. But I think the situation is different. We want to enrich the user experience, we are constantly degrading it in favor of machines. Even though the manuals and interwebs are full of 'don't use these commands in scripts, they may break'. In that light, I would say 'lets break it in favor of UX :p

Quoted 4 lines

The git status command shows one way out of this problem:
we can *add* --porcelain options. Perhaps every command (or every non-plumbing-only one) should have --porcelain[=<version>].

That's a fair argument, and makes it clear, however, there's tons of scripts that probably don't do this right now.

Quoted 5 lines

This doesn't fix the situation today, but provides an obvious future-proofing path.

Chris

#15 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

In reply to Karthik Nayak
Quoted 12 lines · Karthik Nayak
Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Karthik Nayak

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

Is it even be sensible to introduce this configuration variable in the first place? What would this do to users who set this variable and use third-party or their own scripts that run "git diff" under the hood?

Quoted 4 lines

This is definitely a good question to ask. I'm primarily not a user of this option, and this patch series was more of to start this discussion, based on the request. I'm comfortable dropping the patch series too if it doesn't make much sense.

As a human user, I would very much like to see this feature :) It helps much to visually distinct things, but git diff sits way to deep in my muscle memory to remember my alias. Also, we have a configuration system to set configuration options for many things.

I wonder though, how many other configuration options we already have, that potentially break 'random scripts' because the user has set it ...

Quoted 34 lines
Quoted 21 lines

The usual answer is "these tools should be using the low-level plumbing commands like diff-files, diff-index, and diff-tree", so I am not worried about it too much myself, and the above is purely the devil's advocate comment.

Having said that, running

         $ git grep -e 'git diff '

in the collection of scripts I use [*] to work on this project, I am reminded that I may have to be a bit more conservative than I currently am about the risk of breaking scripts with the changes like the one being proposed.

The proposed feature also may break those who use the git-prompt and diff-highlight available in conrib/, even though I am not sure how badly they would break, because I only looked at the lines given by this command:

Quoted 8 lines
         $ git grep -e 'git diff ' -- \*.sh ':!t/'

and didn't check how the output from 'git diff' is used.

[Footnote]

* They can be seen in the 'todo' branch, if anybody is interested.

Having said that, wouldn't this cause a problem only if the config is set up? Meaning the user must explicitly set diff.wordDiff for their scripts to potentially
break. In that sense, is it a breaking feature?

#16 lore raw

Re: [PATCH 0/2] Support diff.wordDiff config

In reply to Junio C Hamano

Hey list,

Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Karthik Nayak

This patch series adds the diff.wordDiff config option. This mimics the '--word-diff' option of git-diff(1).

Is it even be sensible to introduce this configuration variable in the first place?

Of course it is :p as a human, I crave it :p

On a slightly more serious note though, I always have to use an alias, or the command line option I cannot use git diff with this as default. From a human UX point of view, this is odd, and we have tons of configuration options to do exactly what is desired, without aliases.

I suppose the deeper discussion would be, do we distinct between user (human) facing options and arguments, and machine facing options and argument (in theory, yes we do; in practice things get abused).

Git is often blamed due to its horrible UX. I think the problem comes from the deeper issue mentioned above. Because things get abused, they can no longer be touched, not even to improve UX for the human.

Quoted 31 lines

What would this do to users who set this variable
and use third-party or their own scripts that run "git diff" under the hood?

The usual answer is "these tools should be using the low-level plumbing commands like diff-files, diff-index, and diff-tree", so I am not worried about it too much myself, and the above is purely the devil's advocate comment.

Having said that, running

	$ git grep -e 'git diff '

in the collection of scripts I use [*] to work on this project, I am reminded that I may have to be a bit more conservative than I currently am about the risk of breaking scripts with the changes like the one being proposed.

The proposed feature also may break those who use the git-prompt and diff-highlight available in conrib/, even though I am not sure how badly they would break, because I only looked at the lines given by this command:

	$ git grep -e 'git diff ' -- \*.sh ':!t/'

and didn't check how the output from 'git diff' is used.

[Footnote]

* They can be seen in the 'todo' branch, if anybody is interested.