{"thread":{"id":"38220","subject":"[PATCH v3 2/2] git-config support for diff.relative setting","startedAt":"2014-12-21T20:23:15Z","lastAt":"2015-02-12T23:17:56Z","messageCount":5,"participants":["kelson@shysecurity.com","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"253904","messageId":"54972C33.4030009@shysecurity.com","threadId":"38220","inReplyTo":null,"subject":"[PATCH v3 2/2] git-config support for diff.relative setting","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2014-12-21T20:23:15Z","receivedAt":"2014-12-21T20:23:15Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"added support for `git diff --no-relative` (code, documentation, and tests)\n\ngit-diff --no-relative overrides diff.relative config setting and prior \ngit-diff --relative[=<path>] options.\n---\n  Documentation/diff-config.txt  |  1 +\n  Documentation/diff-options.txt |  4 +++\n  diff.c                         |  2 ++\n  t/t4045-diff-relative.sh       | 56 \n+++++++++++++++++++++++++++++++++---------\n  4 files changed, 51 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex 496e9b0..b8a7c60 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -107,6 +107,7 @@ 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+\tOverridden by the '--no-relative' linkgit:git-diff[1] option.\n\n  diff.renameLimit::\n  \tThe number of files to consider when performing the copy/rename\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 6cb083a..7470b16 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -448,6 +448,10 @@ 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+\n+--no-relative::\n+\tTurn off relative pathnames, even when the configuration\n+\tfile gives the default to do so.\n  endif::git-format-patch[]\n\n  -a::\ndiff --git a/diff.c b/diff.c\nindex 03697a9..9e4ec1f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3703,6 +3703,8 @@ int diff_opt_parse(struct diff_options *options, \nconst char **av, int ac)\n  \t\tDIFF_OPT_SET(options, RELATIVE_NAME);\n  \t\toptions->prefix = arg;\n  \t}\n+\telse if (!strcmp(arg, \"--no-relative\"))\n+\t\tDIFF_OPT_CLR(options, RELATIVE_NAME);\n\n  \t/* xdiff options */\n  \telse if (!strcmp(arg, \"--minimal\"))\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 8c8fe0b..b2764d5 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -12,8 +12,8 @@ test_expect_success 'setup' '\n  \tgit commit -m one\n  '\n\n-check_diff() {\n-expect=$1; shift\n+store_diff_relative() {\n+expect=$1;\n  cat >expected <<EOF\n  diff --git a/$expect b/$expect\n  new file mode 100644\n@@ -23,29 +23,61 @@ index 0000000..25c05ef\n  @@ -0,0 +1 @@\n  +other content\n  EOF\n-test_expect_success \"-p $*\" \"\n-\tgit diff -p $* HEAD^ >actual &&\n-\ttest_cmp expected actual\n-\"\n  }\n\n-check_config() {\n-expect=$1; shift\n+store_diff_absolute() {\n+expect=$1;\n  cat >expected <<EOF\n-diff --git a/$expect b/$expect\n+diff --git a/file1 b/file1\n+new file mode 100644\n+index 0000000..d95f3ad\n+--- /dev/null\n++++ b/file1\n+@@ -0,0 +1 @@\n++content\n+diff --git a/subdir/file2 b/subdir/file2\n  new file mode 100644\n  index 0000000..25c05ef\n  --- /dev/null\n-+++ b/$expect\n++++ b/subdir/file2\n  @@ -0,0 +1 @@\n  +other content\n  EOF\n+}\n+\n+check_diff() {\n+store_diff_relative $1; shift\n+test_expect_success \"-p $*\" \"\n+\tgit diff -p $* HEAD^ >actual &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n+check_option_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"-p $* --no-relative\" \"\n+\tgit diff -p $* HEAD^ --no-relative >actual &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n+check_config() {\n+store_diff_relative $1; shift\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_config_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"--no-relative w/ git-config diff.relative=true in \n$1\" \"\n+\t(cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ \n >../actual) &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n+\n  check_numstat() {\n  expect=$1; shift\n  cat >expected <<EOF\n@@ -81,12 +113,12 @@ test_expect_success \"--raw $*\" \"\n  \"\n  }\n\n-for type in diff numstat stat raw; do\n+for type in diff option_no_relative numstat stat raw; do\n  \tcheck_$type file2 --relative=subdir/\n  \tcheck_$type file2 --relative=subdir\n  \tcheck_$type dir/file2 --relative=sub\n  done\n-for type in config; do\n+for type in config config_no_relative; do\n  \tcheck_$type file2 subdir/\n  \tcheck_$type file2 subdir\n  done\n-- \n1.9.1\n"},{"id":"254204","messageId":"54A2E748.3010008@shysecurity.com","threadId":"38220","inReplyTo":"54972C33.4030009@shysecurity.com","subject":"[PATCH v3 2/2] git-config support for diff.relative setting","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2014-12-30T17:56:24Z","receivedAt":"2014-12-30T17:56:24Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"added support for `git diff --no-relative` (code, documentation, and tests)\n\ngit-diff --no-relative overrides diff.relative config setting and prior \ngit-diff --relative[=<path>] options.\n---\n  Documentation/diff-config.txt  |  1 +\n  Documentation/diff-options.txt |  4 +++\n  diff.c                         |  2 ++\n  t/t4045-diff-relative.sh       | 56 \n+++++++++++++++++++++++++++++++++---------\n  4 files changed, 51 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex 496e9b0..b8a7c60 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -107,6 +107,7 @@ diff.relative::\n      Show pathnames relative to the current directory and exclude\n      changes outside this directory; equivalent to the 'git diff'\n      option '--relative'.\n+    Overridden by the '--no-relative' linkgit:git-diff[1] option.\n\n  diff.renameLimit::\n      The number of files to consider when performing the copy/rename\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 6cb083a..7470b16 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -448,6 +448,10 @@ ifndef::git-format-patch[]\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.\n+\n+--no-relative::\n+    Turn off relative pathnames, even when the configuration\n+    file gives the default to do so.\n  endif::git-format-patch[]\n\n  -a::\ndiff --git a/diff.c b/diff.c\nindex 03697a9..9e4ec1f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3703,6 +3703,8 @@ int diff_opt_parse(struct diff_options *options, \nconst char **av, int ac)\n          DIFF_OPT_SET(options, RELATIVE_NAME);\n          options->prefix = arg;\n      }\n+    else if (!strcmp(arg, \"--no-relative\"))\n+        DIFF_OPT_CLR(options, RELATIVE_NAME);\n\n      /* xdiff options */\n      else if (!strcmp(arg, \"--minimal\"))\ndiff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh\nindex 8c8fe0b..b2764d5 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -12,8 +12,8 @@ test_expect_success 'setup' '\n      git commit -m one\n  '\n\n-check_diff() {\n-expect=$1; shift\n+store_diff_relative() {\n+expect=$1;\n  cat >expected <<EOF\n  diff --git a/$expect b/$expect\n  new file mode 100644\n@@ -23,29 +23,61 @@ index 0000000..25c05ef\n  @@ -0,0 +1 @@\n  +other content\n  EOF\n-test_expect_success \"-p $*\" \"\n-    git diff -p $* HEAD^ >actual &&\n-    test_cmp expected actual\n-\"\n  }\n\n-check_config() {\n-expect=$1; shift\n+store_diff_absolute() {\n+expect=$1;\n  cat >expected <<EOF\n-diff --git a/$expect b/$expect\n+diff --git a/file1 b/file1\n+new file mode 100644\n+index 0000000..d95f3ad\n+--- /dev/null\n++++ b/file1\n+@@ -0,0 +1 @@\n++content\n+diff --git a/subdir/file2 b/subdir/file2\n  new file mode 100644\n  index 0000000..25c05ef\n  --- /dev/null\n-+++ b/$expect\n++++ b/subdir/file2\n  @@ -0,0 +1 @@\n  +other content\n  EOF\n+}\n+\n+check_diff() {\n+store_diff_relative $1; shift\n+test_expect_success \"-p $*\" \"\n+    git diff -p $* HEAD^ >actual &&\n+    test_cmp expected actual\n+\"\n+}\n+\n+check_option_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"-p $* --no-relative\" \"\n+    git diff -p $* HEAD^ --no-relative >actual &&\n+    test_cmp expected actual\n+\"\n+}\n+\n+check_config() {\n+store_diff_relative $1; shift\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_config_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"--no-relative w/ git-config diff.relative=true in \n$1\" \"\n+    (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ \n >../actual) &&\n+    test_cmp expected actual\n+\"\n+}\n+\n+\n  check_numstat() {\n  expect=$1; shift\n  cat >expected <<EOF\n@@ -81,12 +113,12 @@ test_expect_success \"--raw $*\" \"\n  \"\n  }\n\n-for type in diff numstat stat raw; do\n+for type in diff option_no_relative numstat stat raw; do\n      check_$type file2 --relative=subdir/\n      check_$type file2 --relative=subdir\n      check_$type dir/file2 --relative=sub\n  done\n-for type in config; do\n+for type in config config_no_relative; do\n      check_$type file2 subdir/\n      check_$type file2 subdir\n  done\n-- \n1.9.1\n"},{"id":"254211","messageId":"54A2FDD2.3010707@shysecurity.com","threadId":"38220","inReplyTo":"54A2E748.3010008@shysecurity.com","subject":"[PATCH 2/2] support for --no-relative and diff.relative","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2014-12-30T19:32:34Z","receivedAt":"2014-12-30T19:32:34Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"added diff.relative setting for git-diff (code, documentation, and tests)\n\n`git-config diff.relative=true` causes `git diff` to behave like `git \ndiff --relative`. Overridden by `git diff --no-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      | 20 ++++++++++++++++++++\n  3 files changed, 34 insertions(+)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex b001779..b8a7c60 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -103,6 +103,12 @@ diff.orderfile::\n  \tone shell glob pattern per line.\n  \tCan be overridden by the '-O' option to linkgit:git-diff[1].\n\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+\tOverridden by the '--no-relative' linkgit:git-diff[1] option.\n+\n  diff.renameLimit::\n  \tThe number of files to consider when performing the copy/rename\n  \tdetection; equivalent to the 'git diff' option '-l'.\ndiff --git a/diff.c b/diff.c\nindex 7bceba8..9e4ec1f 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 ccd67c7..c2c15e4 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -104,10 +104,30 @@ test_expect_success \"--raw $*\" \"\n  \"\n  }\n\n+check_config() {\n+store_diff_relative $1; shift\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_config_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"--no-relative w/ git-config diff.relative=true in \n$1\" \"\n+\t(cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ \n >../actual) &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n  for type in diff numstat stat raw norel_pre norel_post; do\n  \tcheck_$type file2 --relative=subdir/\n  \tcheck_$type file2 --relative=subdir\n  \tcheck_$type dir/file2 --relative=sub\n  done\n+for type in config config_no_relative; do\n+\tcheck_$type file2 subdir/\n+\tcheck_$type file2 subdir\n+done\n\n  test_done\n--\n1.9.1\n"},{"id":"254345","messageId":"54AC0B2E.3050205@shysecurity.com","threadId":"38220","inReplyTo":"54A2FDD2.3010707@shysecurity.com","subject":"[PATCH 2/2] support for --no-relative and diff.relative","fromName":"","fromEmail":"kelson@shysecurity.com","sentAt":"2015-01-06T16:19:58Z","receivedAt":"2015-01-06T16:19:58Z","isPatch":true,"sender":{"key":"kelson@shysecurity.com","avatar":null},"body":"added diff.relative setting for git-diff (code, documentation, and tests)\n\n`git-config diff.relative=true` causes `git diff` to behave like `git \ndiff --relative`. Overridden by `git diff --no-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      | 20 ++++++++++++++++++++\n  3 files changed, 34 insertions(+)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex b001779..b8a7c60 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -103,6 +103,12 @@ diff.orderfile::\n  \tone shell glob pattern per line.\n  \tCan be overridden by the '-O' option to linkgit:git-diff[1].\n\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+\tOverridden by the '--no-relative' linkgit:git-diff[1] option.\n+\n  diff.renameLimit::\n  \tThe number of files to consider when performing the copy/rename\n  \tdetection; equivalent to the 'git diff' option '-l'.\ndiff --git a/diff.c b/diff.c\nindex 7bceba8..9e4ec1f 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 ccd67c7..c2c15e4 100755\n--- a/t/t4045-diff-relative.sh\n+++ b/t/t4045-diff-relative.sh\n@@ -104,10 +104,30 @@ test_expect_success \"--raw $*\" \"\n  \"\n  }\n\n+check_config() {\n+store_diff_relative $1; shift\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_config_no_relative() {\n+store_diff_absolute $1; shift\n+test_expect_success \"--no-relative w/ git-config diff.relative=true in \n$1\" \"\n+\t(cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ \n >../actual) &&\n+\ttest_cmp expected actual\n+\"\n+}\n+\n  for type in diff numstat stat raw norel_pre norel_post; do\n  \tcheck_$type file2 --relative=subdir/\n  \tcheck_$type file2 --relative=subdir\n  \tcheck_$type dir/file2 --relative=sub\n  done\n+for type in config config_no_relative; do\n+\tcheck_$type file2 subdir/\n+\tcheck_$type file2 subdir\n+done\n\n  test_done\n--\n1.9.1\n"},{"id":"256039","messageId":"xmqq1tlupvmj.fsf@gitster.dls.corp.google.com","threadId":"38220","inReplyTo":"54A2FDD2.3010707@shysecurity.com","subject":"Re: [PATCH 2/2] support for --no-relative and diff.relative","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-12T23:17:56Z","receivedAt":"2015-02-12T23:17:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"These two patches\n\n    * bp/diff-relative-config (2015-01-07) 2 commits\n     - diff: teach diff.relative to give default to --relative=<value>\n     - diff: teach --no-relative to override earlier --relative\n\nhave been sitting in my Undecided pile, primarily because I am wary\nof touching a core command like \"diff\" with just me reviewing.  I\nthink they look reasonably safe (especially since the configuration\nparsing is done only in diff_ui_config()), but I may have overlooked\nsomething obvious and silly.\n\nAnother set or two of eyeballs are very much appreciated.\n\nThanks.\n"}]}