* [PATCH v2] git-config support for diff.relative setting
@ 2014-12-20 9:24 kelson
2014-12-20 14:32 ` Philip Oakley
0 siblings, 1 reply; 5+ messages in thread
From: kelson @ 2014-12-20 9:24 UTC (permalink / raw)
To: Git Mailing List; +Cc: Duy Nguyen, Jonathan Nieder
By default, git-diff shows changes and pathnames relative to the
repository root. Setting the diff.relative config option to "true" shows
pathnames relative to the current directory and excludes changes outside
this directory (identical to "git diff --relative").
Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
Documentation/diff-config.txt | 6 ++++++
diff.c | 8 ++++++++
t/t4045-diff-relative.sh | 21 +++++++++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index b001779..10f183f 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -182,3 +182,9 @@ diff.algorithm::
low-occurrence common elements".
--
+
+
+diff.relative::
+ By default, linkgit:git-diff[1] shows changes and pathnames
+ relative to the repository root. Setting this variable to
+ `true` shows pathnames relative to the current directory and
+ excludes changes outside this directory.
diff --git a/diff.c b/diff.c
index d1bd534..03697a9 100644
--- a/diff.c
+++ b/diff.c
@@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const char
*value, void *cb)
return 0;
}
+ if (!strcmp(var, "diff.relative")) {
+ if (git_config_bool(var, value))
+ DIFF_OPT_SET(&default_diff_options, RELATIVE_NAME);
+ else
+ DIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME);
+ return 0;
+ }
+
if (git_color_config(var, value, cb) < 0)
return -1;
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 3950f50..8c8fe0b 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -29,6 +29,23 @@ test_expect_success "-p $*" "
"
}
+check_config() {
+expect=$1; shift
+cat >expected <<EOF
+diff --git a/$expect b/$expect
+new file mode 100644
+index 0000000..25c05ef
+--- /dev/null
++++ b/$expect
+@@ -0,0 +1 @@
++other content
+EOF
+test_expect_success "git-config diff.relative=true in $1" "
+ (cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) &&
+ test_cmp expected actual
+"
+}
+
check_numstat() {
expect=$1; shift
cat >expected <<EOF
@@ -69,5 +86,9 @@ for type in diff numstat stat raw; do
check_$type file2 --relative=subdir
check_$type dir/file2 --relative=sub
done
+for type in config; do
+ check_$type file2 subdir/
+ check_$type file2 subdir
+done
test_done
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] git-config support for diff.relative setting
2014-12-20 9:24 [PATCH v2] git-config support for diff.relative setting kelson
@ 2014-12-20 14:32 ` Philip Oakley
2014-12-21 2:58 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Philip Oakley @ 2014-12-20 14:32 UTC (permalink / raw)
To: kelson, Git Mailing List; +Cc: Duy Nguyen, Jonathan Nieder
From: <kelson@shysecurity.com>
> By default, git-diff shows changes and pathnames relative to the
> repository root. Setting the diff.relative config option to "true"
> shows pathnames relative to the current directory and excludes changes
> outside this directory (identical to "git diff --relative").
Shouldn't this `(identical to "git diff --relative")` also be included
in the documentation change? It would truly clarify the intenbt for the
reader.
>
> Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
> ---
> Documentation/diff-config.txt | 6 ++++++
> diff.c | 8 ++++++++
> t/t4045-diff-relative.sh | 21 +++++++++++++++++++++
> 3 files changed, 35 insertions(+)
>
> diff --git a/Documentation/diff-config.txt
> b/Documentation/diff-config.txt
> index b001779..10f183f 100644
> --- a/Documentation/diff-config.txt
> +++ b/Documentation/diff-config.txt
> @@ -182,3 +182,9 @@ diff.algorithm::
> low-occurrence common elements".
> --
> +
> +
> +diff.relative::
> + By default, linkgit:git-diff[1] shows changes and pathnames
> + relative to the repository root. Setting this variable to
> + `true` shows pathnames relative to the current directory and
> + excludes changes outside this directory.
Insert `(identical to "git diff --relative")` here?
> diff --git a/diff.c b/diff.c
> index d1bd534..03697a9 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const
> char
> *value, void *cb)
> return 0;
> }
>
> + if (!strcmp(var, "diff.relative")) {
> + if (git_config_bool(var, value))
> + DIFF_OPT_SET(&default_diff_options, RELATIVE_NAME);
> + else
> + DIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME);
> + return 0;
> + }
> +
> if (git_color_config(var, value, cb) < 0)
> return -1;
>
> diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
> index 3950f50..8c8fe0b 100755
> --- a/t/t4045-diff-relative.sh
> +++ b/t/t4045-diff-relative.sh
> @@ -29,6 +29,23 @@ test_expect_success "-p $*" "
> "
> }
>
> +check_config() {
> +expect=$1; shift
> +cat >expected <<EOF
> +diff --git a/$expect b/$expect
> +new file mode 100644
> +index 0000000..25c05ef
> +--- /dev/null
> ++++ b/$expect
> +@@ -0,0 +1 @@
> ++other content
> +EOF
> +test_expect_success "git-config diff.relative=true in $1" "
> + (cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) &&
> + test_cmp expected actual
> +"
> +}
> +
> check_numstat() {
> expect=$1; shift
> cat >expected <<EOF
> @@ -69,5 +86,9 @@ for type in diff numstat stat raw; do
> check_$type file2 --relative=subdir
> check_$type dir/file2 --relative=sub
> done
> +for type in config; do
> + check_$type file2 subdir/
> + check_$type file2 subdir
> +done
>
> test_done
> --
Philip
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] git-config support for diff.relative setting
2014-12-20 14:32 ` Philip Oakley
@ 2014-12-21 2:58 ` Junio C Hamano
2014-12-21 19:41 ` kelson
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-12-21 2:58 UTC (permalink / raw)
To: Philip Oakley; +Cc: kelson, Git Mailing List, Duy Nguyen, Jonathan Nieder
"Philip Oakley" <philipoakley@iee.org> writes:
> From: <kelson@shysecurity.com>
>> By default, git-diff shows changes and pathnames relative to the
>> repository root. Setting the diff.relative config option to "true"
>> shows pathnames relative to the current directory and excludes
>> changes outside this directory (identical to "git diff --relative").
> Shouldn't this `(identical to "git diff --relative")` also be included
> in the documentation change? It would truly clarify the intenbt for
> the reader.
A configuration that sticks a non-default behaviour without a way to
revert to the default is a no-no.
There should be a way to run non-relative diff in a repository that
has the configuration set, perhaps by overriding with some command
line option (e.g. "--no-relative").
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] git-config support for diff.relative setting
2014-12-21 2:58 ` Junio C Hamano
@ 2014-12-21 19:41 ` kelson
2014-12-21 22:46 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: kelson @ 2014-12-21 19:41 UTC (permalink / raw)
To: Junio C Hamano, Philip Oakley
Cc: Git Mailing List, Duy Nguyen, Jonathan Nieder
> "Philip Oakley" <philipoakley@iee.org> wrote:
> Shouldn't this `(identical to "git diff --relative")` also be
>included in the documentation change? It would truly clarify the
> intenbt for the reader.
Updated as follows:
+diff.relative::
+ Show pathnames relative to the current directory and exclude
+ changes outside this directory; equivalent to the 'git diff'
+ option '--relative'.
> "Junio C Hamano" <gitster@pobox.com> wrote:
> There should be a way to run non-relative diff in a repository that
> has the configuration set, perhaps by overriding with some command
> line option (e.g. "--no-relative").
Good idea; I'll put together a second patch for a "--no-relative" option
to disable diff.relative.
-----Original Message-----
From: Junio C Hamano <gitster@pobox.com>
Sent: 12/20/2014 09:58 PM
To: Philip Oakley <philipoakley@iee.org>
CC: <kelson@shysecurity.com>, "Git Mailing List" <git@vger.kernel.org>,
"Duy Nguyen" <pclouds@gmail.com>, "Jonathan Nieder" <jrnieder@gmail.com>
Subject: Re: [PATCH v2] git-config support for diff.relative setting
"Philip Oakley" <philipoakley@iee.org> writes:
> From: <kelson@shysecurity.com>
>> By default, git-diff shows changes and pathnames relative to the
>> repository root. Setting the diff.relative config option to "true"
>> shows pathnames relative to the current directory and excludes
>> changes outside this directory (identical to "git diff --relative").
> Shouldn't this `(identical to "git diff --relative")` also be included
> in the documentation change? It would truly clarify the intenbt for
> the reader.
A configuration that sticks a non-default behaviour without a way to
revert to the default is a no-no.
There should be a way to run non-relative diff in a repository that
has the configuration set, perhaps by overriding with some command
line option (e.g. "--no-relative").
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] git-config support for diff.relative setting
2014-12-21 19:41 ` kelson
@ 2014-12-21 22:46 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-12-21 22:46 UTC (permalink / raw)
To: kelson; +Cc: Philip Oakley, Git Mailing List, Duy Nguyen, Jonathan Nieder
kelson@shysecurity.com writes:
>> "Philip Oakley" <philipoakley@iee.org> wrote:
>> Shouldn't this `(identical to "git diff --relative")` also be
>>included in the documentation change? It would truly clarify the
>> intenbt for the reader.
>
> Updated as follows:
> +diff.relative::
> + Show pathnames relative to the current directory and exclude
> + changes outside this directory; equivalent to the 'git diff'
> + option '--relative'.
>
>> "Junio C Hamano" <gitster@pobox.com> wrote:
>> There should be a way to run non-relative diff in a repository that
>> has the configuration set, perhaps by overriding with some command
>> line option (e.g. "--no-relative").
>
> Good idea; I'll put together a second patch for a "--no-relative"
> option to disable diff.relative.
The order should be first to add --no-relative, which should allow
you to say
$ alias gd "git diff --relative"
$ gd --no-relative
which would expand to "git diff --relative --no-relative" to defeat
the earlier one on the command line, and then add diff.relative in
the second patch, I would think. A natural consequence of the
latter would be that these would steps work as expected:
$ git config diff.relative no
$ git diff
$ git diff --relative
$ git diff --no-relative
$ git config diff.relative yes
$ git diff
$ git diff --relative
$ git diff --no-relative
which should be tested in a new set of tests added to t4045.
For the first patch, I would expect a new set of tests added to
t4045 to check at least the following:
$ git diff --no-relative
$ git diff --no-relative --relative
$ git diff --relative --no-relative
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-21 22:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-20 9:24 [PATCH v2] git-config support for diff.relative setting kelson
2014-12-20 14:32 ` Philip Oakley
2014-12-21 2:58 ` Junio C Hamano
2014-12-21 19:41 ` kelson
2014-12-21 22:46 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).