{"thread":{"id":"18811","subject":"buglet: 'git apply' doesn't handle criss-cross renames","startedAt":"2009-04-09T18:59:38Z","lastAt":"2009-04-21T12:41:40Z","messageCount":7,"participants":["Linus Torvalds","Michał Kiedrowicz","Junio C Hamano","Alex Riesen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"110947","messageId":"alpine.LFD.2.00.0904091147290.4583@localhost.localdomain","threadId":"18811","inReplyTo":null,"subject":"buglet: 'git apply' doesn't handle criss-cross renames","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-04-09T18:59:38Z","receivedAt":"2009-04-09T18:59:38Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nOk, this doesn't come up in real life very much, but it's not impossible, \nand I was generating this test-case to show Al how it's probably going to \nbe a real bitch to teach 'patch' how to handle git rename patches (or git \ncopy patches) in the general case.\n\nOf course, the way git patches work is that the same source file may show \nup several times (due to copies) or as both a source and a destination \n(criss-cross renames or just rename + create new file), and we always look \nat the _original_ state when we apply a patch fragment. Which makes it \nhard for something like GNU \"patch\" that is purely linear.\n\nAnd I was going to send Al an example of git doing that, and I was sure \nthat we had handled this at some point, but maybe I'm just wrong. I didn't \nreally go back and test it.\n\nThe point is, git itself fails here. Although not for any really \nfundamental reason - but simply because we are a bit too tight on some \nerror handling, and do some checks wrong.\n\nGit can _generate_ criss-cross merges correctly (although you have to use \nthe -B flag to make git try to break the names up):\n\n\tmv kernel/sched.c a\n\tmv kernel/exit.c kernel/sched.c\n\tmv a kernel/exit.c\n\tgit diff -B -M > diff\n\nand we get a nice correct diff:\n\n\tdiff --git a/kernel/sched.c b/kernel/exit.c\n\tsimilarity index 100%\n\trename from kernel/sched.c\n\trename to kernel/exit.c\n\tdiff --git a/kernel/exit.c b/kernel/sched.c\n\tsimilarity index 100%\n\trename from kernel/exit.c\n\trename to kernel/sched.c\n\nbut if you actually try to apply such a patch, we fail miserably (you need \nto got a 'git reset --hard' or similar to get back the original tree to \napply the diff on, obviously):\n\n\t[torvalds@nehalem linux]$ git apply diff\n\terror: kernel/exit.c: already exists in working directory\n\terror: kernel/sched.c: already exists in working directory\n\nwhich is really sad.\n\nI don't have a patch for it, and I don't think it's a huge deal in \npractice, but I do think it's seriously wrong how we can generate a diff \nthat we then refuse to apply.\n\n\t\t\tLinus\n"},{"id":"111048","messageId":"1239463584-1427-1-git-send-email-michal.kiedrowicz@gmail.com","threadId":"18811","inReplyTo":"alpine.LFD.2.00.0904091147290.4583@localhost.localdomain","subject":"[PATCH] tests: test applying criss-cross rename patch","fromName":"Michał Kiedrowicz","fromEmail":"michal.kiedrowicz@gmail.com","sentAt":"2009-04-11T15:26:24Z","receivedAt":"2009-04-11T15:26:24Z","isPatch":true,"sender":{"key":"michal.kiedrowicz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14072847?v=4"},"body":"\nSigned-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n---\n t/t4130-apply-criss-cross-rename.sh |   35 +++++++++++++++++++++++++++++++++++\n 1 files changed, 35 insertions(+), 0 deletions(-)\n create mode 100755 t/t4130-apply-criss-cross-rename.sh\n\ndiff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh\nnew file mode 100755\nindex 0000000..30187ff\n--- /dev/null\n+++ b/t/t4130-apply-criss-cross-rename.sh\n@@ -0,0 +1,35 @@\n+#!/bin/sh\n+\n+test_description='git apply handling criss-cross rename patch.'\n+. ./test-lib.sh\n+\n+create_file() {\n+\tfor ((i=0; i<100; i++)); do\n+\t\techo \"$2\" >> \"$1\"\n+\tdone\n+}\n+\n+test_expect_success 'setup' '\n+\tcreate_file file1 \"File1 contents\" &&\n+\tcreate_file file2 \"File2 contents\" &&\n+\tgit add file1 file2 &&\n+\tgit commit -m 1\n+'\n+\n+test_expect_success 'criss-cross rename' '\n+\tmv file1 tmp &&\n+\tmv file2 file1 &&\n+\tmv tmp file2\n+'\n+\n+test_expect_success 'diff -M -B' '\n+\tgit diff -M -B > diff &&\n+\tgit reset --hard\n+\n+'\n+\n+test_expect_failure 'apply' '\n+\tgit apply diff\n+'\n+\n+test_done\n-- \n1.6.0.6\n"},{"id":"111199","messageId":"7vd4bgh560.fsf@gitster.siamese.dyndns.org","threadId":"18811","inReplyTo":"1239463584-1427-1-git-send-email-michal.kiedrowicz@gmail.com","subject":"Re: [PATCH] tests: test applying criss-cross rename patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-13T16:47:19Z","receivedAt":"2009-04-13T16:47:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:\n\n> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n> ---\n>  t/t4130-apply-criss-cross-rename.sh |   35 +++++++++++++++++++++++++++++++++++\n>  1 files changed, 35 insertions(+), 0 deletions(-)\n>  create mode 100755 t/t4130-apply-criss-cross-rename.sh\n>\n> diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh\n> new file mode 100755\n> index 0000000..30187ff\n> --- /dev/null\n> +++ b/t/t4130-apply-criss-cross-rename.sh\n> @@ -0,0 +1,35 @@\n> +#!/bin/sh\n> +\n> +test_description='git apply handling criss-cross rename patch.'\n> +. ./test-lib.sh\n> +\n> +create_file() {\n> +\tfor ((i=0; i<100; i++)); do\n\nPlease don't; isn't this a bashism?\n\n> +\t\techo \"$2\" >> \"$1\"\n> +\tdone\n> +}\n> +\n> +test_expect_success 'setup' '\n> +\tcreate_file file1 \"File1 contents\" &&\n> +\tcreate_file file2 \"File2 contents\" &&\n> +\tgit add file1 file2 &&\n> +\tgit commit -m 1\n> +'\n> +\n> +test_expect_success 'criss-cross rename' '\n> +\tmv file1 tmp &&\n> +\tmv file2 file1 &&\n> +\tmv tmp file2\n> +'\n> +\n> +test_expect_success 'diff -M -B' '\n> +\tgit diff -M -B > diff &&\n> +\tgit reset --hard\n> +\n> +'\n> +\n> +test_expect_failure 'apply' '\n> +\tgit apply diff\n> +'\n> +\n> +test_done\n> -- \n> 1.6.0.6\n"},{"id":"111227","messageId":"7vvdp8e4k2.fsf@gitster.siamese.dyndns.org","threadId":"18811","inReplyTo":"7vd4bgh560.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] tests: test applying criss-cross rename patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-13T19:28:45Z","receivedAt":"2009-04-13T19:28:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:\n>\n>> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n>> ---\n>>  t/t4130-apply-criss-cross-rename.sh |   35 +++++++++++++++++++++++++++++++++++\n>>  1 files changed, 35 insertions(+), 0 deletions(-)\n>>  create mode 100755 t/t4130-apply-criss-cross-rename.sh\n>>\n>> diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh\n>> new file mode 100755\n>> index 0000000..30187ff\n>> --- /dev/null\n>> +++ b/t/t4130-apply-criss-cross-rename.sh\n>> @@ -0,0 +1,35 @@\n>> +#!/bin/sh\n>> +\n>> +test_description='git apply handling criss-cross rename patch.'\n>> +. ./test-lib.sh\n>> +\n>> +create_file() {\n>> +\tfor ((i=0; i<100; i++)); do\n>\n> Please don't; isn't this a bashism?\n\nI've queued your two patches with minimum fix-up (not covering all the\npoints in my comments) to 'pu'.  You may want to take a look and send in\nimprovement to replace them.\n\nThanks.\n"},{"id":"111736","messageId":"81b0412b0904200711p66ea2500s7cc5894aba71f641@mail.gmail.com","threadId":"18811","inReplyTo":"1239463584-1427-1-git-send-email-michal.kiedrowicz@gmail.com","subject":"Re: [PATCH] tests: test applying criss-cross rename patch","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2009-04-20T14:11:01Z","receivedAt":"2009-04-20T14:11:01Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:\n> +test_expect_success 'criss-cross rename' '\n> +       mv file1 tmp &&\n> +       mv file2 file1 &&\n> +       mv tmp file2\n> +'\n> +\n> +test_expect_success 'diff -M -B' '\n> +       git diff -M -B > diff &&\n> +       git reset --hard\n> +\n> +'\n\nThis cannot work on systems where ctime is not trusted:\ngit diff will produce no data, as there are no changes in\nmetadata (the files are of the same size). Either make\nthe file sizes different or add a \"touch file1 file2\".\n\ndiff --git a/t/t4130-apply-criss-cross-rename.sh\nb/t/t4130-apply-criss-cross-rename.sh\nindex 8623dbe..1ff049a 100755\n--- a/t/t4130-apply-criss-cross-rename.sh\n+++ b/t/t4130-apply-criss-cross-rename.sh\n@@ -14,7 +14,7 @@ create_file() {\n\n test_expect_success 'setup' '\n \tcreate_file file1 \"File1 contents\" &&\n-\tcreate_file file2 \"File2 contents\" &&\n+\tcreate_file file2 \"Contents of File2\" &&\n \tgit add file1 file2 &&\n \tgit commit -m 1\n '\n"},{"id":"111846","messageId":"7viqkya3hq.fsf@gitster.siamese.dyndns.org","threadId":"18811","inReplyTo":"81b0412b0904200711p66ea2500s7cc5894aba71f641@mail.gmail.com","subject":"Re: [PATCH] tests: test applying criss-cross rename patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-21T07:08:01Z","receivedAt":"2009-04-21T07:08:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> 2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:\n>> +test_expect_success 'criss-cross rename' '\n>> +       mv file1 tmp &&\n>> +       mv file2 file1 &&\n>> +       mv tmp file2\n>> +'\n>> +\n>> +test_expect_success 'diff -M -B' '\n>> +       git diff -M -B > diff &&\n>> +       git reset --hard\n>> +\n>> +'\n>\n> This cannot work on systems where ctime is not trusted:\n> git diff will produce no data, as there are no changes in\n> metadata (the files are of the same size). Either make\n> the file sizes different or add a \"touch file1 file2\".\n\nYou seem to be saying that we still have a racy-git bug somewhere.  Is\nyour statement from an actual experience or a speculation?  If the former\nwe have a bug to kill, not a workaround to avoid the issue in this test.\n\n>\n> diff --git a/t/t4130-apply-criss-cross-rename.sh\n> b/t/t4130-apply-criss-cross-rename.sh\n> index 8623dbe..1ff049a 100755\n> --- a/t/t4130-apply-criss-cross-rename.sh\n> +++ b/t/t4130-apply-criss-cross-rename.sh\n> @@ -14,7 +14,7 @@ create_file() {\n>\n>  test_expect_success 'setup' '\n>  \tcreate_file file1 \"File1 contents\" &&\n> -\tcreate_file file2 \"File2 contents\" &&\n> +\tcreate_file file2 \"Contents of File2\" &&\n>  \tgit add file1 file2 &&\n>  \tgit commit -m 1\n>  '\n"},{"id":"111875","messageId":"81b0412b0904210541o17baa103h62fc0825727fe83b@mail.gmail.com","threadId":"18811","inReplyTo":"7viqkya3hq.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] tests: test applying criss-cross rename patch","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2009-04-21T12:41:40Z","receivedAt":"2009-04-21T12:41:40Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"2009/4/21 Junio C Hamano <gitster@pobox.com>:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n>\n>> 2009/4/11 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:\n>>> +test_expect_success 'criss-cross rename' '\n>>> +       mv file1 tmp &&\n>>> +       mv file2 file1 &&\n>>> +       mv tmp file2\n>>> +'\n>>> +\n>>> +test_expect_success 'diff -M -B' '\n>>> +       git diff -M -B > diff &&\n>>> +       git reset --hard\n>>> +\n>>> +'\n>>\n>> This cannot work on systems where ctime is not trusted:\n>> git diff will produce no data, as there are no changes in\n>> metadata (the files are of the same size). Either make\n>> the file sizes different or add a \"touch file1 file2\".\n>\n> You seem to be saying that we still have a racy-git bug somewhere.  Is\n> your statement from an actual experience or a speculation?\n\nThe test reproducibly fails for me.\n\n> If the former we have a bug to kill, not a workaround to avoid the\n> issue in this test.\n\nMaybe. As I see it, there is just not _enough_ metadata in this\nparticular case to notice the change without doing complete\ncontent comparison: the size is the same, mtime is the same,\ndev/ino aren't available, and ctime is marked untrusted and thus\nis not used. What's left to notice the change?\n"}]}