{"thread":{"id":"38212","subject":"[PATCH v2] git-config support for diff.relative setting","startedAt":"2014-12-20T09:24:36Z","lastAt":"2014-12-21T22:46:16Z","messageCount":5,"participants":["kelson@shysecurity.com","Philip Oakley","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"253876","messageId":"54954054.7080201@shysecurity.com","threadId":"38212","inReplyTo":null,"subject":"[PATCH v2] git-config support for diff.relative setting","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2014-12-20T09:24:36Z","receivedAt":"2014-12-20T09:24:36Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"By default, git-diff shows changes and pathnames relative to the \nrepository root. Setting the diff.relative config option to \"true\" shows \npathnames relative to the current directory and excludes changes outside \nthis directory (identical to \"git diff --relative\").\n\nSigned-off-by: Brandon Phillips <kelson@shysecurity.com>\n---\n  Documentation/diff-config.txt |  6 ++++++\n  diff.c                        |  8 ++++++++\n  t/t4045-diff-relative.sh      | 21 +++++++++++++++++++++\n  3 files changed, 35 insertions(+)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex b001779..10f183f 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -182,3 +182,9 @@ diff.algorithm::\n  \tlow-occurrence common elements\".\n  --\n  +\n+\n+diff.relative::\n+\tBy default, linkgit:git-diff[1] shows changes and pathnames\n+\trelative to the repository root. Setting this variable to\n+\t`true` shows pathnames relative to the current directory and\n+\texcludes changes outside this directory.\ndiff --git a/diff.c b/diff.c\nindex d1bd534..03697a9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const char\n*value, void *cb)\n  \t\treturn 0;\n  \t}\n\n+\tif (!strcmp(var, \"diff.relative\")) {\n+\t\tif (git_config_bool(var, value))\n+\t\t\tDIFF_OPT_SET(&default_diff_options, RELATIVE_NAME);\n+\t\telse\n+\t\t\tDIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME);\n+\t\treturn 0;\n+\t}\n+\n  \tif (git_color_config(var, value, cb) < 0)\n  \t\treturn -1;\n\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 3950f50..8c8fe0b 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -29,6 +29,23 @@ test_expect_success \"-p $*\" \"\n  \"\n  }\n\n+check_config() {\n+expect=$1; shift\n+cat >expected <<EOF\n+diff --git a/$expect b/$expect\n+new file mode 100644\n+index 0000000..25c05ef\n+--- /dev/null\n++++ b/$expect\n+@@ -0,0 +1 @@\n++other content\n+EOF\n+test_expect_success \"git-config diff.relative=true in $1\" \"\n+\t(cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n  check_numstat() {\n  expect=$1; shift\n  cat >expected <<EOF\n@@ -69,5 +86,9 @@ for type in diff numstat stat raw; do\n  \tcheck_$type file2 --relative=subdir\n  \tcheck_$type dir/file2 --relative=sub\n  done\n+for type in config; do\n+\tcheck_$type file2 subdir/\n+\tcheck_$type file2 subdir\n+done\n\n  test_done\n-- \n1.9.1\n"},{"id":"253879","messageId":"CFEBFB254713492C988FED7E11475227@PhilipOakley","threadId":"38212","inReplyTo":"54954054.7080201@shysecurity.com","subject":"Re: [PATCH v2] git-config support for diff.relative setting","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":null,"receivedAt":"2014-12-20T12:39:16Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: <kelson@shysecurity.com>\n> By default, git-diff shows changes and pathnames relative to the \n> repository root. Setting the diff.relative config option to \"true\" \n> shows pathnames relative to the current directory and excludes changes \n> outside this directory (identical to \"git diff --relative\").\nShouldn't this `(identical to \"git diff --relative\")` also be included \nin the documentation change? It would truly clarify the intenbt for the \nreader.\n\n>\n> Signed-off-by: Brandon Phillips <kelson@shysecurity.com>\n> ---\n>  Documentation/diff-config.txt |  6 ++++++\n>  diff.c                        |  8 ++++++++\n>  t/t4045-diff-relative.sh      | 21 +++++++++++++++++++++\n>  3 files changed, 35 insertions(+)\n>\n> diff --git a/Documentation/diff-config.txt \n> b/Documentation/diff-config.txt\n> index b001779..10f183f 100644\n> --- a/Documentation/diff-config.txt\n> +++ b/Documentation/diff-config.txt\n> @@ -182,3 +182,9 @@ diff.algorithm::\n>  low-occurrence common elements\".\n>  --\n>  +\n> +\n> +diff.relative::\n> + By default, linkgit:git-diff[1] shows changes and pathnames\n> + relative to the repository root. Setting this variable to\n> + `true` shows pathnames relative to the current directory and\n> + excludes changes outside this directory.\n    Insert `(identical to \"git diff --relative\")` here?\n\n> diff --git a/diff.c b/diff.c\n> index d1bd534..03697a9 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const \n> char\n> *value, void *cb)\n>  return 0;\n>  }\n>\n> + if (!strcmp(var, \"diff.relative\")) {\n> + if (git_config_bool(var, value))\n> + DIFF_OPT_SET(&default_diff_options, RELATIVE_NAME);\n> + else\n> + DIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME);\n> + return 0;\n> + }\n> +\n>  if (git_color_config(var, value, cb) < 0)\n>  return -1;\n>\n> diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\n> index 3950f50..8c8fe0b 100755\n> --- a/t/t4045-diff-relative.sh\n> +++ b/t/t4045-diff-relative.sh\n> @@ -29,6 +29,23 @@ test_expect_success \"-p $*\" \"\n>  \"\n>  }\n>\n> +check_config() {\n> +expect=$1; shift\n> +cat >expected <<EOF\n> +diff --git a/$expect b/$expect\n> +new file mode 100644\n> +index 0000000..25c05ef\n> +--- /dev/null\n> ++++ b/$expect\n> +@@ -0,0 +1 @@\n> ++other content\n> +EOF\n> +test_expect_success \"git-config diff.relative=true in $1\" \"\n> + (cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) &&\n> + test_cmp expected actual\n> +\"\n> +}\n> +\n>  check_numstat() {\n>  expect=$1; shift\n>  cat >expected <<EOF\n> @@ -69,5 +86,9 @@ for type in diff numstat stat raw; do\n>  check_$type file2 --relative=subdir\n>  check_$type dir/file2 --relative=sub\n>  done\n> +for type in config; do\n> + check_$type file2 subdir/\n> + check_$type file2 subdir\n> +done\n>\n>  test_done\n> -- \nPhilip \n"},{"id":"253887","messageId":"xmqq61d5d7yn.fsf@gitster.dls.corp.google.com","threadId":"38212","inReplyTo":"CFEBFB254713492C988FED7E11475227@PhilipOakley","subject":"Re: [PATCH v2] git-config support for diff.relative setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-21T02:58:56Z","receivedAt":"2014-12-21T02:58:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Philip Oakley\" <philipoakley@iee.org> writes:\n\n> From: <kelson@shysecurity.com>\n>> By default, git-diff shows changes and pathnames relative to the\n>> repository root. Setting the diff.relative config option to \"true\"\n>> shows pathnames relative to the current directory and excludes\n>> changes outside this directory (identical to \"git diff --relative\").\n> Shouldn't this `(identical to \"git diff --relative\")` also be included\n> in the documentation change? It would truly clarify the intenbt for\n> the reader.\n\nA configuration that sticks a non-default behaviour without a way to\nrevert to the default is a no-no.\n\nThere should be a way to run non-relative diff in a repository that\nhas the configuration set, perhaps by overriding with some command\nline option (e.g. \"--no-relative\").\n"},{"id":"253901","messageId":"54972281.9050603@shysecurity.com","threadId":"38212","inReplyTo":"xmqq61d5d7yn.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2] git-config support for diff.relative setting","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2014-12-21T19:41:53Z","receivedAt":"2014-12-21T19:41:53Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"> \"Philip Oakley\" <philipoakley@iee.org> wrote:\n> Shouldn't this `(identical to \"git diff --relative\")` also be\n>included in the documentation change? It would truly clarify the\n> intenbt for the reader.\n\nUpdated as follows:\n+diff.relative::\n+\tShow pathnames relative to the current directory and exclude\n+\tchanges outside this directory; equivalent to the 'git diff'\n+\toption '--relative'.\n\n> \"Junio C Hamano\" <gitster@pobox.com> wrote:\n> There should be a way to run non-relative diff in a repository that\n> has the configuration set, perhaps by overriding with some command\n> line option (e.g. \"--no-relative\").\n\nGood idea; I'll put together a second patch for a \"--no-relative\" option \nto disable diff.relative.\n\n-----Original Message-----\nFrom: Junio C Hamano <gitster@pobox.com>\nSent: 12/20/2014 09:58 PM\nTo: Philip Oakley <philipoakley@iee.org>\nCC: <kelson@shysecurity.com>,  \"Git Mailing List\" <git@vger.kernel.org>, \n  \"Duy Nguyen\" <pclouds@gmail.com>,  \"Jonathan Nieder\" <jrnieder@gmail.com>\nSubject: Re: [PATCH v2] git-config support for diff.relative setting\n\n\"Philip Oakley\" <philipoakley@iee.org> writes:\n> From: <kelson@shysecurity.com>\n>> By default, git-diff shows changes and pathnames relative to the\n>> repository root. Setting the diff.relative config option to \"true\"\n>> shows pathnames relative to the current directory and excludes\n>> changes outside this directory (identical to \"git diff --relative\").\n> Shouldn't this `(identical to \"git diff --relative\")` also be included\n> in the documentation change? It would truly clarify the intenbt for\n> the reader.\n\nA configuration that sticks a non-default behaviour without a way to\nrevert to the default is a no-no.\n\nThere should be a way to run non-relative diff in a repository that\nhas the configuration set, perhaps by overriding with some command\nline option (e.g. \"--no-relative\").\n"},{"id":"253909","messageId":"xmqqppbcbozr.fsf@gitster.dls.corp.google.com","threadId":"38212","inReplyTo":"54972281.9050603@shysecurity.com","subject":"Re: [PATCH v2] git-config support for diff.relative setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-21T22:46:16Z","receivedAt":"2014-12-21T22:46:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"kelson@shysecurity.com writes:\n\n>> \"Philip Oakley\" <philipoakley@iee.org> wrote:\n>> Shouldn't this `(identical to \"git diff --relative\")` also be\n>>included in the documentation change? It would truly clarify the\n>> intenbt for the reader.\n>\n> Updated as follows:\n> +diff.relative::\n> +\tShow pathnames relative to the current directory and exclude\n> +\tchanges outside this directory; equivalent to the 'git diff'\n> +\toption '--relative'.\n>\n>> \"Junio C Hamano\" <gitster@pobox.com> wrote:\n>> There should be a way to run non-relative diff in a repository that\n>> has the configuration set, perhaps by overriding with some command\n>> line option (e.g. \"--no-relative\").\n>\n> Good idea; I'll put together a second patch for a \"--no-relative\"\n> option to disable diff.relative.\n\nThe order should be first to add --no-relative, which should allow\nyou to say\n\n\t$ alias gd \"git diff --relative\"\n        $ gd --no-relative\n\nwhich would expand to \"git diff --relative --no-relative\" to defeat\nthe earlier one on the command line, and then add diff.relative in\nthe second patch, I would think.  A natural consequence of the\nlatter would be that these would steps work as expected:\n\n\t$ git config diff.relative no\n        $ git diff\n        $ git diff --relative\n        $ git diff --no-relative\n        $ git config diff.relative yes\n        $ git diff\n        $ git diff --relative\n        $ git diff --no-relative\n\nwhich should be tested in a new set of tests added to t4045.\n\nFor the first patch, I would expect a new set of tests added to\nt4045 to check at least the following:\n\n\t$ git diff --no-relative\n\t$ git diff --no-relative --relative\n\t$ git diff --relative --no-relative\n\nThanks.\n"}]}