* [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd()
@ 2024-09-08 7:05 René Scharfe
2024-09-08 7:08 ` [PATCH 2/2] diff: report dirty submodules as changes in builtin_diff() René Scharfe
2024-09-09 15:16 ` [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() Phillip Wood
0 siblings, 2 replies; 4+ messages in thread
From: René Scharfe @ 2024-09-08 7:05 UTC (permalink / raw)
To: Git List; +Cc: Jorge Luis Martinez Gomez, David Hull
The diff machinery has two ways to detect changes to set the exit code:
Just comparing hashes and comparing blob contents. The latter is needed
if certain changes have to be ignored, e.g. with --ignore-space-change
or --ignore-matching-lines. It's enabled by the diff_options flag
diff_from_contents.
The slower mode has never considered copies and renames to be changes,
which is inconsistent with the quicker one. Fix it. Even if we ignore
the file contents (because it's empty or contains only ignored lines),
there's still the meta data change of adding or changing a filename, so
we need to report it in the exit code.
d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09) set diff_from_contents if external diff
programs are allowed. This is the default e.g. for git diff, and so
that change exposed the inconsistency much more widely.
Reported-by: Jorge Luis Martinez Gomez <jol@jol.dev>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
diff.c | 3 +++
t/t4017-diff-retval.sh | 16 ++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/diff.c b/diff.c
index 4035a9374d..1d2057d4cb 100644
--- a/diff.c
+++ b/diff.c
@@ -4587,6 +4587,9 @@ static void run_diff_cmd(const struct external_diff *pgm,
builtin_diff(name, other ? other : name,
one, two, xfrm_msg, must_show_header,
o, complete_rewrite);
+ if (p->status == DIFF_STATUS_COPIED ||
+ p->status == DIFF_STATUS_RENAMED)
+ o->found_changes = 1;
} else {
fprintf(o->file, "* Unmerged path %s\n", name);
o->found_changes = 1;
diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh
index f439f469bd..9a4f578614 100755
--- a/t/t4017-diff-retval.sh
+++ b/t/t4017-diff-retval.sh
@@ -143,4 +143,20 @@ test_expect_success 'option errors are not confused by --exit-code' '
grep '^usage:' err
'
+for option in --exit-code --quiet
+do
+ test_expect_success "git diff $option returns 1 for copied file" "
+ git reset --hard &&
+ cp a copy &&
+ git add copy &&
+ test_expect_code 1 git diff $option --cached --find-copies-harder
+ "
+
+ test_expect_success "git diff $option returns 1 for renamed file" "
+ git reset --hard &&
+ git mv a renamed &&
+ test_expect_code 1 git diff $option --cached
+ "
+done
+
test_done
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] diff: report dirty submodules as changes in builtin_diff()
2024-09-08 7:05 [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() René Scharfe
@ 2024-09-08 7:08 ` René Scharfe
2024-09-09 15:16 ` [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() Phillip Wood
1 sibling, 0 replies; 4+ messages in thread
From: René Scharfe @ 2024-09-08 7:08 UTC (permalink / raw)
To: Git List; +Cc: Jorge Luis Martinez Gomez, David Hull
The diff machinery has two ways to detect changes to set the exit code:
Just comparing hashes and comparing blob contents. The latter is needed
if certain changes have to be ignored, e.g. with --ignore-space-change
or --ignore-matching-lines. It's enabled by the diff_options flag
diff_from_contents.
The slower mode as never considered submodules (and subrepos) as changes
with --submodule=diff or --submodule=log, which is inconsistent with
--submodule=short (the default). Fix it.
d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09) set diff_from_contents if external diff
programs are allowed. This is the default e.g. for git diff, and so
that change exposed the inconsistency much more widely.
Reported-by: David Hull <david.hull@friendbuy.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
diff.c | 2 ++
t/t4017-diff-retval.sh | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/diff.c b/diff.c
index 1d2057d4cb..472479eb10 100644
--- a/diff.c
+++ b/diff.c
@@ -3565,6 +3565,7 @@ static void builtin_diff(const char *name_a,
show_submodule_diff_summary(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
+ o->found_changes = 1;
return;
} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
(!one->mode || S_ISGITLINK(one->mode)) &&
@@ -3573,6 +3574,7 @@ static void builtin_diff(const char *name_a,
show_submodule_inline_diff(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
+ o->found_changes = 1;
return;
}
diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh
index 9a4f578614..d644310e22 100755
--- a/t/t4017-diff-retval.sh
+++ b/t/t4017-diff-retval.sh
@@ -159,4 +159,25 @@ do
"
done
+test_expect_success 'setup dirty subrepo' '
+ git reset --hard &&
+ test_create_repo subrepo &&
+ test_commit -C subrepo subrepo-file &&
+ test_tick &&
+ git add subrepo &&
+ git commit -m subrepo &&
+ test_commit -C subrepo another-subrepo-file
+'
+
+for option in --exit-code --quiet
+do
+ for submodule_format in diff log short
+ do
+ opts="$option --submodule=$submodule_format" &&
+ test_expect_success "git diff $opts returns 1 for dirty subrepo" "
+ test_expect_code 1 git diff $opts
+ "
+ done
+done
+
test_done
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd()
2024-09-08 7:05 [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() René Scharfe
2024-09-08 7:08 ` [PATCH 2/2] diff: report dirty submodules as changes in builtin_diff() René Scharfe
@ 2024-09-09 15:16 ` Phillip Wood
2024-09-09 16:59 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Phillip Wood @ 2024-09-09 15:16 UTC (permalink / raw)
To: René Scharfe, Git List; +Cc: Jorge Luis Martinez Gomez, David Hull
Hi René
On 08/09/2024 08:05, René Scharfe wrote:
> The diff machinery has two ways to detect changes to set the exit code:
> Just comparing hashes and comparing blob contents. The latter is needed
> if certain changes have to be ignored, e.g. with --ignore-space-change
> or --ignore-matching-lines. It's enabled by the diff_options flag
> diff_from_contents.
>
> The slower mode has never considered copies and renames to be changes,
> which is inconsistent with the quicker one. Fix it. Even if we ignore
> the file contents (because it's empty or contains only ignored lines),
> there's still the meta data change of adding or changing a filename, so
> we need to report it in the exit code.
>
> d7b97b7185 (diff: let external diffs report that changes are
> uninteresting, 2024-06-09) set diff_from_contents if external diff
> programs are allowed. This is the default e.g. for git diff, and so
> that change exposed the inconsistency much more widely.
Thanks for fixing this - both patches looks good to me.
Best Wishes
Phillip
> Reported-by: Jorge Luis Martinez Gomez <jol@jol.dev>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> diff.c | 3 +++
> t/t4017-diff-retval.sh | 16 ++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/diff.c b/diff.c
> index 4035a9374d..1d2057d4cb 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4587,6 +4587,9 @@ static void run_diff_cmd(const struct external_diff *pgm,
> builtin_diff(name, other ? other : name,
> one, two, xfrm_msg, must_show_header,
> o, complete_rewrite);
> + if (p->status == DIFF_STATUS_COPIED ||
> + p->status == DIFF_STATUS_RENAMED)
> + o->found_changes = 1;
> } else {
> fprintf(o->file, "* Unmerged path %s\n", name);
> o->found_changes = 1;
> diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh
> index f439f469bd..9a4f578614 100755
> --- a/t/t4017-diff-retval.sh
> +++ b/t/t4017-diff-retval.sh
> @@ -143,4 +143,20 @@ test_expect_success 'option errors are not confused by --exit-code' '
> grep '^usage:' err
> '
>
> +for option in --exit-code --quiet
> +do
> + test_expect_success "git diff $option returns 1 for copied file" "
> + git reset --hard &&
> + cp a copy &&
> + git add copy &&
> + test_expect_code 1 git diff $option --cached --find-copies-harder
> + "
> +
> + test_expect_success "git diff $option returns 1 for renamed file" "
> + git reset --hard &&
> + git mv a renamed &&
> + test_expect_code 1 git diff $option --cached
> + "
> +done
> +
> test_done
> --
> 2.46.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd()
2024-09-09 15:16 ` [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() Phillip Wood
@ 2024-09-09 16:59 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-09-09 16:59 UTC (permalink / raw)
To: Phillip Wood
Cc: René Scharfe, Git List, Jorge Luis Martinez Gomez,
David Hull
Phillip Wood <phillip.wood123@gmail.com> writes:
>> which is inconsistent with the quicker one. Fix it. Even if we ignore
>> the file contents (because it's empty or contains only ignored lines),
>> there's still the meta data change of adding or changing a filename, so
>> we need to report it in the exit code.
>> d7b97b7185 (diff: let external diffs report that changes are
>> uninteresting, 2024-06-09) set diff_from_contents if external diff
>> programs are allowed. This is the default e.g. for git diff, and so
>> that change exposed the inconsistency much more widely.
>
> Thanks for fixing this - both patches looks good to me.
Yup, thanks, both.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-09 16:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-08 7:05 [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() René Scharfe
2024-09-08 7:08 ` [PATCH 2/2] diff: report dirty submodules as changes in builtin_diff() René Scharfe
2024-09-09 15:16 ` [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() Phillip Wood
2024-09-09 16:59 ` 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).