{"thread":{"id":"53479","subject":"[PATCH] diff: add config option relative","startedAt":"2020-05-15T16:04:03Z","lastAt":"2020-05-23T02:14:42Z","messageCount":39,"participants":["Laurent Arnoud","Philip Oakley","brian m. carlson","Junio C Hamano","Phillip Wood","Đoàn Trần Công Danh","Danh Doan","Shourya Shukla","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"397890","messageId":"20200515155706.GA1165062@spk-laptop","threadId":"53479","inReplyTo":null,"subject":"[PATCH] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-15T15:57:06Z","receivedAt":"2020-05-15T16:04:03Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` to show only changes on the\ncurrent directory and show relative pathnames.\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt   |  4 +++\n diff.c                          |  7 +++++\n t/t9904-diff-relative-config.sh | 48 +++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+)\n create mode 100755 t/t9904-diff-relative-config.sh\n\ndiff --git Documentation/config/diff.txt Documentation/config/diff.txt\nindex ff09f1cf73..1d311358d8 100644\n--- Documentation/config/diff.txt\n+++ Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n \n+diff.relative::\n+\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git diff.c diff.c\nindex d1ad6a3c4a..24b7a0ae08 100644\n--- diff.c\n+++ diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \t\toptions->b_prefix = \"b/\";\n \t}\n \n+\toptions->flags.relative_name = diff_relative;\n+\n \toptions->color_moved = diff_color_moved_default;\n \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n \ndiff --git t/t9904-diff-relative-config.sh t/t9904-diff-relative-config.sh\nnew file mode 100755\nindex 0000000000..a92d53ca25\n--- /dev/null\n+++ t/t9904-diff-relative-config.sh\n@@ -0,0 +1,48 @@\n+#!/bin/sh\n+\n+test_description='config diff.relative'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tgit commit --allow-empty -m empty &&\n+\techo content >file1 &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add . &&\n+\tgit commit -m one\n+'\n+\n+check_diff () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\ttest_expect_success \"-p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff . file2 false --relative=subdir/\n+check_diff . file2 false --relative=subdir\n+check_diff . file2 true --relative=subdir/\n+check_diff . file2 true --relative=subdir\n+check_diff subdir file2 false --relative\n+check_diff subdir file2 true --relative\n+check_diff subdir file2 true\n+\n+test_done\n-- \n2.26.2\n"},{"id":"397944","messageId":"baa06609-11fe-28e7-2b8b-8590b9e37104@iee.email","threadId":"53479","inReplyTo":"20200515155706.GA1165062@spk-laptop","subject":"Re: [PATCH] diff: add config option relative","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2020-05-15T22:22:53Z","receivedAt":"2020-05-15T22:22:57Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Laurent,\n\nOn 15/05/2020 16:57, Laurent Arnoud wrote:\n> The `diff.relative` boolean option set to `true` to show only changes on the\n> current directory and show relative pathnames.\n>\n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n> ---\n>  Documentation/config/diff.txt   |  4 +++\n>  diff.c                          |  7 +++++\n>  t/t9904-diff-relative-config.sh | 48 +++++++++++++++++++++++++++++++++\n>  3 files changed, 59 insertions(+)\n>  create mode 100755 t/t9904-diff-relative-config.sh\n>\n> diff --git Documentation/config/diff.txt Documentation/config/diff.txt\n> index ff09f1cf73..1d311358d8 100644\n> --- Documentation/config/diff.txt\n> +++ Documentation/config/diff.txt\n> @@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n>  diff.noprefix::\n>  \tIf set, 'git diff' does not show any source or destination prefix.\n>  \n> +diff.relative::\n> +\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n> +\tand show pathnames relative.\n\nThis last part sounded stilted. Maybe \"and shows pathnames relative to\nthe current directory\", assuming I've understood what it was meant to\nsay (and possible the same change in the commit message)\n\nPhilip\n> +\n>  diff.orderFile::\n>  \tFile indicating how to order files within a diff.\n>  \tSee the '-O' option to linkgit:git-diff[1] for details.\n> diff --git diff.c diff.c\n> index d1ad6a3c4a..24b7a0ae08 100644\n> --- diff.c\n> +++ diff.c\n> @@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n>  int diff_auto_refresh_index = 1;\n>  static int diff_mnemonic_prefix;\n>  static int diff_no_prefix;\n> +static int diff_relative;\n>  static int diff_stat_graph_width;\n>  static int diff_dirstat_permille_default = 30;\n>  static struct diff_options default_diff_options;\n> @@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n>  \t\tdiff_no_prefix = git_config_bool(var, value);\n>  \t\treturn 0;\n>  \t}\n> +\tif (!strcmp(var, \"diff.relative\")) {\n> +\t\tdiff_relative = git_config_bool(var, value);\n> +\t\treturn 0;\n> +\t}\n>  \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n>  \t\tdiff_stat_graph_width = git_config_int(var, value);\n>  \t\treturn 0;\n> @@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n>  \t\toptions->b_prefix = \"b/\";\n>  \t}\n>  \n> +\toptions->flags.relative_name = diff_relative;\n> +\n>  \toptions->color_moved = diff_color_moved_default;\n>  \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n>  \n> diff --git t/t9904-diff-relative-config.sh t/t9904-diff-relative-config.sh\n> new file mode 100755\n> index 0000000000..a92d53ca25\n> --- /dev/null\n> +++ t/t9904-diff-relative-config.sh\n> @@ -0,0 +1,48 @@\n> +#!/bin/sh\n> +\n> +test_description='config diff.relative'\n> +\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'setup' '\n> +\tgit commit --allow-empty -m empty &&\n> +\techo content >file1 &&\n> +\tmkdir subdir &&\n> +\techo other content >subdir/file2 &&\n> +\tgit add . &&\n> +\tgit commit -m one\n> +'\n> +\n> +check_diff () {\n> +\tdir=$1\n> +\tshift\n> +\texpect=$1\n> +\tshift\n> +\trelative_opt=$1\n> +\tshift\n> +\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n> +\tcat >expected <<-EOF\n> +\tdiff --git a/$expect b/$expect\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob\n> +\t--- /dev/null\n> +\t+++ b/$expect\n> +\t@@ -0,0 +1 @@\n> +\t+other content\n> +\tEOF\n> +\ttest_expect_success \"-p $*\" \"\n> +\t\ttest_config -C $dir diff.relative $relative_opt &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n> +\t\ttest_cmp expected actual\n> +\t\"\n> +}\n> +\n> +check_diff . file2 false --relative=subdir/\n> +check_diff . file2 false --relative=subdir\n> +check_diff . file2 true --relative=subdir/\n> +check_diff . file2 true --relative=subdir\n> +check_diff subdir file2 false --relative\n> +check_diff subdir file2 true --relative\n> +check_diff subdir file2 true\n> +\n> +test_done\n\n"},{"id":"397949","messageId":"20200515233130.GC6362@camp.crustytoothpaste.net","threadId":"53479","inReplyTo":"20200515155706.GA1165062@spk-laptop","subject":"Re: [PATCH] diff: add config option relative","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-05-15T23:31:30Z","receivedAt":"2020-05-15T23:32:07Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-05-15 at 15:57:06, Laurent Arnoud wrote:\n> The `diff.relative` boolean option set to `true` to show only changes on the\n> current directory and show relative pathnames.\n\nUsually when we implement configuration settings like this, we implement\nan option value, such as --no-relative, so that users or scripting tools\ncan disable this feature if they need to.  However, I don't see that in\nthis series.  Would adding such a feature be possible?\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"397951","messageId":"xmqq1rnk923o.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200515233130.GC6362@camp.crustytoothpaste.net","subject":"Re: [PATCH] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-16T00:04:43Z","receivedAt":"2020-05-16T00:04:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On 2020-05-15 at 15:57:06, Laurent Arnoud wrote:\n>> The `diff.relative` boolean option set to `true` to show only changes on the\n>> current directory and show relative pathnames.\n>\n> Usually when we implement configuration settings like this, we implement\n> an option value, such as --no-relative, so that users or scripting tools\n> can disable this feature if they need to.  However, I don't see that in\n> this series.  Would adding such a feature be possible?\n\nI think I saw a variant that does have --[no-]foobar support on the\nlist, but I may be hallucinating.  You definitely would want it, or\nyou've broken \"format-patch\" forever without a knob to countermand\nthe configuration (well, you can still say \"git -c diff.foobar=no\"\nbut that's kind of cheating).\n\n"},{"id":"397979","messageId":"20200516173052.GA29974@spk-laptop","threadId":"53479","inReplyTo":"baa06609-11fe-28e7-2b8b-8590b9e37104@iee.email","subject":"Re: [PATCH] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-16T17:30:52Z","receivedAt":"2020-05-16T17:31:00Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"Hi Philip,\n\nOn Fri, May 15, 2020 at 11:22:53PM +0100, Philip Oakley wrote:\n> On 15/05/2020 16:57, Laurent Arnoud wrote:\n> > +diff.relative::\n> > +\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n> > +\tand show pathnames relative.\n> \n> This last part sounded stilted. Maybe \"and shows pathnames relative to\n> the current directory\", assuming I've understood what it was meant to\n> say (and possible the same change in the commit message)\n\nYes that what it was meant by this, I will submit a patch with your suggestion\n\nCheers\n\n-- \nLaurent\n"},{"id":"397980","messageId":"20200516173518.GA34961@spk-laptop","threadId":"53479","inReplyTo":"xmqq1rnk923o.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-16T17:35:18Z","receivedAt":"2020-05-16T17:35:25Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"On Fri, May 15, 2020 at 05:04:43PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > On 2020-05-15 at 15:57:06, Laurent Arnoud wrote:\n> >> The `diff.relative` boolean option set to `true` to show only changes on the\n> >> current directory and show relative pathnames.\n> >\n> > Usually when we implement configuration settings like this, we implement\n> > an option value, such as --no-relative, so that users or scripting tools\n> > can disable this feature if they need to.  However, I don't see that in\n> > this series.  Would adding such a feature be possible?\n> \n> I think I saw a variant that does have --[no-]foobar support on the\n> list, but I may be hallucinating.  You definitely would want it, or\n> you've broken \"format-patch\" forever without a knob to countermand\n> the configuration (well, you can still say \"git -c diff.foobar=no\"\n> but that's kind of cheating).\n\nYes I've submitted a v2 patch with the `--no-relative` I will send a v3 to this\nthread for review\n\n-- \nLaurent\n"},{"id":"397981","messageId":"20200516173828.GB34961@spk-laptop","threadId":"53479","inReplyTo":"xmqq1rnk923o.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-16T17:38:28Z","receivedAt":"2020-05-16T17:38:33Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` show only changes on\nthe current directory and show relative pathnames to the current\ndirectory.\n\nTeach --no-relative to override earlier --relative\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt   |  4 ++\n Documentation/diff-options.txt  |  2 +\n diff.c                          | 10 ++++\n t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++\n 4 files changed, 109 insertions(+)\n create mode 100755 t/t9904-diff-relative-config.sh\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..76537c3b0c 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n\n+diff.relative::\n+\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..fdc5aefa37 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n+--no-relative::\n+\tTurn off relative pathnames and include all changes in the repository.\n endif::git-format-patch[]\n\n -a::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..c4dcf01ec0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \t\toptions->b_prefix = \"b/\";\n \t}\n\n+\toptions->flags.relative_name = diff_relative;\n+\n \toptions->color_moved = diff_color_moved_default;\n \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n\n@@ -5494,6 +5501,9 @@ static void prep_parse_options(struct diff_options *options)\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n+\t\tOPT_SET_INT_F(0, \"no-relative\", &options->flags.relative_name,\n+\t\t\t      N_(\"disable diff.relative config option\"),\n+\t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\n \t\tOPT_BOOL('R', NULL, &options->flags.reverse_diff,\ndiff --git a/t/t9904-diff-relative-config.sh b/t/t9904-diff-relative-config.sh\nnew file mode 100755\nindex 0000000000..23ab1af5e0\n--- /dev/null\n+++ b/t/t9904-diff-relative-config.sh\n@@ -0,0 +1,93 @@\n+#!/bin/sh\n+\n+test_description='config diff.relative'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tgit commit --allow-empty -m empty &&\n+\techo content >file1 &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add . &&\n+\tgit commit -m one\n+'\n+\n+check_diff_relative () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob_file1=$(git rev-parse --short \"$(git hash-object file1)\")\n+\tshort_blob_file2=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/file1 b/file1\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file1\n+\t--- /dev/null\n+\t+++ b/file1\n+\t@@ -0,0 +1 @@\n+\t+content\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file2\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\tcat expected\n+\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_relative . file2 false --relative=subdir/\n+check_diff_relative . file2 false --relative=subdir\n+check_diff_relative . file2 true --relative=subdir/\n+check_diff_relative . file2 true --relative=subdir\n+check_diff_relative subdir file2 false --relative\n+check_diff_relative subdir file2 true --relative\n+check_diff_relative subdir file2 true\n+check_diff_relative subdir file2 false --no-relative --relative\n+check_diff_relative subdir file2 true --no-relative --relative\n+check_diff_relative . file2 false --no-relative --relative=subdir\n+check_diff_relative . file2 true --no-relative --relative=subdir\n+\n+check_diff_no_relative . subdir/file2 false\n+check_diff_no_relative . subdir/file2 true --no-relative\n+check_diff_no_relative . subdir/file2 false --no-relative\n+check_diff_no_relative subdir subdir/file2 false\n+check_diff_no_relative subdir subdir/file2 true --no-relative\n+check_diff_no_relative subdir subdir/file2 false --no-relative\n+\n+test_done\n--\n2.26.2\n"},{"id":"397982","messageId":"92cb6302-09a8-6780-9398-890b1e766680@gmail.com","threadId":"53479","inReplyTo":"20200516173828.GB34961@spk-laptop","subject":"Re: [PATCH v3] diff: add config option relative","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-05-16T18:33:42Z","receivedAt":"2020-05-16T18:33:48Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Laurent\n\nOn 16/05/2020 18:38, Laurent Arnoud wrote:\n> The `diff.relative` boolean option set to `true` show only changes on\n> the current directory and show relative pathnames to the current\n> directory.\n> \n> Teach --no-relative to override earlier --relative\n> \n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n> ---\n>   Documentation/config/diff.txt   |  4 ++\n>   Documentation/diff-options.txt  |  2 +\n>   diff.c                          | 10 ++++\n>   t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++\n>   4 files changed, 109 insertions(+)\n>   create mode 100755 t/t9904-diff-relative-config.sh\n> \n> diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\n> index ff09f1cf73..76537c3b0c 100644\n> --- a/Documentation/config/diff.txt\n> +++ b/Documentation/config/diff.txt\n> @@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n>   diff.noprefix::\n>   \tIf set, 'git diff' does not show any source or destination prefix.\n> \n> +diff.relative::\n> +\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n> +\tand show pathnames relative to the current directory.\n> +\n>   diff.orderFile::\n>   \tFile indicating how to order files within a diff.\n>   \tSee the '-O' option to linkgit:git-diff[1] for details.\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index bb31f0c42b..fdc5aefa37 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n>   \tnot in a subdirectory (e.g. in a bare repository), you\n>   \tcan name which subdirectory to make the output relative\n>   \tto by giving a <path> as an argument.\n> +--no-relative::\n> +\tTurn off relative pathnames and include all changes in the repository.\n\nIt might be helpful to mention that this is the default and this option \nexists to override the config setting\n\n>   endif::git-format-patch[]\n> \n>   -a::\n> diff --git a/diff.c b/diff.c\n> index d1ad6a3c4a..c4dcf01ec0 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n>   int diff_auto_refresh_index = 1;\n>   static int diff_mnemonic_prefix;\n>   static int diff_no_prefix;\n> +static int diff_relative;\n>   static int diff_stat_graph_width;\n>   static int diff_dirstat_permille_default = 30;\n>   static struct diff_options default_diff_options;\n> @@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n>   \t\tdiff_no_prefix = git_config_bool(var, value);\n>   \t\treturn 0;\n>   \t}\n> +\tif (!strcmp(var, \"diff.relative\")) {\n> +\t\tdiff_relative = git_config_bool(var, value);\n> +\t\treturn 0;\n> +\t}\n>   \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n>   \t\tdiff_stat_graph_width = git_config_int(var, value);\n>   \t\treturn 0;\n> @@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n>   \t\toptions->b_prefix = \"b/\";\n>   \t}\n> \n> +\toptions->flags.relative_name = diff_relative;\n> +\n>   \toptions->color_moved = diff_color_moved_default;\n>   \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n> \n> @@ -5494,6 +5501,9 @@ static void prep_parse_options(struct diff_options *options)\n>   \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n>   \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n>   \t\t\t       diff_opt_relative),\n> +\t\tOPT_SET_INT_F(0, \"no-relative\", &options->flags.relative_name,\n> +\t\t\t      N_(\"disable diff.relative config option\"),\n> +\t\t\t      0, PARSE_OPT_NONEG),\n\nRather than adding a new option, it would be better to modify the \nexisting --relative option. If you remove PARSE_OPT_NONEG from the \ndeclaration above it will support --no-relative. You will also need to \nmodify diff_opt_relative() to handle clearing the option.\n\nBest Wishes\n\nPhillip\n\n>   \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n>   \t\t\t N_(\"treat all files as text\")),\n>   \t\tOPT_BOOL('R', NULL, &options->flags.reverse_diff,\n> diff --git a/t/t9904-diff-relative-config.sh b/t/t9904-diff-relative-config.sh\n> new file mode 100755\n> index 0000000000..23ab1af5e0\n> --- /dev/null\n> +++ b/t/t9904-diff-relative-config.sh\n> @@ -0,0 +1,93 @@\n> +#!/bin/sh\n> +\n> +test_description='config diff.relative'\n> +\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'setup' '\n> +\tgit commit --allow-empty -m empty &&\n> +\techo content >file1 &&\n> +\tmkdir subdir &&\n> +\techo other content >subdir/file2 &&\n> +\tgit add . &&\n> +\tgit commit -m one\n> +'\n> +\n> +check_diff_relative () {\n> +\tdir=$1\n> +\tshift\n> +\texpect=$1\n> +\tshift\n> +\trelative_opt=$1\n> +\tshift\n> +\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n> +\tcat >expected <<-EOF\n> +\tdiff --git a/$expect b/$expect\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob\n> +\t--- /dev/null\n> +\t+++ b/$expect\n> +\t@@ -0,0 +1 @@\n> +\t+other content\n> +\tEOF\n> +\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n> +\t\ttest_config -C $dir diff.relative $relative_opt &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n> +\t\ttest_cmp expected actual\n> +\t\"\n> +}\n> +\n> +check_diff_no_relative () {\n> +\tdir=$1\n> +\tshift\n> +\texpect=$1\n> +\tshift\n> +\trelative_opt=$1\n> +\tshift\n> +\tshort_blob_file1=$(git rev-parse --short \"$(git hash-object file1)\")\n> +\tshort_blob_file2=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n> +\tcat >expected <<-EOF\n> +\tdiff --git a/file1 b/file1\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob_file1\n> +\t--- /dev/null\n> +\t+++ b/file1\n> +\t@@ -0,0 +1 @@\n> +\t+content\n> +\tdiff --git a/$expect b/$expect\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob_file2\n> +\t--- /dev/null\n> +\t+++ b/$expect\n> +\t@@ -0,0 +1 @@\n> +\t+other content\n> +\tEOF\n> +\tcat expected\n> +\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n> +\t\ttest_config -C $dir diff.relative $relative_opt &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n> +\t\ttest_cmp expected actual\n> +\t\"\n> +}\n> +\n> +check_diff_relative . file2 false --relative=subdir/\n> +check_diff_relative . file2 false --relative=subdir\n> +check_diff_relative . file2 true --relative=subdir/\n> +check_diff_relative . file2 true --relative=subdir\n> +check_diff_relative subdir file2 false --relative\n> +check_diff_relative subdir file2 true --relative\n> +check_diff_relative subdir file2 true\n> +check_diff_relative subdir file2 false --no-relative --relative\n> +check_diff_relative subdir file2 true --no-relative --relative\n> +check_diff_relative . file2 false --no-relative --relative=subdir\n> +check_diff_relative . file2 true --no-relative --relative=subdir\n> +\n> +check_diff_no_relative . subdir/file2 false\n> +check_diff_no_relative . subdir/file2 true --no-relative\n> +check_diff_no_relative . subdir/file2 false --no-relative\n> +check_diff_no_relative subdir subdir/file2 false\n> +check_diff_no_relative subdir subdir/file2 true --no-relative\n> +check_diff_no_relative subdir subdir/file2 false --no-relative\n> +\n> +test_done\n> --\n> 2.26.2\n> \n"},{"id":"397986","messageId":"20200516194033.GA2252@spk-laptop","threadId":"53479","inReplyTo":"92cb6302-09a8-6780-9398-890b1e766680@gmail.com","subject":"Re: [PATCH v4] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-16T19:40:33Z","receivedAt":"2020-05-16T19:40:51Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` show only changes on\nthe current directory and show relative pathnames to the current\ndirectory.\n\nTeach --no-relative to override earlier --relative\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt   |  4 ++\n Documentation/diff-options.txt  |  3 ++\n diff.c                          | 16 ++++--\n t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++\n 4 files changed, 113 insertions(+), 3 deletions(-)\n create mode 100755 t/t9904-diff-relative-config.sh\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..76537c3b0c 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n\n+diff.relative::\n+\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..1b279904eb 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -651,6 +651,9 @@ ifndef::git-format-patch[]\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n+--no-relative::\n+\tTurn off relative pathnames and include all changes in the repository.\n+\tThis can be used to override configuration settings `diff.relative`.\n endif::git-format-patch[]\n\n -a::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..af28e39785 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \t\toptions->b_prefix = \"b/\";\n \t}\n\n+\toptions->flags.relative_name = diff_relative;\n+\n \toptions->color_moved = diff_color_moved_default;\n \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n\n@@ -5195,8 +5202,11 @@ static int diff_opt_relative(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n\n-\tBUG_ON_OPT_NEG(unset);\n-\toptions->flags.relative_name = 1;\n+\tif (unset) {\n+\t\toptions->flags.relative_name = 0;\n+\t} else {\n+\t\toptions->flags.relative_name = 1;\n+\t}\n \tif (arg)\n \t\toptions->prefix = arg;\n \treturn 0;\n@@ -5492,7 +5502,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_GROUP(N_(\"Other diff options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n-\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\ndiff --git a/t/t9904-diff-relative-config.sh b/t/t9904-diff-relative-config.sh\nnew file mode 100755\nindex 0000000000..23ab1af5e0\n--- /dev/null\n+++ b/t/t9904-diff-relative-config.sh\n@@ -0,0 +1,93 @@\n+#!/bin/sh\n+\n+test_description='config diff.relative'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tgit commit --allow-empty -m empty &&\n+\techo content >file1 &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add . &&\n+\tgit commit -m one\n+'\n+\n+check_diff_relative () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob_file1=$(git rev-parse --short \"$(git hash-object file1)\")\n+\tshort_blob_file2=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/file1 b/file1\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file1\n+\t--- /dev/null\n+\t+++ b/file1\n+\t@@ -0,0 +1 @@\n+\t+content\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file2\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\tcat expected\n+\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_relative . file2 false --relative=subdir/\n+check_diff_relative . file2 false --relative=subdir\n+check_diff_relative . file2 true --relative=subdir/\n+check_diff_relative . file2 true --relative=subdir\n+check_diff_relative subdir file2 false --relative\n+check_diff_relative subdir file2 true --relative\n+check_diff_relative subdir file2 true\n+check_diff_relative subdir file2 false --no-relative --relative\n+check_diff_relative subdir file2 true --no-relative --relative\n+check_diff_relative . file2 false --no-relative --relative=subdir\n+check_diff_relative . file2 true --no-relative --relative=subdir\n+\n+check_diff_no_relative . subdir/file2 false\n+check_diff_no_relative . subdir/file2 true --no-relative\n+check_diff_no_relative . subdir/file2 false --no-relative\n+check_diff_no_relative subdir subdir/file2 false\n+check_diff_no_relative subdir subdir/file2 true --no-relative\n+check_diff_no_relative subdir subdir/file2 false --no-relative\n+\n+test_done\n--\n2.26.2\n"},{"id":"397991","messageId":"20200517021452.GA2114@danh.dev","threadId":"53479","inReplyTo":"20200516194033.GA2252@spk-laptop","subject":"Re: [PATCH v4] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-17T02:14:52Z","receivedAt":"2020-05-17T02:14:57Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Hi Laurent,\n\nOn 2020-05-16 21:40:33+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n> Subject: Re: [PATCH v4] diff: add config option relative\n\nI think the subject should be changed to.\n\n\tdiff: allow overriding --relative\n\n> The `diff.relative` boolean option set to `true` show only changes on\n> the current directory and show relative pathnames to the current\n> directory.\n> \n> Teach --no-relative to override earlier --relative\n> \n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n> ---\n>  Documentation/config/diff.txt   |  4 ++\n>  Documentation/diff-options.txt  |  3 ++\n>  diff.c                          | 16 ++++--\n>  t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++\n\nI think t99?? is used for miscellaneous tests.\n\nTo me, diff-relative things should be tested in t4045-diff-relative.sh\n\n>  4 files changed, 113 insertions(+), 3 deletions(-)\n>  create mode 100755 t/t9904-diff-relative-config.sh\n> \n> diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\n> index ff09f1cf73..76537c3b0c 100644\n> --- a/Documentation/config/diff.txt\n> +++ b/Documentation/config/diff.txt\n> @@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n>  diff.noprefix::\n>  \tIf set, 'git diff' does not show any source or destination prefix.\n> \n> +diff.relative::\n> +\tIf set to \"true\", 'git diff' does not show changes outside of the directory\n\nI think it's better to change \"true\" to either:\n'true' (generated to <em>true</em>, or\n`true` generated to <code>true<code>\n\nNot sure which one is prefered, though.\nThis file uses both 2 styles.\n\nI _think_ `true` is preferred.\n\n> +\tand show pathnames relative to the current directory.\n> +\n>  diff.orderFile::\n>  \tFile indicating how to order files within a diff.\n>  \tSee the '-O' option to linkgit:git-diff[1] for details.\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index bb31f0c42b..1b279904eb 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -651,6 +651,9 @@ ifndef::git-format-patch[]\n>  \tnot in a subdirectory (e.g. in a bare repository), you\n>  \tcan name which subdirectory to make the output relative\n>  \tto by giving a <path> as an argument.\n> +--no-relative::\n\nPlease merge this option with `--relative[=<path>]` above.\nAnd says something likes:\n\n\t`--no-relative` can be used to countermand\n\tboth `diff.relative` and previous `--relative`\n\n> @@ -5195,8 +5202,11 @@ static int diff_opt_relative(const struct option *opt,\n>  {\n>  \tstruct diff_options *options = opt->value;\n> \n> -\tBUG_ON_OPT_NEG(unset);\n> -\toptions->flags.relative_name = 1;\n> +\tif (unset) {\n> +\t\toptions->flags.relative_name = 0;\n> +\t} else {\n> +\t\toptions->flags.relative_name = 1;\n> +\t}\n\nCan this block be simplified as:\n\n\toptions->flags.relative_name = !unset;\n\n> +check_diff_relative () {\n> +\tdir=$1\n> +\tshift\n> +\texpect=$1\n> +\tshift\n> +\trelative_opt=$1\n> +\tshift\n> +\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n\nI think current practice want to have git hash-object as separated.\nAnd all git-related code moved inside test_expect*\n\ndiff --git a/t/t9904-diff-relative-config.sh b/t/t9904-diff-relative-config.sh\nindex 23ab1af5e0..4747647917 100755\n--- a/t/t9904-diff-relative-config.sh\n+++ b/t/t9904-diff-relative-config.sh\n@@ -20,17 +20,18 @@ check_diff_relative () {\n \tshift\n \trelative_opt=$1\n \tshift\n-\tshort_blob=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n-\tcat >expected <<-EOF\n-\tdiff --git a/$expect b/$expect\n-\tnew file mode 100644\n-\tindex 0000000..$short_blob\n-\t--- /dev/null\n-\t+++ b/$expect\n-\t@@ -0,0 +1 @@\n-\t+other content\n-\tEOF\n-\ttest_expect_success \"config.relative $relative_opt -p $*\" \"\n+\ttest_expect_success \"config.relative $relative_opt -p $* in $dir\" \"\n+\t\thash=\\$(git hash-object subdir/file2) &&\n+\t\tshort_blob=\\$(git rev-parse --short \\$hash) &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n \t\ttest_config -C $dir diff.relative $relative_opt &&\n \t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n \t\ttest_cmp expected actual\n\n> +\tshort_blob_file1=$(git rev-parse --short \"$(git hash-object file1)\")\n> +\tshort_blob_file2=$(git rev-parse --short \"$(git hash-object subdir/file2)\")\n> +\tcat >expected <<-EOF\n> +\tdiff --git a/file1 b/file1\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob_file1\n> +\t--- /dev/null\n> +\t+++ b/file1\n> +\t@@ -0,0 +1 @@\n> +\t+content\n> +\tdiff --git a/$expect b/$expect\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob_file2\n> +\t--- /dev/null\n> +\t+++ b/$expect\n> +\t@@ -0,0 +1 @@\n> +\t+other content\n> +\tEOF\n> +\tcat expected\n\nAbove comment also applied here.\nAnd remove this debug cat.\n\n-- \nDanh\n"},{"id":"397999","messageId":"67A0CBED-16A8-4DD1-9F79-1495FC242A0C@gmail.com","threadId":"53479","inReplyTo":"20200517021452.GA2114@danh.dev","subject":"Re: [PATCH v4] diff: add config option relative","fromName":"Danh Doan","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-17T02:48:03Z","receivedAt":"2020-05-17T02:48:13Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"\n\n> On May 17, 2020, at 09:14, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:\n> \n> ﻿Hi Laurent,\n> \n>> On 2020-05-16 21:40:33+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n>> Subject: Re: [PATCH v4] diff: add config option relative\n> \n> I think the subject should be changed to.\n> \n>    diff: allow overriding --relative\n\nI feel stupid about this now.\nPlease disregard my comment about subject."},{"id":"398008","messageId":"xmqqpnb27g76.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"92cb6302-09a8-6780-9398-890b1e766680@gmail.com","subject":"Re: [PATCH v3] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-17T15:07:41Z","receivedAt":"2020-05-17T15:07:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n>> @@ -5494,6 +5501,9 @@ static void prep_parse_options(struct diff_options *options)\n>>   \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n>>   \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n>>   \t\t\t       diff_opt_relative),\n>> +\t\tOPT_SET_INT_F(0, \"no-relative\", &options->flags.relative_name,\n>> +\t\t\t      N_(\"disable diff.relative config option\"),\n>> +\t\t\t      0, PARSE_OPT_NONEG),\n>\n> Rather than adding a new option, it would be better to modify the\n> existing --relative option. If you remove PARSE_OPT_NONEG from the\n> declaration above it will support --no-relative. You will also need to\n> modify diff_opt_relative() to handle clearing the option.\n\nExcellent.\n"},{"id":"398009","messageId":"xmqqlflq7fyd.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200517021452.GA2114@danh.dev","subject":"Re: [PATCH v4] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-17T15:12:58Z","receivedAt":"2020-05-17T15:13:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n>>  Documentation/config/diff.txt   |  4 ++\n>>  Documentation/diff-options.txt  |  3 ++\n>>  diff.c                          | 16 ++++--\n>>  t/t9904-diff-relative-config.sh | 93 +++++++++++++++++++++++++++++++++\n>\n> I think t99?? is used for miscellaneous tests.\n>\n> To me, diff-relative things should be tested in t4045-diff-relative.sh\n\nRight.  Thanks for carefully checking what we already have.\n\n>> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n>> index bb31f0c42b..1b279904eb 100644\n>> --- a/Documentation/diff-options.txt\n>> +++ b/Documentation/diff-options.txt\n>> @@ -651,6 +651,9 @@ ifndef::git-format-patch[]\n>>  \tnot in a subdirectory (e.g. in a bare repository), you\n>>  \tcan name which subdirectory to make the output relative\n>>  \tto by giving a <path> as an argument.\n>> +--no-relative::\n>\n> Please merge this option with `--relative[=<path>]` above.\n> And says something likes:\n>\n> \t`--no-relative` can be used to countermand\n> \tboth `diff.relative` and previous `--relative`\n\nThis, and all the rest of comments are quite good.  Thanks for helping.\n"},{"id":"398041","messageId":"20200518094021.GA2069@spk-laptop","threadId":"53479","inReplyTo":"xmqqlflq7fyd.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T09:40:21Z","receivedAt":"2020-05-18T09:40:28Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` show only changes on\nthe current directory and show relative pathnames to the current\ndirectory.\n\nTeach --no-relative to override earlier --relative\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt  |  4 ++\n Documentation/diff-options.txt |  2 +\n diff.c                         | 12 +++--\n t/t4045-diff-relative.sh       | 83 ++++++++++++++++++++++++++++++++--\n 4 files changed, 95 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..c3ae136eba 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n\n+diff.relative::\n+\tIf set to 'true', 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..167b451b89 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n+\t`--no-relative` can be used to countermand both `diff.relative` config\n+\toption and previous `--relative`.\n endif::git-format-patch[]\n\n -a::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..e3f98334e9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \t\toptions->b_prefix = \"b/\";\n \t}\n\n+\toptions->flags.relative_name = diff_relative;\n+\n \toptions->color_moved = diff_color_moved_default;\n \toptions->color_moved_ws_handling = diff_color_moved_ws_default;\n\n@@ -5195,8 +5202,7 @@ static int diff_opt_relative(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n\n-\tBUG_ON_OPT_NEG(unset);\n-\toptions->flags.relative_name = 1;\n+\toptions->flags.relative_name = !unset;\n \tif (arg)\n \t\toptions->prefix = arg;\n \treturn 0;\n@@ -5492,7 +5498,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_GROUP(N_(\"Other diff options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n-\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 258808708e..ac264ccc2a 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -8,7 +8,8 @@ test_expect_success 'setup' '\n \techo content >file1 &&\n \tmkdir subdir &&\n \techo other content >subdir/file2 &&\n-\tblob=$(git hash-object subdir/file2) &&\n+\tblob_file1=$(git hash-object file1) &&\n+\tblob_file2=$(git hash-object subdir/file2) &&\n \tgit add . &&\n \tgit commit -m one\n '\n@@ -18,7 +19,7 @@ check_diff () {\n \tshift\n \texpect=$1\n \tshift\n-\tshort_blob=$(git rev-parse --short $blob)\n+\tshort_blob=$(git rev-parse --short $blob_file2)\n \tcat >expected <<-EOF\n \tdiff --git a/$expect b/$expect\n \tnew file mode 100644\n@@ -70,7 +71,7 @@ check_raw () {\n \texpect=$1\n \tshift\n \tcat >expected <<-EOF\n-\t:000000 100644 $ZERO_OID $blob A\t$expect\n+\t:000000 100644 $ZERO_OID $blob_file2 A\t$expect\n \tEOF\n \ttest_expect_success \"--raw $*\" \"\n \t\tgit -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&\n@@ -86,4 +87,80 @@ do\n \tcheck_$type . dir/file2 --relative=sub\n done\n\n+check_diff_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob=$(git rev-parse --short \"$blob_file2\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\tshort_blob_file1=$(git rev-parse --short \"$blob_file1\")\n+\tshort_blob_file2=$(git rev-parse --short \"$blob_file2\")\n+\tcat >expected <<-EOF\n+\tdiff --git a/file1 b/file1\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file1\n+\t--- /dev/null\n+\t+++ b/file1\n+\t@@ -0,0 +1 @@\n+\t+content\n+\tdiff --git a/$expect b/$expect\n+\tnew file mode 100644\n+\tindex 0000000..$short_blob_file2\n+\t--- /dev/null\n+\t+++ b/$expect\n+\t@@ -0,0 +1 @@\n+\t+other content\n+\tEOF\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option . subdir/file2 false\n+check_diff_no_relative_option . subdir/file2 true --no-relative\n+check_diff_no_relative_option . subdir/file2 false --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false\n+check_diff_no_relative_option subdir subdir/file2 true --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false --no-relative\n+\n+check_diff_relative_option . file2 false --relative=subdir/\n+check_diff_relative_option . file2 false --relative=subdir\n+check_diff_relative_option . file2 true --relative=subdir/\n+check_diff_relative_option . file2 true --relative=subdir\n+check_diff_relative_option subdir file2 false --relative\n+check_diff_relative_option subdir file2 true --relative\n+check_diff_relative_option subdir file2 true\n+check_diff_relative_option subdir file2 false --no-relative --relative\n+check_diff_relative_option subdir file2 true --no-relative --relative\n+check_diff_relative_option . file2 false --no-relative --relative=subdir\n+check_diff_relative_option . file2 true --no-relative --relative=subdir\n+\n test_done\n--\n2.26.2\n"},{"id":"398054","messageId":"20200518094359.GB2069@spk-laptop","threadId":"53479","inReplyTo":"20200517021452.GA2114@danh.dev","subject":"Re: [PATCH v4] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T09:43:59Z","receivedAt":"2020-05-18T09:44:03Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"Hi Danh,\n\nOn Sun, May 17, 2020 at 09:14:52AM +0700, Đoàn Trần Công Danh wrote:\n> Above comment also applied here.\n> And remove this debug cat.\n\nOops thanks for the review I've submitted a v5 for review let me know if I\nresponded to all your feedbacks\n\n-- \nLaurent\n"},{"id":"398065","messageId":"20200518114630.GA30622@konoha","threadId":"53479","inReplyTo":"20200518094021.GA2069@spk-laptop","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Shourya Shukla","fromEmail":"shouryashukla.oo@gmail.com","sentAt":"2020-05-18T11:46:30Z","receivedAt":"2020-05-18T11:46:40Z","isPatch":true,"sender":{"key":"shouryashukla.oo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43680618?v=4"},"body":"Hello Laurent,\n\nI have not worked in this part of Git before, please pardon my\nignorance. I went through the conversations held in this thread\nHere are my inferences:\n\n> The `diff.relative` boolean option set to `true` show only changes on\n> the current directory and show relative pathnames to the current\n> directory.\n\n> Teach --no-relative to override earlier --relative\n\nI think the message can be written better, maybe something like:\n\n    The `diff.relative` boolean option set to `true` shows only changes\n    in the current directory/value specified by the `path` argument of\n    the `relative` option and shows pathnames relative to the\n    aforementioned directory.\n\n    Teach `--no-relative` to override the earlier `--relative`\n\n> --- a/Documentation/config/diff.txt\n> +++ b/Documentation/config/diff.txt\n> @@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n>  diff.noprefix::\n>  \tIf set, 'git diff' does not show any source or destination prefix.\n> \n> +diff.relative::\n> +\tIf set to 'true', 'git diff' does not show changes outside of the directory\n> +\tand show pathnames relative to the current directory.\n\nIn the second last line, it would be better to write is as:\n\n    ... does not show changes outside of the current directory/the path\n    provided as the argument in `relative`?\n\nEven my version of the above line seems very crude and innaccurate, but\nI think that we should take into account the `path` passed down to us\nby the `--relative[=<path>]` option.\n\nMoving on, what I wondered was that maybe making it a `true/false`\noption would be better? Something like:\n\n    git diff --relative=false //override the diff.relative setting\n    git diff --relative=true <path> //works like the usual `relative`\n\nAnd by the usual, I mean :\n    git diff --relative[=<path>]\n\nWhat do you think? I think it would be better than adding a new option.\n\nAlso, if I am not mistaken:\n\n> @@ -5195,8 +5202,7 @@ static int diff_opt_relative(const struct option *opt,\n>  {\n>  \tstruct diff_options *options = opt->value;\n> \n> -\tBUG_ON_OPT_NEG(unset);\n> -\toptions->flags.relative_name = 1;\n> +\toptions->flags.relative_name = !unset;\n\nThis is the overriding part right?\n\nBTW you mention the `no-relative` setting which will override the\n`relative` option. I am not able to see where exactly is the occurence\nof the `no-relative` option in the code? What I mean is that I am not\nable to observe where exactly does the C code identify a `no-relative`\noption from the command line input? Did I miss something out here?\n\nAll nits aside, it looks like a very good concept to me. Nice work! :)\n\nRegards,\nShourya Shukla\n"},{"id":"398066","messageId":"20200518130421.GA1980@danh.dev","threadId":"53479","inReplyTo":"20200518114630.GA30622@konoha","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-18T13:04:21Z","receivedAt":"2020-05-18T13:04:25Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Hi Shourya,\n\nOn 2020-05-18 17:16:30+0530, Shourya Shukla <shouryashukla.oo@gmail.com> wrote:\n> BTW you mention the `no-relative` setting which will override the\n> `relative` option. I am not able to see where exactly is the occurence\n> of the `no-relative` option in the code? What I mean is that I am not\n> able to observe where exactly does the C code identify a `no-relative`\n> option from the command line input? Did I miss something out here?\n\n--no-relative is parsed by removing PARSE_OPT_NONE in\nprep_parse_options (diff.c:5495)\n\n-- \nDanh\n"},{"id":"398067","messageId":"20200518135656.GB1980@danh.dev","threadId":"53479","inReplyTo":"20200518094021.GA2069@spk-laptop","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-18T13:56:56Z","receivedAt":"2020-05-18T13:57:01Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Hi Laurent,\n\nOn 2020-05-18 11:40:21+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n> The `diff.relative` boolean option set to `true` show only changes on\n> the current directory and show relative pathnames to the current\n> directory.\n> \n> Teach --no-relative to override earlier --relative\n> \n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n\nThanks for addressing my comment.\n\nSorry for detecting this late.\nSince I usually only look into end of mail-archive to see any\ninteresting topic.\n\nAnd sorry for this late email,\nI want to run full test before replying with this.\n\nI've just seen this:\nhttps://lore.kernel.org/git/xmqq1rnk923o.fsf@gitster.c.googlers.com/\n\nI've written some test and concluded that we'll need this fix-up\nto make sure git-format-patch(1) doesn't generate broken patch:\n\n----------------8<----------------\n builtin/log.c            |  1 +\n t/t4045-diff-relative.sh | 11 ++++++++---\n 2 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex d104d5c688..5949a4883e 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1744,6 +1744,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \trev.diff = 1;\n \trev.max_parents = 1;\n \trev.diffopt.flags.recursive = 1;\n+\trev.diffopt.flags.relative_name = 0;\n \trev.subject_prefix = fmt_patch_subject_prefix;\n \tmemset(&s_r_opt, 0, sizeof(s_r_opt));\n \ts_r_opt.def = \"HEAD\";\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex ac264ccc2a..a73b104d66 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -11,7 +11,8 @@ test_expect_success 'setup' '\n \tblob_file1=$(git hash-object file1) &&\n \tblob_file2=$(git hash-object subdir/file2) &&\n \tgit add . &&\n-\tgit commit -m one\n+\tgit commit -m one &&\n+\tgit format-patch -1 --stdout >expect.patch\n '\n \n check_diff () {\n@@ -107,7 +108,9 @@ check_diff_relative_option () {\n \ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n \t\ttest_config -C $dir diff.relative $relative_opt &&\n \t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n-\t\ttest_cmp expected actual\n+\t\ttest_cmp expected actual &&\n+\t\tgit -C '$dir' format-patch -1 --stdout >actual.patch &&\n+\t\ttest_cmp expect.patch actual.patch\n \t\"\n }\n \n@@ -140,7 +143,9 @@ check_diff_no_relative_option () {\n \t\ttest_config -C $dir diff.relative $relative_opt &&\n \t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n \t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n-\t\ttest_cmp expected actual\n+\t\ttest_cmp expected actual &&\n+\t\tgit -C '$dir' format-patch -1 --stdout >actual.patch &&\n+\t\ttest_cmp expect.patch actual.patch\n \t\"\n }\n--------------------8<------------------------- \n> @@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n>  \t\toptions->b_prefix = \"b/\";\n>  \t}\n> \n> +\toptions->flags.relative_name = diff_relative;\n> +\n\nNitpick:\n\nI don't think this option is too special to add a newline to separate\nit from the rest :)\n\nSorry about not seeing this earlier, I'm a very careless person.\n\nAnyway, I think (just a matter of my _personal_ preference),\nit's better to move it up 21 lines, together with:\n\n\toptions->flags.rename_empty = 1;\n\n> diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\n> index 258808708e..ac264ccc2a 100755\n> --- a/t/t4045-diff-relative.sh\n> +++ b/t/t4045-diff-relative.sh\n> @@ -8,7 +8,8 @@ test_expect_success 'setup' '\n>  \techo content >file1 &&\n>  \tmkdir subdir &&\n>  \techo other content >subdir/file2 &&\n> -\tblob=$(git hash-object subdir/file2) &&\n> +\tblob_file1=$(git hash-object file1) &&\n> +\tblob_file2=$(git hash-object subdir/file2) &&\n\nThis rename from blob to blob_file2 is a noise to this patch.\nNot sure if we should make a preparatory patch to rename, though.\n\n*I* would say yes, and another patch to move all git-related code\ninto test_expect_* family. Then, all new testing code for git in this\npatch should be placed inside test_expect_*, too.\n\nI think it's better to wait for other's opinions :)\n\n> @@ -86,4 +87,80 @@ do\n>  \tcheck_$type . dir/file2 --relative=sub\n>  done\n> \n> +\tdiff --git a/$expect b/$expect\n> +\tnew file mode 100644\n> +\tindex 0000000..$short_blob_file2\n> +\t--- /dev/null\n> +\t+++ b/$expect\n> +\t@@ -0,0 +1 @@\n> +\t+other content\n> +\tEOF\n> +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> +\t\ttest_config -C $dir diff.relative $relative_opt &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n> +\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n\nPlease this leftover from debugging.\n\n-- \nDanh\n"},{"id":"398091","messageId":"CAPig+cRNCdtK9SSMSXj83tTCV1n+YW3-a0EnfM_VVVCry8rXCg@mail.gmail.com","threadId":"53479","inReplyTo":"20200518094021.GA2069@spk-laptop","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-05-18T16:19:20Z","receivedAt":"2020-05-18T16:19:35Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, May 18, 2020 at 5:40 AM Laurent Arnoud <laurent@spkdev.net> wrote:\n> The `diff.relative` boolean option set to `true` show only changes on\n> the current directory and show relative pathnames to the current\n> directory.\n>\n> Teach --no-relative to override earlier --relative\n>\n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n> ---\n> diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\n> +check_diff_relative_option () {\n> +       dir=$1\n> +       shift\n> +       expect=$1\n> +       shift\n> +       relative_opt=$1\n> +       shift\n> +       short_blob=$(git rev-parse --short \"$blob_file2\")\n> +       cat >expected <<-EOF\n> +       diff --git a/$expect b/$expect\n> +       new file mode 100644\n> +       index 0000000..$short_blob\n> +       --- /dev/null\n> +       +++ b/$expect\n> +       @@ -0,0 +1 @@\n> +       +other content\n> +       EOF\n> +       test_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> +               test_config -C $dir diff.relative $relative_opt &&\n> +               git -C '$dir' diff -p $* HEAD^ >actual &&\n> +               test_cmp expected actual\n> +       \"\n> +}\n\nLet's move all the setup code into the test itself so that a failure\nof git-rev-parse will be caught. For instance:\n\ncheck_diff_relative_option () {\n   dir=$1\n   shift\n   expect=$1\n   shift\n   relative_opt=$1\n   shift\n   test_expect_success \"config diff.relative $relative_opt -p $*\" \"\n       short_blob=$(git rev-parse --short $blob_file2) &&\n       cat >expected <<-EOF &&\n       diff --git a/$expect b/$expect\n       new file mode 100644\n       index 0000000..$short_blob\n       --- /dev/null\n       +++ b/$expect\n       @@ -0,0 +1 @@\n       +other content\n       EOF\n       test_config -C $dir diff.relative $relative_opt &&\n       git -C '$dir' diff -p $* HEAD^ >actual &&\n       test_cmp expected actual\n   \"\n}\n\nSame comment applies to the other new function added by this patch.\n"},{"id":"398100","messageId":"xmqq4ksd5ggq.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200518135656.GB1980@danh.dev","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T16:57:09Z","receivedAt":"2020-05-18T16:57:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n> I've written some test and concluded that we'll need this fix-up\n> to make sure git-format-patch(1) doesn't generate broken patch:\n>\n> ----------------8<----------------\n>  builtin/log.c            |  1 +\n>  t/t4045-diff-relative.sh | 11 ++++++++---\n>  2 files changed, 9 insertions(+), 3 deletions(-)\n>\n> diff --git a/builtin/log.c b/builtin/log.c\n> index d104d5c688..5949a4883e 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1744,6 +1744,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n>  \trev.diff = 1;\n>  \trev.max_parents = 1;\n>  \trev.diffopt.flags.recursive = 1;\n> +\trev.diffopt.flags.relative_name = 0;\n>  \trev.subject_prefix = fmt_patch_subject_prefix;\n>  \tmemset(&s_r_opt, 0, sizeof(s_r_opt));\n>  \ts_r_opt.def = \"HEAD\";\n\nHmph, what do you exactly mean by \"broken patch\"?\n\nI actually do not mind people who set \"diff.relative\" to do\n\n    $ git config diff.relative true\n    $ cd t && git format-patch -1 --stdout\n\nto get an incomplete patch that covers only the t/ subdirectory, as\nlong as they can ask Git to optionally get the full view with\n\n    $ cd t && git format-patch -1 --stdout --no-relative\n\nNote: this is not limited to format-patch but all the commands in\nthe diff family like \"log --stat\", \"show\", etc.\n\nOf course, diff.relative configuration would have no use for me\npersonally and I suspect it would be useless for many people, but\nthose who work inside a deeply nested project (java perhaps?) it\nwould be handy and it makes sense to match the default behaviour\nbetween \"diff\", \"show\" and \"format-patch\" when the configuration is\nactive, as long as they have a way to contermand from the command\nline.\n"},{"id":"398101","messageId":"xmqqzha541la.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200518135656.GB1980@danh.dev","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T17:03:45Z","receivedAt":"2020-05-18T17:03:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n>> @@ -4558,6 +4563,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n>>  \t\toptions->b_prefix = \"b/\";\n>>  \t}\n>> \n>> +\toptions->flags.relative_name = diff_relative;\n>> +\n>\n> Nitpick:\n>\n> I don't think this option is too special to add a newline to separate\n> it from the rest :)\n>\n> Sorry about not seeing this earlier, I'm a very careless person.\n>\n> Anyway, I think (just a matter of my _personal_ preference),\n> it's better to move it up 21 lines, together with:\n>\n> \toptions->flags.rename_empty = 1;\n\nSounds like a reasonable improvement of readability.\n\n>> diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\n>> index 258808708e..ac264ccc2a 100755\n>> --- a/t/t4045-diff-relative.sh\n>> +++ b/t/t4045-diff-relative.sh\n>> @@ -8,7 +8,8 @@ test_expect_success 'setup' '\n>>  \techo content >file1 &&\n>>  \tmkdir subdir &&\n>>  \techo other content >subdir/file2 &&\n>> -\tblob=$(git hash-object subdir/file2) &&\n>> +\tblob_file1=$(git hash-object file1) &&\n>> +\tblob_file2=$(git hash-object subdir/file2) &&\n>\n> This rename from blob to blob_file2 is a noise to this patch.\n>\n> Not sure if we should make a preparatory patch to rename, though.\n\nI personally do not mind this one.  It is crystal clear from the\npatch text: \"We used to use only one and managed to get away without\nblob1/blob2 but now we use more than 1, so let's use names with\nnumber suffix\".  On the other hand, a \"preparatory patch\" that\nrenames blob to blob_file1 before we need the second one is a noise.\n\n> *I* would say yes, and another patch to move all git-related code\n> into test_expect_* family. Then, all new testing code for git in this\n> patch should be placed inside test_expect_*, too.\n\nThe latter clean-up to make sure we won't notice Git failure outside\ntest_expect_* block may make sense, but I do not know if we want to\nmake it a preparatory clean-up or \"remember to do so later when the\ndust settles\".  If this single-patch topic needs to touch only a\nsmall part of the existing test to do its job, and such a clean-up\nends up touching far wider parts of the script, then I would say we\ncan do so as a post-patch clean-up, not as a part of the topic.\n\n>\n> I think it's better to wait for other's opinions :)\n>\n>> @@ -86,4 +87,80 @@ do\n>>  \tcheck_$type . dir/file2 --relative=sub\n>>  done\n>> \n>> +\tdiff --git a/$expect b/$expect\n>> +\tnew file mode 100644\n>> +\tindex 0000000..$short_blob_file2\n>> +\t--- /dev/null\n>> +\t+++ b/$expect\n>> +\t@@ -0,0 +1 @@\n>> +\t+other content\n>> +\tEOF\n>> +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n>> +\t\ttest_config -C $dir diff.relative $relative_opt &&\n>> +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n>> +\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n>\n> Please this leftover from debugging.\n\nThanks for a careful review, again.\n"},{"id":"398106","messageId":"20200518172103.GA2110@spk-laptop","threadId":"53479","inReplyTo":"xmqqzha541la.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T17:21:03Z","receivedAt":"2020-05-18T17:21:10Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"From 478164550f65dfb26e213957d461f0f94fecbcab Mon Sep 17 00:00:00 2001\nFrom: Laurent Arnoud <laurent@spkdev.net>\nDate: Fri, 15 May 2020 19:34:42 +0200\nSubject: [PATCH v6] diff: add config option relative\n\nThe `diff.relative` boolean option set to `true` shows only changes in\nthe current directory/value specified by the `path` argument of the\n`relative` option and shows pathnames relative to the aforementioned\ndirectory.\n\nTeach --no-relative to override earlier --relative\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt  |  4 ++\n Documentation/diff-options.txt |  2 +\n diff.c                         | 11 +++--\n t/t4014-format-patch.sh        | 13 ++++++\n t/t4045-diff-relative.sh       | 82 ++++++++++++++++++++++++++++++++--\n 5 files changed, 106 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..c3ae136eba 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n \n+diff.relative::\n+\tIf set to 'true', 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..167b451b89 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n+\t`--no-relative` can be used to countermand both `diff.relative` config\n+\toption and previous `--relative`.\n endif::git-format-patch[]\n \n -a::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..863da896c0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4538,6 +4543,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \toptions->interhunkcontext = diff_interhunk_context_default;\n \toptions->ws_error_highlight = ws_error_highlight_default;\n \toptions->flags.rename_empty = 1;\n+\toptions->flags.relative_name = diff_relative;\n \toptions->objfind = NULL;\n \n \t/* pathchange left =NULL by default */\n@@ -5195,8 +5201,7 @@ static int diff_opt_relative(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n \n-\tBUG_ON_OPT_NEG(unset);\n-\toptions->flags.relative_name = 1;\n+\toptions->flags.relative_name = !unset;\n \tif (arg)\n \t\toptions->prefix = arg;\n \treturn 0;\n@@ -5492,7 +5497,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_GROUP(N_(\"Other diff options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n-\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex db7e733af9..575e079cc2 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1602,6 +1602,19 @@ test_expect_success 'format patch ignores color.ui' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format patch respects diff.relative' '\n+\trm -rf subdir &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add subdir/file2 &&\n+\tgit commit -F msg &&\n+\ttest_unconfig diff.relative &&\n+\tgit format-patch --relative=subdir --stdout -1 >expect &&\n+\ttest_config diff.relative true &&\n+\tgit -C subdir format-patch --stdout -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cover letter with invalid --cover-from-description and config' '\n \ttest_config branch.rebuild-1.description \"config subject\n \ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 258808708e..87606de9ec 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -8,7 +8,8 @@ test_expect_success 'setup' '\n \techo content >file1 &&\n \tmkdir subdir &&\n \techo other content >subdir/file2 &&\n-\tblob=$(git hash-object subdir/file2) &&\n+\tblob_file1=$(git hash-object file1) &&\n+\tblob_file2=$(git hash-object subdir/file2) &&\n \tgit add . &&\n \tgit commit -m one\n '\n@@ -18,7 +19,7 @@ check_diff () {\n \tshift\n \texpect=$1\n \tshift\n-\tshort_blob=$(git rev-parse --short $blob)\n+\tshort_blob=$(git rev-parse --short $blob_file2)\n \tcat >expected <<-EOF\n \tdiff --git a/$expect b/$expect\n \tnew file mode 100644\n@@ -70,7 +71,7 @@ check_raw () {\n \texpect=$1\n \tshift\n \tcat >expected <<-EOF\n-\t:000000 100644 $ZERO_OID $blob A\t$expect\n+\t:000000 100644 $ZERO_OID $blob_file2 A\t$expect\n \tEOF\n \ttest_expect_success \"--raw $*\" \"\n \t\tgit -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&\n@@ -86,4 +87,79 @@ do\n \tcheck_$type . dir/file2 --relative=sub\n done\n \n+check_diff_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob=$(git rev-parse --short \"$blob_file2\") &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob_file1=$(git rev-parse --short \"$blob_file1\") &&\n+\t\tshort_blob_file2=$(git rev-parse --short \"$blob_file2\") &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/file1 b/file1\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file1\n+\t\t--- /dev/null\n+\t\t+++ b/file1\n+\t\t@@ -0,0 +1 @@\n+\t\t+content\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file2\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option . subdir/file2 false\n+check_diff_no_relative_option . subdir/file2 true --no-relative\n+check_diff_no_relative_option . subdir/file2 false --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false\n+check_diff_no_relative_option subdir subdir/file2 true --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false --no-relative\n+\n+check_diff_relative_option . file2 false --relative=subdir/\n+check_diff_relative_option . file2 false --relative=subdir\n+check_diff_relative_option . file2 true --relative=subdir/\n+check_diff_relative_option . file2 true --relative=subdir\n+check_diff_relative_option subdir file2 false --relative\n+check_diff_relative_option subdir file2 true --relative\n+check_diff_relative_option subdir file2 true\n+check_diff_relative_option subdir file2 false --no-relative --relative\n+check_diff_relative_option subdir file2 true --no-relative --relative\n+check_diff_relative_option . file2 false --no-relative --relative=subdir\n+check_diff_relative_option . file2 true --no-relative --relative=subdir\n+\n test_done\n-- \n2.26.2\n"},{"id":"398108","messageId":"20200518172504.GB2110@spk-laptop","threadId":"53479","inReplyTo":"20200518114630.GA30622@konoha","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T17:25:04Z","receivedAt":"2020-05-18T17:25:08Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"Hi Shourya,\n\nOn Mon, May 18, 2020 at 05:16:30PM +0530, Shourya Shukla wrote:\n> I think the message can be written better, maybe something like:\n> \n>     The `diff.relative` boolean option set to `true` shows only changes\n>     in the current directory/value specified by the `path` argument of\n>     the `relative` option and shows pathnames relative to the\n>     aforementioned directory.\n> \n>     Teach `--no-relative` to override the earlier `--relative`\n\nThanks I've applied your suggestion to the v6 patch\n\n> > --- a/Documentation/config/diff.txt\n> > +++ b/Documentation/config/diff.txt\n> > @@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n> >  diff.noprefix::\n> >  \tIf set, 'git diff' does not show any source or destination prefix.\n> > \n> > +diff.relative::\n> > +\tIf set to 'true', 'git diff' does not show changes outside of the directory\n> > +\tand show pathnames relative to the current directory.\n> \n> In the second last line, it would be better to write is as:\n> \n>     ... does not show changes outside of the current directory/the path\n>     provided as the argument in `relative`?\n> \n> Even my version of the above line seems very crude and innaccurate, but\n> I think that we should take into account the `path` passed down to us\n> by the `--relative[=<path>]` option.\n> \n> Moving on, what I wondered was that maybe making it a `true/false`\n> option would be better? Something like:\n> \n>     git diff --relative=false //override the diff.relative setting\n>     git diff --relative=true <path> //works like the usual `relative`\n> \n> And by the usual, I mean :\n>     git diff --relative[=<path>]\n> \n> What do you think? I think it would be better than adding a new option.\n\nI think this would be complicated to check if true/false is a directory of not;\nit has been mentioned by Junio on another thread for a patch alike\n\nCheers\n\n-- \nLaurent\n"},{"id":"398109","messageId":"20200518172607.GC2110@spk-laptop","threadId":"53479","inReplyTo":"CAPig+cRNCdtK9SSMSXj83tTCV1n+YW3-a0EnfM_VVVCry8rXCg@mail.gmail.com","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T17:26:07Z","receivedAt":"2020-05-18T17:26:11Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"On Mon, May 18, 2020 at 12:19:20PM -0400, Eric Sunshine wrote:\n> Let's move all the setup code into the test itself so that a failure\n> of git-rev-parse will be caught. For instance:\n> \n> check_diff_relative_option () {\n>    dir=$1\n>    shift\n>    expect=$1\n>    shift\n>    relative_opt=$1\n>    shift\n>    test_expect_success \"config diff.relative $relative_opt -p $*\" \"\n>        short_blob=$(git rev-parse --short $blob_file2) &&\n>        cat >expected <<-EOF &&\n>        diff --git a/$expect b/$expect\n>        new file mode 100644\n>        index 0000000..$short_blob\n>        --- /dev/null\n>        +++ b/$expect\n>        @@ -0,0 +1 @@\n>        +other content\n>        EOF\n>        test_config -C $dir diff.relative $relative_opt &&\n>        git -C '$dir' diff -p $* HEAD^ >actual &&\n>        test_cmp expected actual\n>    \"\n> }\n> \n> Same comment applies to the other new function added by this patch.\n\nThanks its applied on the v6 patch\n\n-- \nLaurent\n"},{"id":"398112","messageId":"xmqqftbx40br.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200518172103.GA2110@spk-laptop","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T17:31:04Z","receivedAt":"2020-05-18T17:31:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Laurent Arnoud <laurent@spkdev.net> writes:\n\n> Subject: Re: [PATCH v6] diff: add config option relative\n\nThis is not a new problem with this round, but can you stop starting\na new iteration that is v6 with \"Subject: Re: [PATCH v6]\"? \n\nIt is good to make v6 a reply to v6, but this is the *first* message\nthat begins v6 iteration, so it is easier to find it without \"Re:\"\nprefix.\n\nThanks.\n"},{"id":"398113","messageId":"20200518173218.GD2110@spk-laptop","threadId":"53479","inReplyTo":"20200518135656.GB1980@danh.dev","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-18T17:32:18Z","receivedAt":"2020-05-18T17:32:23Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"Hi Danh,\n\nOn Mon, May 18, 2020 at 08:56:56PM +0700, Đoàn Trần Công Danh wrote:\n> Thanks for addressing my comment.\n> \n> Sorry for detecting this late.\n> Since I usually only look into end of mail-archive to see any\n> interesting topic.\n> \n> And sorry for this late email,\n> I want to run full test before replying with this.\n> \n> I've just seen this:\n> https://lore.kernel.org/git/xmqq1rnk923o.fsf@gitster.c.googlers.com/\n> \n> I've written some test and concluded that we'll need this fix-up\n> to make sure git-format-patch(1) doesn't generate broken patch:\n\nNo worries this Junio is ok for this I've added a test instead in\nt/t4014-format-patch.sh ensuring that format-patch respects the config\ndiff.relative on the v6 of the patch, let me know what you think\n\n> Nitpick:\n> \n> I don't think this option is too special to add a newline to separate\n> it from the rest :)\n> \n> Sorry about not seeing this earlier, I'm a very careless person.\n> \n> Anyway, I think (just a matter of my _personal_ preference),\n> it's better to move it up 21 lines, together with:\n> \n> \toptions->flags.rename_empty = 1;\n> \n\nApplied in the v6\n\n> > @@ -86,4 +87,80 @@ do\n> >  \tcheck_$type . dir/file2 --relative=sub\n> >  done\n> > \n> > +\tdiff --git a/$expect b/$expect\n> > +\tnew file mode 100644\n> > +\tindex 0000000..$short_blob_file2\n> > +\t--- /dev/null\n> > +\t+++ b/$expect\n> > +\t@@ -0,0 +1 @@\n> > +\t+other content\n> > +\tEOF\n> > +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> > +\t\ttest_config -C $dir diff.relative $relative_opt &&\n> > +\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n> > +\t\tgit -C '$dir' diff -p $* HEAD^ >/tmp/actual &&\n> \n> Please this leftover from debugging.\n\nOpps fixed and thanks again for the review\n\n-- \nLaurent\n"},{"id":"398115","messageId":"xmqq7dx9407i.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"xmqqftbx40br.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T17:33:37Z","receivedAt":"2020-05-18T17:33:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Laurent Arnoud <laurent@spkdev.net> writes:\n>\n>> Subject: Re: [PATCH v6] diff: add config option relative\n>\n> This is not a new problem with this round, but can you stop starting\n> a new iteration that is v6 with \"Subject: Re: [PATCH v6]\"? \n>\n> It is good to make v6 a reply to v6, but this is the *first* message\n\nSorry, \"make v6 a reply to v5\" is what I meant X-<.\n\n> that begins v6 iteration, so it is easier to find it without \"Re:\"\n> prefix.\n>\n> Thanks.\n"},{"id":"398116","messageId":"CAPig+cQqx1GckiMqGXgzwyLHZzx-Q1ayst8boaJ0X6GDPirbHQ@mail.gmail.com","threadId":"53479","inReplyTo":"20200518172103.GA2110@spk-laptop","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-05-18T17:34:43Z","receivedAt":"2020-05-18T17:34:58Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, May 18, 2020 at 1:22 PM Laurent Arnoud <laurent@spkdev.net> wrote:\n> The `diff.relative` boolean option set to `true` shows only changes in\n> the current directory/value specified by the `path` argument of the\n> `relative` option and shows pathnames relative to the aforementioned\n> directory.\n>\n> Teach --no-relative to override earlier --relative\n>\n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n> ---\n> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\n> @@ -86,4 +87,79 @@ do\n> +check_diff_relative_option () {\n> +       dir=$1\n> +       shift\n> +       expect=$1\n> +       shift\n> +       relative_opt=$1\n> +       shift\n> +       test_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> +               short_blob=$(git rev-parse --short \"$blob_file2\") &&\n\nYou're using double quotes inside a double-quote context. (Note that I\ndropped the quotes around $blob_file2 in the example I gave in order\nto avoid this problem.)\n\n> +               cat >expected <<-EOF &&\n> +               diff --git a/$expect b/$expect\n> +               new file mode 100644\n> +               index 0000000..\\$short_blob\n> +               --- /dev/null\n> +               +++ b/$expect\n> +               @@ -0,0 +1 @@\n> +               +other content\n> +               EOF\n> +               test_config -C $dir diff.relative $relative_opt &&\n> +               git -C '$dir' diff -p $* HEAD^ >actual &&\n> +               test_cmp expected actual\n> +       \"\n> +}\n"},{"id":"398131","messageId":"20200518191205.GA1999@danh.dev","threadId":"53479","inReplyTo":"xmqq4ksd5ggq.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-18T19:12:05Z","receivedAt":"2020-05-18T19:12:12Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-05-18 09:57:09-0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Hmph, what do you exactly mean by \"broken patch\"?\n> \n> I actually do not mind people who set \"diff.relative\" to do\n> \n>     $ git config diff.relative true\n>     $ cd t && git format-patch -1 --stdout\n> \n> to get an incomplete patch that covers only the t/ subdirectory, as\n> long as they can ask Git to optionally get the full view with\n> \n>     $ cd t && git format-patch -1 --stdout --no-relative\n\nWell, git-format-patch has never understood --relative,\nwhich I think is a sane behaviour,\nhence git-format-patch will never understand --no-relative after this\npatch.\n\nOh no, to my surprise, git-format-patch does accept --[no-]relative, now.\n\nWe don't document --relative for git-format-patch, the --relative\ndocumentation is placed under the guard, for that matter:\n\nDocumentation/diff-options.txt \n\n\nifndef::git-format-patch[]\n-R::\n        Swap two inputs; that is, show differences from index or\n        on-disk file to tree contents.\n\n--relative[=<path>]::\n        When run from a subdirectory of the project, it can be\n        told to exclude changes outside the directory and show\n        pathnames relative to it with this option.  When you are\n        not in a subdirectory (e.g. in a bare repository), you\n        can name which subdirectory to make the output relative\n        to by giving a <path> as an argument.\nendif::git-format-patch[]\n\nMaybe time to fix the documentation.\n\n-- \nDanh\n"},{"id":"398132","messageId":"20200518191954.GB1999@danh.dev","threadId":"53479","inReplyTo":"20200518172103.GA2110@spk-laptop","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-18T19:19:54Z","receivedAt":"2020-05-18T19:20:00Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-05-18 19:21:03+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index bb31f0c42b..167b451b89 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n>  \tnot in a subdirectory (e.g. in a bare repository), you\n>  \tcan name which subdirectory to make the output relative\n>  \tto by giving a <path> as an argument.\n> +\t`--no-relative` can be used to countermand both `diff.relative` config\n> +\toption and previous `--relative`.\n\nNitpick:\nPlease mentions --no-relative in option list:\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 167b451b89..8761c04bc2 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -645,6 +645,7 @@ ifndef::git-format-patch[]\n \ton-disk file to tree contents.\n \n --relative[=<path>]::\n+--no-relative::\n \tWhen run from a subdirectory of the project, it can be\n \ttold to exclude changes outside the directory and show\n \tpathnames relative to it with this option.  When you are\n\nTogether with Eric suggesstion, this patch looks good to me.\n\n-- \nDanh\n"},{"id":"398139","messageId":"xmqq5zct2eqd.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200518191954.GB1999@danh.dev","subject":"Re: [PATCH v6] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T20:02:50Z","receivedAt":"2020-05-18T20:02:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n> On 2020-05-18 19:21:03+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n>> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n>> index bb31f0c42b..167b451b89 100644\n>> --- a/Documentation/diff-options.txt\n>> +++ b/Documentation/diff-options.txt\n>> @@ -651,6 +651,8 @@ ifndef::git-format-patch[]\n>>  \tnot in a subdirectory (e.g. in a bare repository), you\n>>  \tcan name which subdirectory to make the output relative\n>>  \tto by giving a <path> as an argument.\n>> +\t`--no-relative` can be used to countermand both `diff.relative` config\n>> +\toption and previous `--relative`.\n>\n> Nitpick:\n> Please mentions --no-relative in option list:\n>\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index 167b451b89..8761c04bc2 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -645,6 +645,7 @@ ifndef::git-format-patch[]\n>  \ton-disk file to tree contents.\n>  \n>  --relative[=<path>]::\n> +--no-relative::\n>  \tWhen run from a subdirectory of the project, it can be\n>  \ttold to exclude changes outside the directory and show\n>  \tpathnames relative to it with this option.  When you are\n>\n> Together with Eric suggesstion, this patch looks good to me.\n\nYeah, good suggestions all.\n\nThanks.\n"},{"id":"398154","messageId":"xmqqo8ql0yjg.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200518191205.GA1999@danh.dev","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T20:37:55Z","receivedAt":"2020-05-18T20:37:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n> We don't document --relative for git-format-patch, the --relative\n> documentation is placed under the guard, for that matter:\n\nYup, since it does not make much sense or \"diff.relative\" for that\nmatter in the context of the \"format-patch\".  In the same sense, -R\nmakes little sense, so sane people would not want to read about the\noption in the documentation, I would think.\n\n> ifndef::git-format-patch[]\n> -R::\n>         Swap two inputs; that is, show differences from index or\n>         on-disk file to tree contents.\n>\n> --relative[=<path>]::\n>         When run from a subdirectory of the project, it can be\n>         told to exclude changes outside the directory and show\n"},{"id":"398169","messageId":"20200519003006.GC1999@danh.dev","threadId":"53479","inReplyTo":"xmqqo8ql0yjg.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-19T00:30:06Z","receivedAt":"2020-05-19T00:30:12Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-05-18 13:37:55-0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n> \n> > We don't document --relative for git-format-patch, the --relative\n> > documentation is placed under the guard, for that matter:\n> \n> Yup, since it does not make much sense or \"diff.relative\" for that\n> matter in the context of the \"format-patch\".  In the same sense, -R\n> makes little sense, so sane people would not want to read about the\n> option in the documentation, I would think.\n\nSane people wouldn't want to read that document when we don't have the\nconfig for diff.relative\n\nBut, now, we have. Let's document --no-relative, specifically for\ngit-format-patch(1).\n\nPerhaps something like this (maybe just fixing up to Laurent's)\n-----------------8<--------------\nFrom: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n <congdanhqx@gmail.com>\nDate: Tue, 19 May 2020 07:24:48 +0700\nSubject: [PATCH] Documentation: document --no-relative for format-patch\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\ngit-format-patch(1) accepts --relative for a long time, but the\ngenerated patch couldn't be applied without accompanying information.\n\nHence, we've never document --relative for git-format-patch(1).\n\nNow, we've introduced `diff.relative` config, let's tell Git's users\nthat they have an option to override it.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n Documentation/diff-options.txt | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 167b451b89..0f5c108324 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -654,6 +654,11 @@ ifndef::git-format-patch[]\n \t`--no-relative` can be used to countermand both `diff.relative` config\n \toption and previous `--relative`.\n endif::git-format-patch[]\n+ifdef::git-format-patch[]\n+--no-relative::\n+\tCountermand `diff.relative` config. Show all changes in the repository\n+\twith pathname relative to top-level directory of the repository.\n+endif::git-format-patch[]\n \n -a::\n --text::\n-- \n\nDanh\n\n"},{"id":"398205","messageId":"xmqqv9krztwp.fsf@gitster.c.googlers.com","threadId":"53479","inReplyTo":"20200519003006.GC1999@danh.dev","subject":"Re: [PATCH v5] diff: add config option relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-19T18:00:54Z","receivedAt":"2020-05-19T18:01:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n> Sane people wouldn't want to read that document when we don't have the\n> config for diff.relative\n>\n> But, now, we have. Let's document --no-relative, specifically for\n> git-format-patch(1).\n>\n> Perhaps something like this (maybe just fixing up to Laurent's)\n\nI love it when a contributor pushes back with a well thought out\ncounter-argument.  Yes, I think the reasoning along the line makes\nsense.\n\nIf a project binds another project with -Xsubtree=<path>, a change\nto that part would be a good candidate to use \"format-patch\" with\nthe \"--relative=<path>\".  We didn't consider it a use case that is\ninteresting enough, but it may be, which gives another reason why\ndocumenting \"--[no-]relative[=<path>]\" for the command may not be a\nbad thing, not just for the purpose of defeating \"diff.relative\".\n\nFor that reason, it may even make sense to use the same text for\n--no-relative and --relative[=<path>] we use for other commands in\nthe diff family, i.e. leaving only -R inside the ifndef block.\n\nThanks.\n\n> -----------------8<--------------\n> From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n>  <congdanhqx@gmail.com>\n> Date: Tue, 19 May 2020 07:24:48 +0700\n> Subject: [PATCH] Documentation: document --no-relative for format-patch\n> MIME-Version: 1.0\n> Content-Type: text/plain; charset=UTF-8\n> Content-Transfer-Encoding: 8bit\n>\n> git-format-patch(1) accepts --relative for a long time, but the\n> generated patch couldn't be applied without accompanying information.\n>\n> Hence, we've never document --relative for git-format-patch(1).\n>\n> Now, we've introduced `diff.relative` config, let's tell Git's users\n> that they have an option to override it.\n>\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>  Documentation/diff-options.txt | 5 +++++\n>  1 file changed, 5 insertions(+)\n>\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index 167b451b89..0f5c108324 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -654,6 +654,11 @@ ifndef::git-format-patch[]\n>  \t`--no-relative` can be used to countermand both `diff.relative` config\n>  \toption and previous `--relative`.\n>  endif::git-format-patch[]\n> +ifdef::git-format-patch[]\n> +--no-relative::\n> +\tCountermand `diff.relative` config. Show all changes in the repository\n> +\twith pathname relative to top-level directory of the repository.\n> +endif::git-format-patch[]\n>  \n>  -a::\n>  --text::\n"},{"id":"398214","messageId":"20200519193902.GA202573@spk-laptop","threadId":"53479","inReplyTo":"xmqqv9krztwp.fsf@gitster.c.googlers.com","subject":"[PATCH v7] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-19T19:39:02Z","receivedAt":"2020-05-19T19:39:12Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` shows only changes in\nthe current directory/value specified by the `path` argument of the\n`relative` option and shows pathnames relative to the aforementioned\ndirectory.\n\nTeach `--no-relative` to override earlier `--relative`\n\nAdd for git-format-patch(1) options documentation `--relative` and\n`--no-relative`\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt  |  4 ++\n Documentation/diff-options.txt |  5 ++-\n diff.c                         | 11 +++--\n t/t4014-format-patch.sh        | 13 ++++++\n t/t4045-diff-relative.sh       | 82 ++++++++++++++++++++++++++++++++--\n 5 files changed, 108 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..c3ae136eba 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n\n+diff.relative::\n+\tIf set to 'true', 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..7987d72b02 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -643,15 +643,18 @@ ifndef::git-format-patch[]\n -R::\n \tSwap two inputs; that is, show differences from index or\n \ton-disk file to tree contents.\n+endif::git-format-patch[]\n\n --relative[=<path>]::\n+--no-relative::\n \tWhen run from a subdirectory of the project, it can be\n \ttold to exclude changes outside the directory and show\n \tpathnames relative to it with this option.  When you are\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n-endif::git-format-patch[]\n+\t`--no-relative` can be used to countermand both `diff.relative` config\n+\toption and previous `--relative`.\n\n -a::\n --text::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..863da896c0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4538,6 +4543,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \toptions->interhunkcontext = diff_interhunk_context_default;\n \toptions->ws_error_highlight = ws_error_highlight_default;\n \toptions->flags.rename_empty = 1;\n+\toptions->flags.relative_name = diff_relative;\n \toptions->objfind = NULL;\n\n \t/* pathchange left =NULL by default */\n@@ -5195,8 +5201,7 @@ static int diff_opt_relative(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n\n-\tBUG_ON_OPT_NEG(unset);\n-\toptions->flags.relative_name = 1;\n+\toptions->flags.relative_name = !unset;\n \tif (arg)\n \t\toptions->prefix = arg;\n \treturn 0;\n@@ -5492,7 +5497,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_GROUP(N_(\"Other diff options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n-\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex db7e733af9..575e079cc2 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1602,6 +1602,19 @@ test_expect_success 'format patch ignores color.ui' '\n \ttest_cmp expect actual\n '\n\n+test_expect_success 'format patch respects diff.relative' '\n+\trm -rf subdir &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add subdir/file2 &&\n+\tgit commit -F msg &&\n+\ttest_unconfig diff.relative &&\n+\tgit format-patch --relative=subdir --stdout -1 >expect &&\n+\ttest_config diff.relative true &&\n+\tgit -C subdir format-patch --stdout -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cover letter with invalid --cover-from-description and config' '\n \ttest_config branch.rebuild-1.description \"config subject\n\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 258808708e..6b026c36a5 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -8,7 +8,8 @@ test_expect_success 'setup' '\n \techo content >file1 &&\n \tmkdir subdir &&\n \techo other content >subdir/file2 &&\n-\tblob=$(git hash-object subdir/file2) &&\n+\tblob_file1=$(git hash-object file1) &&\n+\tblob_file2=$(git hash-object subdir/file2) &&\n \tgit add . &&\n \tgit commit -m one\n '\n@@ -18,7 +19,7 @@ check_diff () {\n \tshift\n \texpect=$1\n \tshift\n-\tshort_blob=$(git rev-parse --short $blob)\n+\tshort_blob=$(git rev-parse --short $blob_file2)\n \tcat >expected <<-EOF\n \tdiff --git a/$expect b/$expect\n \tnew file mode 100644\n@@ -70,7 +71,7 @@ check_raw () {\n \texpect=$1\n \tshift\n \tcat >expected <<-EOF\n-\t:000000 100644 $ZERO_OID $blob A\t$expect\n+\t:000000 100644 $ZERO_OID $blob_file2 A\t$expect\n \tEOF\n \ttest_expect_success \"--raw $*\" \"\n \t\tgit -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&\n@@ -86,4 +87,79 @@ do\n \tcheck_$type . dir/file2 --relative=sub\n done\n\n+check_diff_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob=$(git rev-parse --short $blob_file2) &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob_file1=$(git rev-parse --short $blob_file1) &&\n+\t\tshort_blob_file2=$(git rev-parse --short $blob_file2) &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/file1 b/file1\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file1\n+\t\t--- /dev/null\n+\t\t+++ b/file1\n+\t\t@@ -0,0 +1 @@\n+\t\t+content\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file2\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option . subdir/file2 false\n+check_diff_no_relative_option . subdir/file2 true --no-relative\n+check_diff_no_relative_option . subdir/file2 false --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false\n+check_diff_no_relative_option subdir subdir/file2 true --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false --no-relative\n+\n+check_diff_relative_option . file2 false --relative=subdir/\n+check_diff_relative_option . file2 false --relative=subdir\n+check_diff_relative_option . file2 true --relative=subdir/\n+check_diff_relative_option . file2 true --relative=subdir\n+check_diff_relative_option subdir file2 false --relative\n+check_diff_relative_option subdir file2 true --relative\n+check_diff_relative_option subdir file2 true\n+check_diff_relative_option subdir file2 false --no-relative --relative\n+check_diff_relative_option subdir file2 true --no-relative --relative\n+check_diff_relative_option . file2 false --no-relative --relative=subdir\n+check_diff_relative_option . file2 true --no-relative --relative=subdir\n+\n test_done\n--\n2.26.2\n"},{"id":"398223","messageId":"20200519230124.GA12509@danh.dev","threadId":"53479","inReplyTo":"20200519193902.GA202573@spk-laptop","subject":"Re: [PATCH v7] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-19T23:01:24Z","receivedAt":"2020-05-19T23:01:30Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-05-19 21:39:02+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n> \n> +check_diff_relative_option () {\n> +\tdir=$1\n> +\tshift\n> +\texpect=$1\n> +\tshift\n> +\trelative_opt=$1\n> +\tshift\n> +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> +\t\tshort_blob=$(git rev-parse --short $blob_file2) &&\n\nWe need to quote the first dollar, in order to run that command\ninside the test.  Current version will run that git-rev-parse\noutside of the test and interpolated into this command by outer shell.\n\n\tshort_blob=\\$(git rev-parse --short $blob_file2) &&\n\nSorry, I didn't think about this earlier.\n\n> +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> +\t\tshort_blob_file1=$(git rev-parse --short $blob_file1) &&\n> +\t\tshort_blob_file2=$(git rev-parse --short $blob_file2) &&\n\nThis test also needs to quote that dollar.\nBeside that, LGTM.\n\n\n-- \nDanh\n"},{"id":"398416","messageId":"20200522104618.GA2050@spk-laptop","threadId":"53479","inReplyTo":"20200519230124.GA12509@danh.dev","subject":"[PATCH v8] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-22T10:46:18Z","receivedAt":"2020-05-22T10:46:27Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"The `diff.relative` boolean option set to `true` shows only changes in\nthe current directory/value specified by the `path` argument of the\n`relative` option and shows pathnames relative to the aforementioned\ndirectory.\n\nTeach `--no-relative` to override earlier `--relative`\n\nAdd for git-format-patch(1) options documentation `--relative` and\n`--no-relative`\n\nSigned-off-by: Laurent Arnoud <laurent@spkdev.net>\n---\n Documentation/config/diff.txt  |  4 ++\n Documentation/diff-options.txt |  5 ++-\n diff.c                         | 11 +++--\n t/t4014-format-patch.sh        | 13 ++++++\n t/t4045-diff-relative.sh       | 82 ++++++++++++++++++++++++++++++++--\n 5 files changed, 108 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt\nindex ff09f1cf73..c3ae136eba 100644\n--- a/Documentation/config/diff.txt\n+++ b/Documentation/config/diff.txt\n@@ -105,6 +105,10 @@ diff.mnemonicPrefix::\n diff.noprefix::\n \tIf set, 'git diff' does not show any source or destination prefix.\n\n+diff.relative::\n+\tIf set to 'true', 'git diff' does not show changes outside of the directory\n+\tand show pathnames relative to the current directory.\n+\n diff.orderFile::\n \tFile indicating how to order files within a diff.\n \tSee the '-O' option to linkgit:git-diff[1] for details.\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex bb31f0c42b..7987d72b02 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -643,15 +643,18 @@ ifndef::git-format-patch[]\n -R::\n \tSwap two inputs; that is, show differences from index or\n \ton-disk file to tree contents.\n+endif::git-format-patch[]\n\n --relative[=<path>]::\n+--no-relative::\n \tWhen run from a subdirectory of the project, it can be\n \ttold to exclude changes outside the directory and show\n \tpathnames relative to it with this option.  When you are\n \tnot in a subdirectory (e.g. in a bare repository), you\n \tcan name which subdirectory to make the output relative\n \tto by giving a <path> as an argument.\n-endif::git-format-patch[]\n+\t`--no-relative` can be used to countermand both `diff.relative` config\n+\toption and previous `--relative`.\n\n -a::\n --text::\ndiff --git a/diff.c b/diff.c\nindex d1ad6a3c4a..863da896c0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -48,6 +48,7 @@ static const char *diff_order_file_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_relative;\n static int diff_stat_graph_width;\n static int diff_dirstat_permille_default = 30;\n static struct diff_options default_diff_options;\n@@ -386,6 +387,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\tdiff_no_prefix = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tdiff_relative = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.statgraphwidth\")) {\n \t\tdiff_stat_graph_width = git_config_int(var, value);\n \t\treturn 0;\n@@ -4538,6 +4543,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)\n \toptions->interhunkcontext = diff_interhunk_context_default;\n \toptions->ws_error_highlight = ws_error_highlight_default;\n \toptions->flags.rename_empty = 1;\n+\toptions->flags.relative_name = diff_relative;\n \toptions->objfind = NULL;\n\n \t/* pathchange left =NULL by default */\n@@ -5195,8 +5201,7 @@ static int diff_opt_relative(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n\n-\tBUG_ON_OPT_NEG(unset);\n-\toptions->flags.relative_name = 1;\n+\toptions->flags.relative_name = !unset;\n \tif (arg)\n \t\toptions->prefix = arg;\n \treturn 0;\n@@ -5492,7 +5497,7 @@ static void prep_parse_options(struct diff_options *options)\n \t\tOPT_GROUP(N_(\"Other diff options\")),\n \t\tOPT_CALLBACK_F(0, \"relative\", options, N_(\"<prefix>\"),\n \t\t\t       N_(\"when run from subdir, exclude changes outside and show relative paths\"),\n-\t\t\t       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,\n+\t\t\t       PARSE_OPT_OPTARG,\n \t\t\t       diff_opt_relative),\n \t\tOPT_BOOL('a', \"text\", &options->flags.text,\n \t\t\t N_(\"treat all files as text\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex db7e733af9..575e079cc2 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1602,6 +1602,19 @@ test_expect_success 'format patch ignores color.ui' '\n \ttest_cmp expect actual\n '\n\n+test_expect_success 'format patch respects diff.relative' '\n+\trm -rf subdir &&\n+\tmkdir subdir &&\n+\techo other content >subdir/file2 &&\n+\tgit add subdir/file2 &&\n+\tgit commit -F msg &&\n+\ttest_unconfig diff.relative &&\n+\tgit format-patch --relative=subdir --stdout -1 >expect &&\n+\ttest_config diff.relative true &&\n+\tgit -C subdir format-patch --stdout -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cover letter with invalid --cover-from-description and config' '\n \ttest_config branch.rebuild-1.description \"config subject\n\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 258808708e..7be1de736d 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -8,7 +8,8 @@ test_expect_success 'setup' '\n \techo content >file1 &&\n \tmkdir subdir &&\n \techo other content >subdir/file2 &&\n-\tblob=$(git hash-object subdir/file2) &&\n+\tblob_file1=$(git hash-object file1) &&\n+\tblob_file2=$(git hash-object subdir/file2) &&\n \tgit add . &&\n \tgit commit -m one\n '\n@@ -18,7 +19,7 @@ check_diff () {\n \tshift\n \texpect=$1\n \tshift\n-\tshort_blob=$(git rev-parse --short $blob)\n+\tshort_blob=$(git rev-parse --short $blob_file2)\n \tcat >expected <<-EOF\n \tdiff --git a/$expect b/$expect\n \tnew file mode 100644\n@@ -70,7 +71,7 @@ check_raw () {\n \texpect=$1\n \tshift\n \tcat >expected <<-EOF\n-\t:000000 100644 $ZERO_OID $blob A\t$expect\n+\t:000000 100644 $ZERO_OID $blob_file2 A\t$expect\n \tEOF\n \ttest_expect_success \"--raw $*\" \"\n \t\tgit -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&\n@@ -86,4 +87,79 @@ do\n \tcheck_$type . dir/file2 --relative=sub\n done\n\n+check_diff_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob=\\$(git rev-parse --short $blob_file2) &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option () {\n+\tdir=$1\n+\tshift\n+\texpect=$1\n+\tshift\n+\trelative_opt=$1\n+\tshift\n+\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n+\t\tshort_blob_file1=\\$(git rev-parse --short $blob_file1) &&\n+\t\tshort_blob_file2=\\$(git rev-parse --short $blob_file2) &&\n+\t\tcat >expected <<-EOF &&\n+\t\tdiff --git a/file1 b/file1\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file1\n+\t\t--- /dev/null\n+\t\t+++ b/file1\n+\t\t@@ -0,0 +1 @@\n+\t\t+content\n+\t\tdiff --git a/$expect b/$expect\n+\t\tnew file mode 100644\n+\t\tindex 0000000..\\$short_blob_file2\n+\t\t--- /dev/null\n+\t\t+++ b/$expect\n+\t\t@@ -0,0 +1 @@\n+\t\t+other content\n+\t\tEOF\n+\t\ttest_config -C $dir diff.relative $relative_opt &&\n+\t\tgit -C '$dir' diff -p $* HEAD^ >actual &&\n+\t\ttest_cmp expected actual\n+\t\"\n+}\n+\n+check_diff_no_relative_option . subdir/file2 false\n+check_diff_no_relative_option . subdir/file2 true --no-relative\n+check_diff_no_relative_option . subdir/file2 false --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false\n+check_diff_no_relative_option subdir subdir/file2 true --no-relative\n+check_diff_no_relative_option subdir subdir/file2 false --no-relative\n+\n+check_diff_relative_option . file2 false --relative=subdir/\n+check_diff_relative_option . file2 false --relative=subdir\n+check_diff_relative_option . file2 true --relative=subdir/\n+check_diff_relative_option . file2 true --relative=subdir\n+check_diff_relative_option subdir file2 false --relative\n+check_diff_relative_option subdir file2 true --relative\n+check_diff_relative_option subdir file2 true\n+check_diff_relative_option subdir file2 false --no-relative --relative\n+check_diff_relative_option subdir file2 true --no-relative --relative\n+check_diff_relative_option . file2 false --no-relative --relative=subdir\n+check_diff_relative_option . file2 true --no-relative --relative=subdir\n+\n test_done\n--\n2.26.2\n"},{"id":"398417","messageId":"20200522104833.GB2050@spk-laptop","threadId":"53479","inReplyTo":"20200519230124.GA12509@danh.dev","subject":"Re: [PATCH v7] diff: add config option relative","fromName":"Laurent Arnoud","fromEmail":"laurent@spkdev.net","sentAt":"2020-05-22T10:48:33Z","receivedAt":"2020-05-22T10:48:39Z","isPatch":true,"sender":{"key":"laurent@spkdev.net","avatar":"https://avatars.githubusercontent.com/u/98590?v=4"},"body":"On Wed, May 20, 2020 at 06:01:24AM +0700, Đoàn Trần Công Danh wrote:\n> Sorry, I didn't think about this earlier.\n> \n> > +\ttest_expect_success \"config diff.relative $relative_opt -p $*\" \"\n> > +\t\tshort_blob_file1=$(git rev-parse --short $blob_file1) &&\n> > +\t\tshort_blob_file2=$(git rev-parse --short $blob_file2) &&\n> \n> This test also needs to quote that dollar.\n> Beside that, LGTM.\n\nNo worries I've submitted a v8 patch, thanks everyone for the reviews\n\n-- \nLaurent\n"},{"id":"398448","messageId":"20200523021437.GE3283@danh.dev","threadId":"53479","inReplyTo":"20200522104618.GA2050@spk-laptop","subject":"Re: [PATCH v8] diff: add config option relative","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-23T02:14:37Z","receivedAt":"2020-05-23T02:14:42Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Hi Laurent,\n\nOn 2020-05-22 12:46:18+0200, Laurent Arnoud <laurent@spkdev.net> wrote:\n> The `diff.relative` boolean option set to `true` shows only changes in\n> the current directory/value specified by the `path` argument of the\n> `relative` option and shows pathnames relative to the aforementioned\n> directory.\n> \n> Teach `--no-relative` to override earlier `--relative`\n> \n> Add for git-format-patch(1) options documentation `--relative` and\n> `--no-relative`\n> \n> Signed-off-by: Laurent Arnoud <laurent@spkdev.net>\n\nLook good to me, I also run those tests and manually tested some\nusecase I'm interested in.\n\n-- \nDanh\n"}]}