* buglet: 'git apply' doesn't handle criss-cross renames
@ 2009-04-09 18:59 Linus Torvalds
2009-04-11 15:26 ` [PATCH] tests: test applying criss-cross rename patch Michał Kiedrowicz
0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2009-04-09 18:59 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Al Viro
Ok, this doesn't come up in real life very much, but it's not impossible,
and I was generating this test-case to show Al how it's probably going to
be a real bitch to teach 'patch' how to handle git rename patches (or git
copy patches) in the general case.
Of course, the way git patches work is that the same source file may show
up several times (due to copies) or as both a source and a destination
(criss-cross renames or just rename + create new file), and we always look
at the _original_ state when we apply a patch fragment. Which makes it
hard for something like GNU "patch" that is purely linear.
And I was going to send Al an example of git doing that, and I was sure
that we had handled this at some point, but maybe I'm just wrong. I didn't
really go back and test it.
The point is, git itself fails here. Although not for any really
fundamental reason - but simply because we are a bit too tight on some
error handling, and do some checks wrong.
Git can _generate_ criss-cross merges correctly (although you have to use
the -B flag to make git try to break the names up):
mv kernel/sched.c a
mv kernel/exit.c kernel/sched.c
mv a kernel/exit.c
git diff -B -M > diff
and we get a nice correct diff:
diff --git a/kernel/sched.c b/kernel/exit.c
similarity index 100%
rename from kernel/sched.c
rename to kernel/exit.c
diff --git a/kernel/exit.c b/kernel/sched.c
similarity index 100%
rename from kernel/exit.c
rename to kernel/sched.c
but if you actually try to apply such a patch, we fail miserably (you need
to got a 'git reset --hard' or similar to get back the original tree to
apply the diff on, obviously):
[torvalds@nehalem linux]$ git apply diff
error: kernel/exit.c: already exists in working directory
error: kernel/sched.c: already exists in working directory
which is really sad.
I don't have a patch for it, and I don't think it's a huge deal in
practice, but I do think it's seriously wrong how we can generate a diff
that we then refuse to apply.
Linus
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] tests: test applying criss-cross rename patch
2009-04-09 18:59 buglet: 'git apply' doesn't handle criss-cross renames Linus Torvalds
@ 2009-04-11 15:26 ` Michał Kiedrowicz
2009-04-13 16:47 ` Junio C Hamano
2009-04-20 14:11 ` Alex Riesen
0 siblings, 2 replies; 7+ messages in thread
From: Michał Kiedrowicz @ 2009-04-11 15:26 UTC (permalink / raw)
To: Git Mailing List; +Cc: Michał Kiedrowicz
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
t/t4130-apply-criss-cross-rename.sh | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
create mode 100755 t/t4130-apply-criss-cross-rename.sh
diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh
new file mode 100755
index 0000000..30187ff
--- /dev/null
+++ b/t/t4130-apply-criss-cross-rename.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='git apply handling criss-cross rename patch.'
+. ./test-lib.sh
+
+create_file() {
+ for ((i=0; i<100; i++)); do
+ echo "$2" >> "$1"
+ done
+}
+
+test_expect_success 'setup' '
+ create_file file1 "File1 contents" &&
+ create_file file2 "File2 contents" &&
+ git add file1 file2 &&
+ git commit -m 1
+'
+
+test_expect_success 'criss-cross rename' '
+ mv file1 tmp &&
+ mv file2 file1 &&
+ mv tmp file2
+'
+
+test_expect_success 'diff -M -B' '
+ git diff -M -B > diff &&
+ git reset --hard
+
+'
+
+test_expect_failure 'apply' '
+ git apply diff
+'
+
+test_done
--
1.6.0.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] tests: test applying criss-cross rename patch
2009-04-11 15:26 ` [PATCH] tests: test applying criss-cross rename patch Michał Kiedrowicz
@ 2009-04-13 16:47 ` Junio C Hamano
2009-04-13 19:28 ` Junio C Hamano
2009-04-20 14:11 ` Alex Riesen
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2009-04-13 16:47 UTC (permalink / raw)
To: Michał Kiedrowicz; +Cc: Git Mailing List
Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:
> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
> ---
> t/t4130-apply-criss-cross-rename.sh | 35 +++++++++++++++++++++++++++++++++++
> 1 files changed, 35 insertions(+), 0 deletions(-)
> create mode 100755 t/t4130-apply-criss-cross-rename.sh
>
> diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh
> new file mode 100755
> index 0000000..30187ff
> --- /dev/null
> +++ b/t/t4130-apply-criss-cross-rename.sh
> @@ -0,0 +1,35 @@
> +#!/bin/sh
> +
> +test_description='git apply handling criss-cross rename patch.'
> +. ./test-lib.sh
> +
> +create_file() {
> + for ((i=0; i<100; i++)); do
Please don't; isn't this a bashism?
> + echo "$2" >> "$1"
> + done
> +}
> +
> +test_expect_success 'setup' '
> + create_file file1 "File1 contents" &&
> + create_file file2 "File2 contents" &&
> + git add file1 file2 &&
> + git commit -m 1
> +'
> +
> +test_expect_success 'criss-cross rename' '
> + mv file1 tmp &&
> + mv file2 file1 &&
> + mv tmp file2
> +'
> +
> +test_expect_success 'diff -M -B' '
> + git diff -M -B > diff &&
> + git reset --hard
> +
> +'
> +
> +test_expect_failure 'apply' '
> + git apply diff
> +'
> +
> +test_done
> --
> 1.6.0.6
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tests: test applying criss-cross rename patch
2009-04-13 16:47 ` Junio C Hamano
@ 2009-04-13 19:28 ` Junio C Hamano
0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2009-04-13 19:28 UTC (permalink / raw)
To: Michał Kiedrowicz; +Cc: Git Mailing List
Junio C Hamano <gitster@pobox.com> writes:
> Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:
>
>> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
>> ---
>> t/t4130-apply-criss-cross-rename.sh | 35 +++++++++++++++++++++++++++++++++++
>> 1 files changed, 35 insertions(+), 0 deletions(-)
>> create mode 100755 t/t4130-apply-criss-cross-rename.sh
>>
>> diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh
>> new file mode 100755
>> index 0000000..30187ff
>> --- /dev/null
>> +++ b/t/t4130-apply-criss-cross-rename.sh
>> @@ -0,0 +1,35 @@
>> +#!/bin/sh
>> +
>> +test_description='git apply handling criss-cross rename patch.'
>> +. ./test-lib.sh
>> +
>> +create_file() {
>> + for ((i=0; i<100; i++)); do
>
> Please don't; isn't this a bashism?
I've queued your two patches with minimum fix-up (not covering all the
points in my comments) to 'pu'. You may want to take a look and send in
improvement to replace them.
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tests: test applying criss-cross rename patch
2009-04-11 15:26 ` [PATCH] tests: test applying criss-cross rename patch Michał Kiedrowicz
2009-04-13 16:47 ` Junio C Hamano
@ 2009-04-20 14:11 ` Alex Riesen
2009-04-21 7:08 ` Junio C Hamano
1 sibling, 1 reply; 7+ messages in thread
From: Alex Riesen @ 2009-04-20 14:11 UTC (permalink / raw)
To: Michał Kiedrowicz; +Cc: Git Mailing List, Junio C Hamano
2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:
> +test_expect_success 'criss-cross rename' '
> + mv file1 tmp &&
> + mv file2 file1 &&
> + mv tmp file2
> +'
> +
> +test_expect_success 'diff -M -B' '
> + git diff -M -B > diff &&
> + git reset --hard
> +
> +'
This cannot work on systems where ctime is not trusted:
git diff will produce no data, as there are no changes in
metadata (the files are of the same size). Either make
the file sizes different or add a "touch file1 file2".
diff --git a/t/t4130-apply-criss-cross-rename.sh
b/t/t4130-apply-criss-cross-rename.sh
index 8623dbe..1ff049a 100755
--- a/t/t4130-apply-criss-cross-rename.sh
+++ b/t/t4130-apply-criss-cross-rename.sh
@@ -14,7 +14,7 @@ create_file() {
test_expect_success 'setup' '
create_file file1 "File1 contents" &&
- create_file file2 "File2 contents" &&
+ create_file file2 "Contents of File2" &&
git add file1 file2 &&
git commit -m 1
'
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] tests: test applying criss-cross rename patch
2009-04-20 14:11 ` Alex Riesen
@ 2009-04-21 7:08 ` Junio C Hamano
2009-04-21 12:41 ` Alex Riesen
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2009-04-21 7:08 UTC (permalink / raw)
To: Alex Riesen; +Cc: Michał Kiedrowicz, Git Mailing List
Alex Riesen <raa.lkml@gmail.com> writes:
> 2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:
>> +test_expect_success 'criss-cross rename' '
>> + mv file1 tmp &&
>> + mv file2 file1 &&
>> + mv tmp file2
>> +'
>> +
>> +test_expect_success 'diff -M -B' '
>> + git diff -M -B > diff &&
>> + git reset --hard
>> +
>> +'
>
> This cannot work on systems where ctime is not trusted:
> git diff will produce no data, as there are no changes in
> metadata (the files are of the same size). Either make
> the file sizes different or add a "touch file1 file2".
You seem to be saying that we still have a racy-git bug somewhere. Is
your statement from an actual experience or a speculation? If the former
we have a bug to kill, not a workaround to avoid the issue in this test.
>
> diff --git a/t/t4130-apply-criss-cross-rename.sh
> b/t/t4130-apply-criss-cross-rename.sh
> index 8623dbe..1ff049a 100755
> --- a/t/t4130-apply-criss-cross-rename.sh
> +++ b/t/t4130-apply-criss-cross-rename.sh
> @@ -14,7 +14,7 @@ create_file() {
>
> test_expect_success 'setup' '
> create_file file1 "File1 contents" &&
> - create_file file2 "File2 contents" &&
> + create_file file2 "Contents of File2" &&
> git add file1 file2 &&
> git commit -m 1
> '
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tests: test applying criss-cross rename patch
2009-04-21 7:08 ` Junio C Hamano
@ 2009-04-21 12:41 ` Alex Riesen
0 siblings, 0 replies; 7+ messages in thread
From: Alex Riesen @ 2009-04-21 12:41 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michał Kiedrowicz, Git Mailing List
2009/4/21 Junio C Hamano <gitster@pobox.com>:
> Alex Riesen <raa.lkml@gmail.com> writes:
>
>> 2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:
>>> +test_expect_success 'criss-cross rename' '
>>> + mv file1 tmp &&
>>> + mv file2 file1 &&
>>> + mv tmp file2
>>> +'
>>> +
>>> +test_expect_success 'diff -M -B' '
>>> + git diff -M -B > diff &&
>>> + git reset --hard
>>> +
>>> +'
>>
>> This cannot work on systems where ctime is not trusted:
>> git diff will produce no data, as there are no changes in
>> metadata (the files are of the same size). Either make
>> the file sizes different or add a "touch file1 file2".
>
> You seem to be saying that we still have a racy-git bug somewhere. Is
> your statement from an actual experience or a speculation?
The test reproducibly fails for me.
> If the former we have a bug to kill, not a workaround to avoid the
> issue in this test.
Maybe. As I see it, there is just not _enough_ metadata in this
particular case to notice the change without doing complete
content comparison: the size is the same, mtime is the same,
dev/ino aren't available, and ctime is marked untrusted and thus
is not used. What's left to notice the change?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-04-21 12:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-09 18:59 buglet: 'git apply' doesn't handle criss-cross renames Linus Torvalds
2009-04-11 15:26 ` [PATCH] tests: test applying criss-cross rename patch Michał Kiedrowicz
2009-04-13 16:47 ` Junio C Hamano
2009-04-13 19:28 ` Junio C Hamano
2009-04-20 14:11 ` Alex Riesen
2009-04-21 7:08 ` Junio C Hamano
2009-04-21 12:41 ` Alex Riesen
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).