* [PATCH v3 2/2] git-config support for diff.relative setting
@ 2014-12-21 20:23 kelson
2014-12-30 17:56 ` kelson
0 siblings, 1 reply; 5+ messages in thread
From: kelson @ 2014-12-21 20:23 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Philip Oakley, Duy Nguyen, Jonathan Nieder
added support for `git diff --no-relative` (code, documentation, and tests)
git-diff --no-relative overrides diff.relative config setting and prior
git-diff --relative[=<path>] options.
---
Documentation/diff-config.txt | 1 +
Documentation/diff-options.txt | 4 +++
diff.c | 2 ++
t/t4045-diff-relative.sh | 56
+++++++++++++++++++++++++++++++++---------
4 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index 496e9b0..b8a7c60 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -107,6 +107,7 @@ diff.relative::
Show pathnames relative to the current directory and exclude
changes outside this directory; equivalent to the 'git diff'
option '--relative'.
+ Overridden by the '--no-relative' linkgit:git-diff[1] option.
diff.renameLimit::
The number of files to consider when performing the copy/rename
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 6cb083a..7470b16 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -448,6 +448,10 @@ ifndef::git-format-patch[]
not in a subdirectory (e.g. in a bare repository), you
can name which subdirectory to make the output relative
to by giving a <path> as an argument.
+
+--no-relative::
+ Turn off relative pathnames, even when the configuration
+ file gives the default to do so.
endif::git-format-patch[]
-a::
diff --git a/diff.c b/diff.c
index 03697a9..9e4ec1f 100644
--- a/diff.c
+++ b/diff.c
@@ -3703,6 +3703,8 @@ int diff_opt_parse(struct diff_options *options,
const char **av, int ac)
DIFF_OPT_SET(options, RELATIVE_NAME);
options->prefix = arg;
}
+ else if (!strcmp(arg, "--no-relative"))
+ DIFF_OPT_CLR(options, RELATIVE_NAME);
/* xdiff options */
else if (!strcmp(arg, "--minimal"))
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 8c8fe0b..b2764d5 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -12,8 +12,8 @@ test_expect_success 'setup' '
git commit -m one
'
-check_diff() {
-expect=$1; shift
+store_diff_relative() {
+expect=$1;
cat >expected <<EOF
diff --git a/$expect b/$expect
new file mode 100644
@@ -23,29 +23,61 @@ index 0000000..25c05ef
@@ -0,0 +1 @@
+other content
EOF
-test_expect_success "-p $*" "
- git diff -p $* HEAD^ >actual &&
- test_cmp expected actual
-"
}
-check_config() {
-expect=$1; shift
+store_diff_absolute() {
+expect=$1;
cat >expected <<EOF
-diff --git a/$expect b/$expect
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/file1
+@@ -0,0 +1 @@
++content
+diff --git a/subdir/file2 b/subdir/file2
new file mode 100644
index 0000000..25c05ef
--- /dev/null
-+++ b/$expect
++++ b/subdir/file2
@@ -0,0 +1 @@
+other content
EOF
+}
+
+check_diff() {
+store_diff_relative $1; shift
+test_expect_success "-p $*" "
+ git diff -p $* HEAD^ >actual &&
+ test_cmp expected actual
+"
+}
+
+check_option_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "-p $* --no-relative" "
+ git diff -p $* HEAD^ --no-relative >actual &&
+ test_cmp expected actual
+"
+}
+
+check_config() {
+store_diff_relative $1; shift
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_config_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "--no-relative w/ git-config diff.relative=true in
$1" "
+ (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^
>../actual) &&
+ test_cmp expected actual
+"
+}
+
+
check_numstat() {
expect=$1; shift
cat >expected <<EOF
@@ -81,12 +113,12 @@ test_expect_success "--raw $*" "
"
}
-for type in diff numstat stat raw; do
+for type in diff option_no_relative numstat stat raw; do
check_$type file2 --relative=subdir/
check_$type file2 --relative=subdir
check_$type dir/file2 --relative=sub
done
-for type in config; do
+for type in config config_no_relative; do
check_$type file2 subdir/
check_$type file2 subdir
done
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] git-config support for diff.relative setting
2014-12-21 20:23 [PATCH v3 2/2] git-config support for diff.relative setting kelson
@ 2014-12-30 17:56 ` kelson
2014-12-30 19:32 ` [PATCH 2/2] support for --no-relative and diff.relative kelson
0 siblings, 1 reply; 5+ messages in thread
From: kelson @ 2014-12-30 17:56 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Philip Oakley, Duy Nguyen, Jonathan Nieder
added support for `git diff --no-relative` (code, documentation, and tests)
git-diff --no-relative overrides diff.relative config setting and prior
git-diff --relative[=<path>] options.
---
Documentation/diff-config.txt | 1 +
Documentation/diff-options.txt | 4 +++
diff.c | 2 ++
t/t4045-diff-relative.sh | 56
+++++++++++++++++++++++++++++++++---------
4 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index 496e9b0..b8a7c60 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -107,6 +107,7 @@ diff.relative::
Show pathnames relative to the current directory and exclude
changes outside this directory; equivalent to the 'git diff'
option '--relative'.
+ Overridden by the '--no-relative' linkgit:git-diff[1] option.
diff.renameLimit::
The number of files to consider when performing the copy/rename
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 6cb083a..7470b16 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -448,6 +448,10 @@ ifndef::git-format-patch[]
not in a subdirectory (e.g. in a bare repository), you
can name which subdirectory to make the output relative
to by giving a <path> as an argument.
+
+--no-relative::
+ Turn off relative pathnames, even when the configuration
+ file gives the default to do so.
endif::git-format-patch[]
-a::
diff --git a/diff.c b/diff.c
index 03697a9..9e4ec1f 100644
--- a/diff.c
+++ b/diff.c
@@ -3703,6 +3703,8 @@ int diff_opt_parse(struct diff_options *options,
const char **av, int ac)
DIFF_OPT_SET(options, RELATIVE_NAME);
options->prefix = arg;
}
+ else if (!strcmp(arg, "--no-relative"))
+ DIFF_OPT_CLR(options, RELATIVE_NAME);
/* xdiff options */
else if (!strcmp(arg, "--minimal"))
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 8c8fe0b..b2764d5 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -12,8 +12,8 @@ test_expect_success 'setup' '
git commit -m one
'
-check_diff() {
-expect=$1; shift
+store_diff_relative() {
+expect=$1;
cat >expected <<EOF
diff --git a/$expect b/$expect
new file mode 100644
@@ -23,29 +23,61 @@ index 0000000..25c05ef
@@ -0,0 +1 @@
+other content
EOF
-test_expect_success "-p $*" "
- git diff -p $* HEAD^ >actual &&
- test_cmp expected actual
-"
}
-check_config() {
-expect=$1; shift
+store_diff_absolute() {
+expect=$1;
cat >expected <<EOF
-diff --git a/$expect b/$expect
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/file1
+@@ -0,0 +1 @@
++content
+diff --git a/subdir/file2 b/subdir/file2
new file mode 100644
index 0000000..25c05ef
--- /dev/null
-+++ b/$expect
++++ b/subdir/file2
@@ -0,0 +1 @@
+other content
EOF
+}
+
+check_diff() {
+store_diff_relative $1; shift
+test_expect_success "-p $*" "
+ git diff -p $* HEAD^ >actual &&
+ test_cmp expected actual
+"
+}
+
+check_option_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "-p $* --no-relative" "
+ git diff -p $* HEAD^ --no-relative >actual &&
+ test_cmp expected actual
+"
+}
+
+check_config() {
+store_diff_relative $1; shift
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_config_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "--no-relative w/ git-config diff.relative=true in
$1" "
+ (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^
>../actual) &&
+ test_cmp expected actual
+"
+}
+
+
check_numstat() {
expect=$1; shift
cat >expected <<EOF
@@ -81,12 +113,12 @@ test_expect_success "--raw $*" "
"
}
-for type in diff numstat stat raw; do
+for type in diff option_no_relative numstat stat raw; do
check_$type file2 --relative=subdir/
check_$type file2 --relative=subdir
check_$type dir/file2 --relative=sub
done
-for type in config; do
+for type in config config_no_relative; do
check_$type file2 subdir/
check_$type file2 subdir
done
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] support for --no-relative and diff.relative
2014-12-30 17:56 ` kelson
@ 2014-12-30 19:32 ` kelson
2015-01-06 16:19 ` kelson
2015-02-12 23:17 ` Junio C Hamano
0 siblings, 2 replies; 5+ messages in thread
From: kelson @ 2014-12-30 19:32 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Philip Oakley, Duy Nguyen, Jonathan Nieder
added diff.relative setting for git-diff (code, documentation, and tests)
`git-config diff.relative=true` causes `git diff` to behave like `git
diff --relative`. Overridden by `git diff --no-relative`.
Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
Documentation/diff-config.txt | 6 ++++++
diff.c | 8 ++++++++
t/t4045-diff-relative.sh | 20 ++++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index b001779..b8a7c60 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -103,6 +103,12 @@ diff.orderfile::
one shell glob pattern per line.
Can be overridden by the '-O' option to linkgit:git-diff[1].
+diff.relative::
+ Show pathnames relative to the current directory and exclude
+ changes outside this directory; equivalent to the 'git diff'
+ option '--relative'.
+ Overridden by the '--no-relative' linkgit:git-diff[1] option.
+
diff.renameLimit::
The number of files to consider when performing the copy/rename
detection; equivalent to the 'git diff' option '-l'.
diff --git a/diff.c b/diff.c
index 7bceba8..9e4ec1f 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 ccd67c7..c2c15e4 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -104,10 +104,30 @@ test_expect_success "--raw $*" "
"
}
+check_config() {
+store_diff_relative $1; shift
+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_config_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "--no-relative w/ git-config diff.relative=true in
$1" "
+ (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^
>../actual) &&
+ test_cmp expected actual
+"
+}
+
for type in diff numstat stat raw norel_pre norel_post; do
check_$type file2 --relative=subdir/
check_$type file2 --relative=subdir
check_$type dir/file2 --relative=sub
done
+for type in config config_no_relative; 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
* [PATCH 2/2] support for --no-relative and diff.relative
2014-12-30 19:32 ` [PATCH 2/2] support for --no-relative and diff.relative kelson
@ 2015-01-06 16:19 ` kelson
2015-02-12 23:17 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: kelson @ 2015-01-06 16:19 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Philip Oakley, Duy Nguyen, Jonathan Nieder
added diff.relative setting for git-diff (code, documentation, and tests)
`git-config diff.relative=true` causes `git diff` to behave like `git
diff --relative`. Overridden by `git diff --no-relative`.
Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
Documentation/diff-config.txt | 6 ++++++
diff.c | 8 ++++++++
t/t4045-diff-relative.sh | 20 ++++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index b001779..b8a7c60 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -103,6 +103,12 @@ diff.orderfile::
one shell glob pattern per line.
Can be overridden by the '-O' option to linkgit:git-diff[1].
+diff.relative::
+ Show pathnames relative to the current directory and exclude
+ changes outside this directory; equivalent to the 'git diff'
+ option '--relative'.
+ Overridden by the '--no-relative' linkgit:git-diff[1] option.
+
diff.renameLimit::
The number of files to consider when performing the copy/rename
detection; equivalent to the 'git diff' option '-l'.
diff --git a/diff.c b/diff.c
index 7bceba8..9e4ec1f 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 ccd67c7..c2c15e4 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -104,10 +104,30 @@ test_expect_success "--raw $*" "
"
}
+check_config() {
+store_diff_relative $1; shift
+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_config_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "--no-relative w/ git-config diff.relative=true in
$1" "
+ (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^
>../actual) &&
+ test_cmp expected actual
+"
+}
+
for type in diff numstat stat raw norel_pre norel_post; do
check_$type file2 --relative=subdir/
check_$type file2 --relative=subdir
check_$type dir/file2 --relative=sub
done
+for type in config config_no_relative; 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 2/2] support for --no-relative and diff.relative
2014-12-30 19:32 ` [PATCH 2/2] support for --no-relative and diff.relative kelson
2015-01-06 16:19 ` kelson
@ 2015-02-12 23:17 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2015-02-12 23:17 UTC (permalink / raw)
To: Git Mailing List; +Cc: kelson, Philip Oakley, Duy Nguyen, Jonathan Nieder
These two patches
* bp/diff-relative-config (2015-01-07) 2 commits
- diff: teach diff.relative to give default to --relative=<value>
- diff: teach --no-relative to override earlier --relative
have been sitting in my Undecided pile, primarily because I am wary
of touching a core command like "diff" with just me reviewing. I
think they look reasonably safe (especially since the configuration
parsing is done only in diff_ui_config()), but I may have overlooked
something obvious and silly.
Another set or two of eyeballs are very much appreciated.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-12 23:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-21 20:23 [PATCH v3 2/2] git-config support for diff.relative setting kelson
2014-12-30 17:56 ` kelson
2014-12-30 19:32 ` [PATCH 2/2] support for --no-relative and diff.relative kelson
2015-01-06 16:19 ` kelson
2015-02-12 23:17 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.