git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] diff: add config option relative

From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
Date
May 17, 2020, 02:14 UTC
Message-ID
<20200517021452.GA2114@danh.dev>
In-Reply-To
<20200516194033.GA2252@spk-laptop>
Hi Laurent,
On 2020-05-16 21:40:33+0200, Laurent Arnoud <laurent@spkdev.net> wrote:
> Subject: Re: [PATCH v4] diff: add config option relative
I think the subject should be changed to.
	diff: allow overriding --relative
Show 12 quoted lines
> The `diff.relative` boolean option set to `true` show only changes on
> the current directory and show relative pathnames to the current
> directory.
> 
> Teach --no-relative to override earlier --relative
> 
> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>
> ---
>  Documentation/config/diff.txt   |  4 ++
>  Documentation/diff-options.txt  |  3 ++
>  diff.c                          | 16 ++++--
>  t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++
I think t99?? is used for miscellaneous tests.
To me, diff-relative things should be tested in t4045-diff-relative.sh
Show 13 quoted lines
>  4 files changed, 113 insertions(+), 3 deletions(-)
>  create mode 100755 t/t9904-diff-relative-config.sh
> 
> diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
> index ff09f1cf73..76537c3b0c 100644
> --- a/Documentation/config/diff.txt
> +++ b/Documentation/config/diff.txt
> @@ -105,6 +105,10 @@ diff.mnemonicPrefix::
>  diff.noprefix::
>  	If set, 'git diff' does not show any source or destination prefix.
> 
> +diff.relative::
> +	If set to "true", 'git diff' does not show changes outside of the directory

I think it's better to change "true" to either: 'true' (generated to <em>true</em>, or `true` generated to <code>true<code>

Not sure which one is prefered, though. This file uses both 2 styles.

I _think_ `true` is preferred.
Show 14 quoted lines
> +	and show pathnames relative to the current directory.
> +
>  diff.orderFile::
>  	File indicating how to order files within a diff.
>  	See the '-O' option to linkgit:git-diff[1] for details.
> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
> index bb31f0c42b..1b279904eb 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -651,6 +651,9 @@ ifndef::git-format-patch[]
>  	not in a subdirectory (e.g. in a bare repository), you
>  	can name which subdirectory to make the output relative
>  	to by giving a <path> as an argument.
> +--no-relative::

Please merge this option with `--relative[=<path>]` above. And says something likes:

	`--no-relative` can be used to countermand
	both `diff.relative` and previous `--relative`
Show 11 quoted lines
> @@ -5195,8 +5202,11 @@ static int diff_opt_relative(const struct option *opt,
>  {
>  	struct diff_options *options = opt->value;
> 
> -	BUG_ON_OPT_NEG(unset);
> -	options->flags.relative_name = 1;
> +	if (unset) {
> +		options->flags.relative_name = 0;
> +	} else {
> +		options->flags.relative_name = 1;
> +	}
Can this block be simplified as:
	options->flags.relative_name = !unset;
Show 8 quoted lines
> +check_diff_relative () {
> +	dir=$1
> +	shift
> +	expect=$1
> +	shift
> +	relative_opt=$1
> +	shift
> +	short_blob=$(git rev-parse --short "$(git hash-object subdir/file2)")

I think current practice want to have git hash-object as separated. And all git-related code moved inside test_expect*

diff --git a/t/t9904-diff-relative-config.sh b/t/t9904-diff-relative-config.sh
index 23ab1af5e0..4747647917 100755
--- a/t/t9904-diff-relative-config.sh
+++ b/t/t9904-diff-relative-config.sh
@@ -20,17 +20,18 @@ check_diff_relative () {
 	shift
 	relative_opt=$1
 	shift
-	short_blob=$(git rev-parse --short "$(git hash-object subdir/file2)")
-	cat >expected <<-EOF
-	diff --git a/$expect b/$expect
-	new file mode 100644
-	index 0000000..$short_blob
-	--- /dev/null
-	+++ b/$expect
-	@@ -0,0 +1 @@
-	+other content
-	EOF
-	test_expect_success "config.relative $relative_opt -p $*" "
+	test_expect_success "config.relative $relative_opt -p $* in $dir" "
+		hash=\$(git hash-object subdir/file2) &&
+		short_blob=\$(git rev-parse --short \$hash) &&
+		cat >expected <<-EOF &&
+		diff --git a/$expect b/$expect
+		new file mode 100644
+		index 0000000..\$short_blob
+		--- /dev/null
+		+++ b/$expect
+		@@ -0,0 +1 @@
+		+other content
+		EOF
 		test_config -C $dir diff.relative $relative_opt &&
 		git -C '$dir' diff -p $* HEAD^ >actual &&
 		test_cmp expected actual

> +	short_blob_file1=$(git rev-parse --short "$(git hash-object file1)")
> +	short_blob_file2=$(git rev-parse --short "$(git hash-object subdir/file2)")
> +	cat >expected <<-EOF
> +	diff --git a/file1 b/file1
> +	new file mode 100644
> +	index 0000000..$short_blob_file1
> +	--- /dev/null
> +	+++ b/file1
> +	@@ -0,0 +1 @@
> +	+content
> +	diff --git a/$expect b/$expect
> +	new file mode 100644
> +	index 0000000..$short_blob_file2
> +	--- /dev/null
> +	+++ b/$expect
> +	@@ -0,0 +1 @@
> +	+other content
> +	EOF
> +	cat expected

Above comment also applied here.
And remove this debug cat.
-- 
Danh
Previous: Laurent ArnoudNext: Danh Doan
Message 10 of 39 in “diff: add config option relative”
  1. diff: add config option relativeLaurent Arnoud, May 15, 2020
  2. Philip OakleyMay 15, 2020
  3. Laurent ArnoudMay 16, 2020
  4. brian m. carlsonMay 15, 2020
  5. Junio C HamanoMay 16, 2020
  6. Laurent ArnoudMay 16, 2020
  7. Laurent ArnoudMay 16, 2020
  8. Phillip WoodMay 16, 2020
  9. Laurent ArnoudMay 16, 2020
  10. Đoàn Trần Công DanhMay 17, 2020
  11. Danh DoanMay 17, 2020
  12. Junio C HamanoMay 17, 2020
  13. Laurent ArnoudMay 18, 2020
  14. Shourya ShuklaMay 18, 2020
  15. Đoàn Trần Công DanhMay 18, 2020
  16. Laurent ArnoudMay 18, 2020
  17. Đoàn Trần Công DanhMay 18, 2020
  18. Junio C HamanoMay 18, 2020
  19. Đoàn Trần Công DanhMay 18, 2020
  20. Junio C HamanoMay 18, 2020
  21. Đoàn Trần Công DanhMay 19, 2020
  22. Junio C HamanoMay 19, 2020
  23. diff: add config option relativeLaurent Arnoud, May 19, 2020
  24. Đoàn Trần Công DanhMay 19, 2020
  25. diff: add config option relativeLaurent Arnoud, May 22, 2020
  26. Đoàn Trần Công DanhMay 23, 2020
  27. Laurent ArnoudMay 22, 2020
  28. Junio C HamanoMay 18, 2020
  29. Laurent ArnoudMay 18, 2020
  30. Junio C HamanoMay 18, 2020
  31. Junio C HamanoMay 18, 2020
  32. Eric SunshineMay 18, 2020
  33. Đoàn Trần Công DanhMay 18, 2020
  34. Junio C HamanoMay 18, 2020
  35. Laurent ArnoudMay 18, 2020
  36. Eric SunshineMay 18, 2020
  37. Laurent ArnoudMay 18, 2020
  38. Laurent ArnoudMay 18, 2020
  39. Junio C HamanoMay 17, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.