You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by David Ellingsworth <da...@identd.dyndns.org> on 2009/01/07 00:57:19 UTC

svn diff produces a patch which does not reapply cleanly

While using TortoiseSVN 1.5.6 build 14908, I encountered an error
while trying to apply a patch with TortoiseMerge that was previously
created using TortoiseSVN's "Create Patch" feature. While I was unable
to apply the patch with TortoiseMerge, I did succeed while using the
standard patch command, but not without any fuzz.

The reply to the issue I posted on TortioseSVN"s user mailing list
indicates this is an error in svn's core since the patch generated is
equivalent to "svn diff file > patchfile". I have verified this using
svn client 1.5.1 and 1.5.5.

Attached are some files I created which are capable of reliably
reproducing the problem. The files are as follows: the original
file(test.txt), the updated file(test_v2.txt), and the associated
patch file generated from svn diff(test.patch).

For reference purposes, the original report posted to TortioseSVN's
user mailing list can be found here:
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=1007806

Regards,

David Ellingsworth

Re: svn diff produces a patch which does not reapply cleanly

Posted by Justin Erenkrantz <je...@apache.org>.
On Wed, Jan 7, 2009 at 12:41 PM, Stefan Küng <to...@gmail.com> wrote:
> Problem still is: the original 'patch' tool can't apply that patch
> cleanly without doing 'fuzzy' work. Which means the patch is not correct?

No, not necessarily.  -- justin


Re: svn diff produces a patch which does not reapply cleanly

Posted by Mark Phippard <mp...@collab.net>.
On Wed, Jan 7, 2009 at 4:18 PM, Stefan Küng <to...@gmail.com> wrote:
> On Wed, Jan 7, 2009 at 21:41, Stefan Küng <to...@gmail.com> wrote:
>> If there was a documentation on how a patch has to be created and how
>> those chunk infos are supposed to work, it would be easier...
>
> Found this:
> http://en.wikipedia.org/wiki/Diff
>
> but the chunk info is not very clearly documented there either. I'll
> do some more checks...

You may have already seen this, but here is another attempt to explain it:

http://www.artima.com/forums/flat.jsp?forum=106&thread=164293

-- 
Thanks

Mark Phippard
http://markphip.blogspot.com/


Re: svn diff produces a patch which does not reapply cleanly

Posted by Stefan Küng <to...@gmail.com>.
On Wed, Jan 7, 2009 at 22:18, Stefan Küng <to...@gmail.com> wrote:
> On Wed, Jan 7, 2009 at 21:41, Stefan Küng <to...@gmail.com> wrote:
>> If there was a documentation on how a patch has to be created and how
>> those chunk infos are supposed to work, it would be easier...
>
> Found this:
> http://en.wikipedia.org/wiki/Diff
>
> but the chunk info is not very clearly documented there either. I'll
> do some more checks...

Got a copy of the gnu diff for Windows, and the output of

diff --unified=1 test.txt test_v2.txt > out

looks different than what Subversion produces. The second chunk starts with
@@ -4,9 +7,9 @@
instead of
@@ -2,9 +5,9 @@

which is also what TortoiseMerge expects.

The full output of gnu diff for those two files:

--- ..\test.txt	2009-01-07 21:54:33.135280400 +0100
+++ ..\test_v2.txt	2009-01-06 21:33:35.120879900 +0100
@@ -1 +1,4 @@
+line_1a
+line_1b
+line_1c
 line_1
@@ -4,9 +7,9 @@
 line_4
-line_5
-line_6
-line_7
+line_5a
+line_6a
+line_7a
 line_8
-line_9
-line_10
-line_11
+line_9a
+line_10a
+line_11a
 line_12
\ No newline at end of file


Stefan

-- 
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net

Re: svn diff produces a patch which does not reapply cleanly

Posted by Stefan Küng <to...@gmail.com>.
On Wed, Jan 7, 2009 at 21:41, Stefan Küng <to...@gmail.com> wrote:
> If there was a documentation on how a patch has to be created and how
> those chunk infos are supposed to work, it would be easier...

Found this:
http://en.wikipedia.org/wiki/Diff

but the chunk info is not very clearly documented there either. I'll
do some more checks...

Stefan

-- 
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net

Re: svn diff produces a patch which does not reapply cleanly

Posted by David Ellingsworth <da...@identd.dyndns.org>.
On Fri, Jan 23, 2009 at 11:42 AM, David Ellingsworth
<da...@identd.dyndns.org> wrote:
> On Wed, Jan 7, 2009 at 5:01 PM, Konstantin Kolinko
> <kn...@gmail.com> wrote:
>> 2009/1/7 Stefan Küng <to...@gmail.com>:
>>> David Glasser wrote:
>>>> On Wed, Jan 7, 2009 at 10:07 AM, Stefan Kueng <to...@gmail.com> wrote:
>>>>> David Ellingsworth wrote:
>>>>>> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>>>>>>> Daniel Shahaf wrote:
>>>>>>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>>>>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>>>>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>>>>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>>>>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>>>>>>> standard patch command, but not without any fuzz.
>>>>>>>>>
>>>>>>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>>>>>>> indicates this is an error in svn's core since the patch generated is
>>>>>>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>>>>>>> svn client 1.5.1 and 1.5.5.
>>>>>>>>>
>>>>>>>>> Attached are some files I created which are capable of reliably
>>>>>>>>> reproducing the problem. The files are as follows: the original
>>>>>>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>>>>>>> patch file generated from svn diff(test.patch).
>>>>>>>>>
>>>>>>>> What *exactly* should we do with these three files to reproduce the error?
>>>>>>>> (If you can package the answer in script (or transcript) form, that's
>>>>>>>> best.)  I tried
>>>>>>>>
>>>>>>>>       svn add wc1\trunk\test.txt
>>>>>>>>       svn commit wc1 -m "add"
>>>>>>>>       rm -f wc1\trunk\test.txt
>>>>>>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>>>>>>       svn diff wc1 > out
>>>>>>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>>>>>>       svn revert wc1\trunk\test.txt
>>>>>>>>       patch -d wc1\trunk < out
>>>>>>>>       diff -u wc1\trunk\test*.txt
>>>>>>>>
>>>>>>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>>>>>>> found no differences (the expected result).  Results are the same with
>>>>>>>> both 1.5 and trunk.
>>>>>>> Try
>>>>>>>
>>>>>>>  svn add wc1\trunk\test.txt
>>>>>>>  svn commit wc1 -m "add"
>>>>>>>  cp test_v2.txt wc1\trunk\test.txt
>>>>>>>  svn diff wc1 > out
>>>>>>>  svn revert wc1\trunk\test.txt
>>>>>>>  patch -d wc1\trunk < out
>>>>>>>
>>>>>>> Stefan
>>>>>>>
>>>>>> Output is as follows, I don't have a trunk directory so it's been excluded:
>>>>>>
>>>>>> $ svn add wc1\test.txt
>>>>>> A        wc1\test.txt
>>>>>>
>>>>>> $ svn commit wc1 -m "add"
>>>>>> Adding        wc1\test.txt
>>>>>> Transmitting file data .
>>>>>> Committed revision 1.
>>>>>>
>>>>>> $ cp test_v2.txt wc1\test.txt
>>>>>>
>>>>>> $ svn diff wc1 > out
>>>>>>
>>>>>> $ svn revert wc1\test.txt
>>>>>> Reverted 'wc1\test.txt'
>>>>>>
>>>>>> $ patch -d wc1 < out
>>>>>> patching file 'test.txt'
>>>>>> Hunk #2 succeeded at 7 (offset 2 lines)
>>>>> sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
>>>>> The patch should be applied cleanly, without any offset.
>>>>>
>>>>> I haven't found any clear docs on how a patch file really is defined,
>>>>> but from what I think is wrong:
>>>>>
>>>>> The chunk info line
>>>>> @@ -2,9 +5,9 @@
>>>>> is wrong. AFAIK the first number (-2) is the line number where removing
>>>>> starts, the second one the number of lines to remove (including context
>>>>> lines), the third one (5) the line number where adding starts and the
>>>>> fourth (9) the number of lines to add (also including context lines).
>>>>>
>>>>> Now, in 1.4.x, the diff would have the start line numbers adjusted. The
>>>>> first chunk is always correct, but now (>= 1.5.x) the line numbers are
>>>>> always in reference to the original file. Before those lines were
>>>>> adjusted: if a chunk before added lines or removed lines, the 'start'
>>>>> lines of the following chunks would take that into account.
>>>>>
>>>>> Does anyone know if (and where) the patch file format is documented?
>>>>> Because I may be completely wrong here - I've implemented the patch
>>>>> functionality in TortoiseMerge completely by reverse engineering the
>>>>> format...
>>>>
>>>> I get the same patch with 1.4.x and ~trunk (with that line), FWIW.
>>>> You get something different with 1.4.x?
>>>
>>> hmm - no. I also get the same patch with 1.4.x and even 1.3.x.
>>>
>>> Problem still is: the original 'patch' tool can't apply that patch
>>> cleanly without doing 'fuzzy' work. Which means the patch is not correct?
>>>
>>> If there was a documentation on how a patch has to be created and how
>>> those chunk infos are supposed to work, it would be easier...
>>>
>>>
>>> Stefan
>>>
>>
>> Here is the specification:
>> It is POSIX.1-2008 (The Open Group Base Specifications Issue 7)
>>
>> http://www.opengroup.org/onlinepubs/9699919799/utilities/diff.html
>> http://www.opengroup.org/onlinepubs/9699919799/utilities/patch.html
>>
>> Note: The entrance is here:
>> http://www.opengroup.org/bookstore/catalog/c082.htm
>> They ask for your name and assign you a cookie.
>>
>> The previous Issue 6 is freely accessible here, though it does not yet
>> specify the -u format:
>> http://www.opengroup.org/onlinepubs/009695399/utilities/diff.html
>>
>> Best regards,
>> Konstantin Kolinko
>>
>
> I haven't heard much about this issue since I submitted it. Is a fix
> planned for this or is there a work around I can use in the mean time?
>

Building a bit on the previous issue, I've updated the test files to
show the full extent of the problem. Attached are the updated files.
test.txt is the original file committed to the archive, test_v2.txt is
the modified version of test.txt, and test.patch is the resulting
output from svn diff. If test.txt is reverted to the original version
and the patch applied with patch -p0 < test.patch, patch produces the
following output:

$ patch -p0 < test.patch
patching file 'test.txt'
Hunk #2 succeeded at 7 (offset 2 lines).
Hunk #3 succeeded at 11 (offset -2 lines).
Hunk #4 succeeded at 25 (offset 2 lines).
Hunk #5 succeeded at 31 (offset -2 lines).

As you can see, the patch does not apply cleanly. The correct offset
should be 0 lines for a perfect patch file. As you can see.. not only
is the offset of the second hunk wrong, but all following hunks are
wrong as well.

Regards,

David Ellingsworth

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1050424

Re: svn diff produces a patch which does not reapply cleanly

Posted by David Ellingsworth <da...@identd.dyndns.org>.
On Wed, Jan 7, 2009 at 5:01 PM, Konstantin Kolinko
<kn...@gmail.com> wrote:
> 2009/1/7 Stefan Küng <to...@gmail.com>:
>> David Glasser wrote:
>>> On Wed, Jan 7, 2009 at 10:07 AM, Stefan Kueng <to...@gmail.com> wrote:
>>>> David Ellingsworth wrote:
>>>>> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>>>>>> Daniel Shahaf wrote:
>>>>>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>>>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>>>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>>>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>>>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>>>>>> standard patch command, but not without any fuzz.
>>>>>>>>
>>>>>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>>>>>> indicates this is an error in svn's core since the patch generated is
>>>>>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>>>>>> svn client 1.5.1 and 1.5.5.
>>>>>>>>
>>>>>>>> Attached are some files I created which are capable of reliably
>>>>>>>> reproducing the problem. The files are as follows: the original
>>>>>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>>>>>> patch file generated from svn diff(test.patch).
>>>>>>>>
>>>>>>> What *exactly* should we do with these three files to reproduce the error?
>>>>>>> (If you can package the answer in script (or transcript) form, that's
>>>>>>> best.)  I tried
>>>>>>>
>>>>>>>       svn add wc1\trunk\test.txt
>>>>>>>       svn commit wc1 -m "add"
>>>>>>>       rm -f wc1\trunk\test.txt
>>>>>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>>>>>       svn diff wc1 > out
>>>>>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>>>>>       svn revert wc1\trunk\test.txt
>>>>>>>       patch -d wc1\trunk < out
>>>>>>>       diff -u wc1\trunk\test*.txt
>>>>>>>
>>>>>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>>>>>> found no differences (the expected result).  Results are the same with
>>>>>>> both 1.5 and trunk.
>>>>>> Try
>>>>>>
>>>>>>  svn add wc1\trunk\test.txt
>>>>>>  svn commit wc1 -m "add"
>>>>>>  cp test_v2.txt wc1\trunk\test.txt
>>>>>>  svn diff wc1 > out
>>>>>>  svn revert wc1\trunk\test.txt
>>>>>>  patch -d wc1\trunk < out
>>>>>>
>>>>>> Stefan
>>>>>>
>>>>> Output is as follows, I don't have a trunk directory so it's been excluded:
>>>>>
>>>>> $ svn add wc1\test.txt
>>>>> A        wc1\test.txt
>>>>>
>>>>> $ svn commit wc1 -m "add"
>>>>> Adding        wc1\test.txt
>>>>> Transmitting file data .
>>>>> Committed revision 1.
>>>>>
>>>>> $ cp test_v2.txt wc1\test.txt
>>>>>
>>>>> $ svn diff wc1 > out
>>>>>
>>>>> $ svn revert wc1\test.txt
>>>>> Reverted 'wc1\test.txt'
>>>>>
>>>>> $ patch -d wc1 < out
>>>>> patching file 'test.txt'
>>>>> Hunk #2 succeeded at 7 (offset 2 lines)
>>>> sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
>>>> The patch should be applied cleanly, without any offset.
>>>>
>>>> I haven't found any clear docs on how a patch file really is defined,
>>>> but from what I think is wrong:
>>>>
>>>> The chunk info line
>>>> @@ -2,9 +5,9 @@
>>>> is wrong. AFAIK the first number (-2) is the line number where removing
>>>> starts, the second one the number of lines to remove (including context
>>>> lines), the third one (5) the line number where adding starts and the
>>>> fourth (9) the number of lines to add (also including context lines).
>>>>
>>>> Now, in 1.4.x, the diff would have the start line numbers adjusted. The
>>>> first chunk is always correct, but now (>= 1.5.x) the line numbers are
>>>> always in reference to the original file. Before those lines were
>>>> adjusted: if a chunk before added lines or removed lines, the 'start'
>>>> lines of the following chunks would take that into account.
>>>>
>>>> Does anyone know if (and where) the patch file format is documented?
>>>> Because I may be completely wrong here - I've implemented the patch
>>>> functionality in TortoiseMerge completely by reverse engineering the
>>>> format...
>>>
>>> I get the same patch with 1.4.x and ~trunk (with that line), FWIW.
>>> You get something different with 1.4.x?
>>
>> hmm - no. I also get the same patch with 1.4.x and even 1.3.x.
>>
>> Problem still is: the original 'patch' tool can't apply that patch
>> cleanly without doing 'fuzzy' work. Which means the patch is not correct?
>>
>> If there was a documentation on how a patch has to be created and how
>> those chunk infos are supposed to work, it would be easier...
>>
>>
>> Stefan
>>
>
> Here is the specification:
> It is POSIX.1-2008 (The Open Group Base Specifications Issue 7)
>
> http://www.opengroup.org/onlinepubs/9699919799/utilities/diff.html
> http://www.opengroup.org/onlinepubs/9699919799/utilities/patch.html
>
> Note: The entrance is here:
> http://www.opengroup.org/bookstore/catalog/c082.htm
> They ask for your name and assign you a cookie.
>
> The previous Issue 6 is freely accessible here, though it does not yet
> specify the -u format:
> http://www.opengroup.org/onlinepubs/009695399/utilities/diff.html
>
> Best regards,
> Konstantin Kolinko
>

I haven't heard much about this issue since I submitted it. Is a fix
planned for this or is there a work around I can use in the mean time?

Regards,

David Ellingsworth

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1045067


Re: svn diff produces a patch which does not reapply cleanly

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/1/7 Stefan Küng <to...@gmail.com>:
> David Glasser wrote:
>> On Wed, Jan 7, 2009 at 10:07 AM, Stefan Kueng <to...@gmail.com> wrote:
>>> David Ellingsworth wrote:
>>>> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>>>>> Daniel Shahaf wrote:
>>>>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>>>>> standard patch command, but not without any fuzz.
>>>>>>>
>>>>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>>>>> indicates this is an error in svn's core since the patch generated is
>>>>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>>>>> svn client 1.5.1 and 1.5.5.
>>>>>>>
>>>>>>> Attached are some files I created which are capable of reliably
>>>>>>> reproducing the problem. The files are as follows: the original
>>>>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>>>>> patch file generated from svn diff(test.patch).
>>>>>>>
>>>>>> What *exactly* should we do with these three files to reproduce the error?
>>>>>> (If you can package the answer in script (or transcript) form, that's
>>>>>> best.)  I tried
>>>>>>
>>>>>>       svn add wc1\trunk\test.txt
>>>>>>       svn commit wc1 -m "add"
>>>>>>       rm -f wc1\trunk\test.txt
>>>>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>>>>       svn diff wc1 > out
>>>>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>>>>       svn revert wc1\trunk\test.txt
>>>>>>       patch -d wc1\trunk < out
>>>>>>       diff -u wc1\trunk\test*.txt
>>>>>>
>>>>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>>>>> found no differences (the expected result).  Results are the same with
>>>>>> both 1.5 and trunk.
>>>>> Try
>>>>>
>>>>>  svn add wc1\trunk\test.txt
>>>>>  svn commit wc1 -m "add"
>>>>>  cp test_v2.txt wc1\trunk\test.txt
>>>>>  svn diff wc1 > out
>>>>>  svn revert wc1\trunk\test.txt
>>>>>  patch -d wc1\trunk < out
>>>>>
>>>>> Stefan
>>>>>
>>>> Output is as follows, I don't have a trunk directory so it's been excluded:
>>>>
>>>> $ svn add wc1\test.txt
>>>> A        wc1\test.txt
>>>>
>>>> $ svn commit wc1 -m "add"
>>>> Adding        wc1\test.txt
>>>> Transmitting file data .
>>>> Committed revision 1.
>>>>
>>>> $ cp test_v2.txt wc1\test.txt
>>>>
>>>> $ svn diff wc1 > out
>>>>
>>>> $ svn revert wc1\test.txt
>>>> Reverted 'wc1\test.txt'
>>>>
>>>> $ patch -d wc1 < out
>>>> patching file 'test.txt'
>>>> Hunk #2 succeeded at 7 (offset 2 lines)
>>> sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
>>> The patch should be applied cleanly, without any offset.
>>>
>>> I haven't found any clear docs on how a patch file really is defined,
>>> but from what I think is wrong:
>>>
>>> The chunk info line
>>> @@ -2,9 +5,9 @@
>>> is wrong. AFAIK the first number (-2) is the line number where removing
>>> starts, the second one the number of lines to remove (including context
>>> lines), the third one (5) the line number where adding starts and the
>>> fourth (9) the number of lines to add (also including context lines).
>>>
>>> Now, in 1.4.x, the diff would have the start line numbers adjusted. The
>>> first chunk is always correct, but now (>= 1.5.x) the line numbers are
>>> always in reference to the original file. Before those lines were
>>> adjusted: if a chunk before added lines or removed lines, the 'start'
>>> lines of the following chunks would take that into account.
>>>
>>> Does anyone know if (and where) the patch file format is documented?
>>> Because I may be completely wrong here - I've implemented the patch
>>> functionality in TortoiseMerge completely by reverse engineering the
>>> format...
>>
>> I get the same patch with 1.4.x and ~trunk (with that line), FWIW.
>> You get something different with 1.4.x?
>
> hmm - no. I also get the same patch with 1.4.x and even 1.3.x.
>
> Problem still is: the original 'patch' tool can't apply that patch
> cleanly without doing 'fuzzy' work. Which means the patch is not correct?
>
> If there was a documentation on how a patch has to be created and how
> those chunk infos are supposed to work, it would be easier...
>
>
> Stefan
>

Here is the specification:
It is POSIX.1-2008 (The Open Group Base Specifications Issue 7)

http://www.opengroup.org/onlinepubs/9699919799/utilities/diff.html
http://www.opengroup.org/onlinepubs/9699919799/utilities/patch.html

Note: The entrance is here:
http://www.opengroup.org/bookstore/catalog/c082.htm
They ask for your name and assign you a cookie.

The previous Issue 6 is freely accessible here, though it does not yet
specify the -u format:
http://www.opengroup.org/onlinepubs/009695399/utilities/diff.html

Best regards,
Konstantin Kolinko

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1010551


Re: svn diff produces a patch which does not reapply cleanly

Posted by Stefan Küng <to...@gmail.com>.
David Glasser wrote:
> On Wed, Jan 7, 2009 at 10:07 AM, Stefan Kueng <to...@gmail.com> wrote:
>> David Ellingsworth wrote:
>>> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>>>> Daniel Shahaf wrote:
>>>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>>>> standard patch command, but not without any fuzz.
>>>>>>
>>>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>>>> indicates this is an error in svn's core since the patch generated is
>>>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>>>> svn client 1.5.1 and 1.5.5.
>>>>>>
>>>>>> Attached are some files I created which are capable of reliably
>>>>>> reproducing the problem. The files are as follows: the original
>>>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>>>> patch file generated from svn diff(test.patch).
>>>>>>
>>>>> What *exactly* should we do with these three files to reproduce the error?
>>>>> (If you can package the answer in script (or transcript) form, that's
>>>>> best.)  I tried
>>>>>
>>>>>       svn add wc1\trunk\test.txt
>>>>>       svn commit wc1 -m "add"
>>>>>       rm -f wc1\trunk\test.txt
>>>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>>>       svn diff wc1 > out
>>>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>>>       svn revert wc1\trunk\test.txt
>>>>>       patch -d wc1\trunk < out
>>>>>       diff -u wc1\trunk\test*.txt
>>>>>
>>>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>>>> found no differences (the expected result).  Results are the same with
>>>>> both 1.5 and trunk.
>>>> Try
>>>>
>>>>  svn add wc1\trunk\test.txt
>>>>  svn commit wc1 -m "add"
>>>>  cp test_v2.txt wc1\trunk\test.txt
>>>>  svn diff wc1 > out
>>>>  svn revert wc1\trunk\test.txt
>>>>  patch -d wc1\trunk < out
>>>>
>>>> Stefan
>>>>
>>> Output is as follows, I don't have a trunk directory so it's been excluded:
>>>
>>> $ svn add wc1\test.txt
>>> A        wc1\test.txt
>>>
>>> $ svn commit wc1 -m "add"
>>> Adding        wc1\test.txt
>>> Transmitting file data .
>>> Committed revision 1.
>>>
>>> $ cp test_v2.txt wc1\test.txt
>>>
>>> $ svn diff wc1 > out
>>>
>>> $ svn revert wc1\test.txt
>>> Reverted 'wc1\test.txt'
>>>
>>> $ patch -d wc1 < out
>>> patching file 'test.txt'
>>> Hunk #2 succeeded at 7 (offset 2 lines)
>> sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
>> The patch should be applied cleanly, without any offset.
>>
>> I haven't found any clear docs on how a patch file really is defined,
>> but from what I think is wrong:
>>
>> The chunk info line
>> @@ -2,9 +5,9 @@
>> is wrong. AFAIK the first number (-2) is the line number where removing
>> starts, the second one the number of lines to remove (including context
>> lines), the third one (5) the line number where adding starts and the
>> fourth (9) the number of lines to add (also including context lines).
>>
>> Now, in 1.4.x, the diff would have the start line numbers adjusted. The
>> first chunk is always correct, but now (>= 1.5.x) the line numbers are
>> always in reference to the original file. Before those lines were
>> adjusted: if a chunk before added lines or removed lines, the 'start'
>> lines of the following chunks would take that into account.
>>
>> Does anyone know if (and where) the patch file format is documented?
>> Because I may be completely wrong here - I've implemented the patch
>> functionality in TortoiseMerge completely by reverse engineering the
>> format...
> 
> I get the same patch with 1.4.x and ~trunk (with that line), FWIW.
> You get something different with 1.4.x?

hmm - no. I also get the same patch with 1.4.x and even 1.3.x.

Problem still is: the original 'patch' tool can't apply that patch
cleanly without doing 'fuzzy' work. Which means the patch is not correct?

If there was a documentation on how a patch has to be created and how
those chunk infos are supposed to work, it would be easier...


Stefan

-- 
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1010485

Re: svn diff produces a patch which does not reapply cleanly

Posted by David Glasser <gl...@davidglasser.net>.
On Wed, Jan 7, 2009 at 10:07 AM, Stefan Kueng <to...@gmail.com> wrote:
> David Ellingsworth wrote:
>> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>>> Daniel Shahaf wrote:
>>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>>> standard patch command, but not without any fuzz.
>>>>>
>>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>>> indicates this is an error in svn's core since the patch generated is
>>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>>> svn client 1.5.1 and 1.5.5.
>>>>>
>>>>> Attached are some files I created which are capable of reliably
>>>>> reproducing the problem. The files are as follows: the original
>>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>>> patch file generated from svn diff(test.patch).
>>>>>
>>>> What *exactly* should we do with these three files to reproduce the error?
>>>> (If you can package the answer in script (or transcript) form, that's
>>>> best.)  I tried
>>>>
>>>>       svn add wc1\trunk\test.txt
>>>>       svn commit wc1 -m "add"
>>>>       rm -f wc1\trunk\test.txt
>>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>>       svn diff wc1 > out
>>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>>       svn revert wc1\trunk\test.txt
>>>>       patch -d wc1\trunk < out
>>>>       diff -u wc1\trunk\test*.txt
>>>>
>>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>>> found no differences (the expected result).  Results are the same with
>>>> both 1.5 and trunk.
>>> Try
>>>
>>>  svn add wc1\trunk\test.txt
>>>  svn commit wc1 -m "add"
>>>  cp test_v2.txt wc1\trunk\test.txt
>>>  svn diff wc1 > out
>>>  svn revert wc1\trunk\test.txt
>>>  patch -d wc1\trunk < out
>>>
>>> Stefan
>>>
>>
>> Output is as follows, I don't have a trunk directory so it's been excluded:
>>
>> $ svn add wc1\test.txt
>> A        wc1\test.txt
>>
>> $ svn commit wc1 -m "add"
>> Adding        wc1\test.txt
>> Transmitting file data .
>> Committed revision 1.
>>
>> $ cp test_v2.txt wc1\test.txt
>>
>> $ svn diff wc1 > out
>>
>> $ svn revert wc1\test.txt
>> Reverted 'wc1\test.txt'
>>
>> $ patch -d wc1 < out
>> patching file 'test.txt'
>> Hunk #2 succeeded at 7 (offset 2 lines)
>
> sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
> The patch should be applied cleanly, without any offset.
>
> I haven't found any clear docs on how a patch file really is defined,
> but from what I think is wrong:
>
> The chunk info line
> @@ -2,9 +5,9 @@
> is wrong. AFAIK the first number (-2) is the line number where removing
> starts, the second one the number of lines to remove (including context
> lines), the third one (5) the line number where adding starts and the
> fourth (9) the number of lines to add (also including context lines).
>
> Now, in 1.4.x, the diff would have the start line numbers adjusted. The
> first chunk is always correct, but now (>= 1.5.x) the line numbers are
> always in reference to the original file. Before those lines were
> adjusted: if a chunk before added lines or removed lines, the 'start'
> lines of the following chunks would take that into account.
>
> Does anyone know if (and where) the patch file format is documented?
> Because I may be completely wrong here - I've implemented the patch
> functionality in TortoiseMerge completely by reverse engineering the
> format...

I get the same patch with 1.4.x and ~trunk (with that line), FWIW.
You get something different with 1.4.x?

--dave


-- 
glasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/


Re: svn diff produces a patch which does not reapply cleanly

Posted by Stefan Kueng <to...@gmail.com>.
David Ellingsworth wrote:
> On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
>> Daniel Shahaf wrote:
>>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>>> while trying to apply a patch with TortoiseMerge that was previously
>>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>>> standard patch command, but not without any fuzz.
>>>>
>>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>>> indicates this is an error in svn's core since the patch generated is
>>>> equivalent to "svn diff file > patchfile". I have verified this using
>>>> svn client 1.5.1 and 1.5.5.
>>>>
>>>> Attached are some files I created which are capable of reliably
>>>> reproducing the problem. The files are as follows: the original
>>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>>> patch file generated from svn diff(test.patch).
>>>>
>>> What *exactly* should we do with these three files to reproduce the error?
>>> (If you can package the answer in script (or transcript) form, that's
>>> best.)  I tried
>>>
>>>       svn add wc1\trunk\test.txt
>>>       svn commit wc1 -m "add"
>>>       rm -f wc1\trunk\test.txt
>>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>>       svn diff wc1 > out
>>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>>       svn revert wc1\trunk\test.txt
>>>       patch -d wc1\trunk < out
>>>       diff -u wc1\trunk\test*.txt
>>>
>>> but it didn't cause any error message, and the 'diff -u' at the end also
>>> found no differences (the expected result).  Results are the same with
>>> both 1.5 and trunk.
>> Try
>>
>>  svn add wc1\trunk\test.txt
>>  svn commit wc1 -m "add"
>>  cp test_v2.txt wc1\trunk\test.txt
>>  svn diff wc1 > out
>>  svn revert wc1\trunk\test.txt
>>  patch -d wc1\trunk < out
>>
>> Stefan
>>
> 
> Output is as follows, I don't have a trunk directory so it's been excluded:
> 
> $ svn add wc1\test.txt
> A        wc1\test.txt
> 
> $ svn commit wc1 -m "add"
> Adding        wc1\test.txt
> Transmitting file data .
> Committed revision 1.
> 
> $ cp test_v2.txt wc1\test.txt
> 
> $ svn diff wc1 > out
> 
> $ svn revert wc1\test.txt
> Reverted 'wc1\test.txt'
> 
> $ patch -d wc1 < out
> patching file 'test.txt'
> Hunk #2 succeeded at 7 (offset 2 lines)

sure, the patch can be applied, but not cleanly - 'offset 2 lines'.
The patch should be applied cleanly, without any offset.

I haven't found any clear docs on how a patch file really is defined,
but from what I think is wrong:

The chunk info line
@@ -2,9 +5,9 @@
is wrong. AFAIK the first number (-2) is the line number where removing
starts, the second one the number of lines to remove (including context
lines), the third one (5) the line number where adding starts and the
fourth (9) the number of lines to add (also including context lines).

Now, in 1.4.x, the diff would have the start line numbers adjusted. The
first chunk is always correct, but now (>= 1.5.x) the line numbers are
always in reference to the original file. Before those lines were
adjusted: if a chunk before added lines or removed lines, the 'start'
lines of the following chunks would take that into account.

Does anyone know if (and where) the patch file format is documented?
Because I may be completely wrong here - I've implemented the patch
functionality in TortoiseMerge completely by reverse engineering the
format...

Stefan

-- 
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1010205

Re: svn diff produces a patch which does not reapply cleanly

Posted by David Ellingsworth <da...@identd.dyndns.org>.
On Wed, Jan 7, 2009 at 11:26 AM, Stefan Küng <to...@gmail.com> wrote:
> Daniel Shahaf wrote:
>> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>>> while trying to apply a patch with TortoiseMerge that was previously
>>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>>> to apply the patch with TortoiseMerge, I did succeed while using the
>>> standard patch command, but not without any fuzz.
>>>
>>> The reply to the issue I posted on TortioseSVN"s user mailing list
>>> indicates this is an error in svn's core since the patch generated is
>>> equivalent to "svn diff file > patchfile". I have verified this using
>>> svn client 1.5.1 and 1.5.5.
>>>
>>> Attached are some files I created which are capable of reliably
>>> reproducing the problem. The files are as follows: the original
>>> file(test.txt), the updated file(test_v2.txt), and the associated
>>> patch file generated from svn diff(test.patch).
>>>
>>
>> What *exactly* should we do with these three files to reproduce the error?
>> (If you can package the answer in script (or transcript) form, that's
>> best.)  I tried
>>
>>       svn add wc1\trunk\test.txt
>>       svn commit wc1 -m "add"
>>       rm -f wc1\trunk\test.txt
>>       cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>>       svn diff wc1 > out
>>       vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>>       svn revert wc1\trunk\test.txt
>>       patch -d wc1\trunk < out
>>       diff -u wc1\trunk\test*.txt
>>
>> but it didn't cause any error message, and the 'diff -u' at the end also
>> found no differences (the expected result).  Results are the same with
>> both 1.5 and trunk.
>
> Try
>
>  svn add wc1\trunk\test.txt
>  svn commit wc1 -m "add"
>  cp test_v2.txt wc1\trunk\test.txt
>  svn diff wc1 > out
>  svn revert wc1\trunk\test.txt
>  patch -d wc1\trunk < out
>
> Stefan
>

Output is as follows, I don't have a trunk directory so it's been excluded:

$ svn add wc1\test.txt
A        wc1\test.txt

$ svn commit wc1 -m "add"
Adding        wc1\test.txt
Transmitting file data .
Committed revision 1.

$ cp test_v2.txt wc1\test.txt

$ svn diff wc1 > out

$ svn revert wc1\test.txt
Reverted 'wc1\test.txt'

$ patch -d wc1 < out
patching file 'test.txt'
Hunk #2 succeeded at 7 (offset 2 lines)

Regards,

David Ellingsworth


Re: svn diff produces a patch which does not reapply cleanly

Posted by Stefan Kueng <to...@gmail.com>.
Daniel Shahaf wrote:
> David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
>> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
>> while trying to apply a patch with TortoiseMerge that was previously
>> created using TortoiseSVN's "Create Patch" feature. While I was unable
>> to apply the patch with TortoiseMerge, I did succeed while using the
>> standard patch command, but not without any fuzz.
>>
>> The reply to the issue I posted on TortioseSVN"s user mailing list
>> indicates this is an error in svn's core since the patch generated is
>> equivalent to "svn diff file > patchfile". I have verified this using
>> svn client 1.5.1 and 1.5.5.
>>
>> Attached are some files I created which are capable of reliably
>> reproducing the problem. The files are as follows: the original
>> file(test.txt), the updated file(test_v2.txt), and the associated
>> patch file generated from svn diff(test.patch).
>>
> 
> What *exactly* should we do with these three files to reproduce the error? 
> (If you can package the answer in script (or transcript) form, that's 
> best.)  I tried
> 
> 	svn add wc1\trunk\test.txt
> 	svn commit wc1 -m "add"
> 	rm -f wc1\trunk\test.txt
> 	cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
> 	svn diff wc1 > out
> 	vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
> 	svn revert wc1\trunk\test.txt
> 	patch -d wc1\trunk < out
> 	diff -u wc1\trunk\test*.txt
> 
> but it didn't cause any error message, and the 'diff -u' at the end also 
> found no differences (the expected result).  Results are the same with 
> both 1.5 and trunk.

Try

  svn add wc1\trunk\test.txt
  svn commit wc1 -m "add"
  cp test_v2.txt wc1\trunk\test.txt
  svn diff wc1 > out
  svn revert wc1\trunk\test.txt
  patch -d wc1\trunk < out

Stefan


-- 
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1010128

Re: svn diff produces a patch which does not reapply cleanly

Posted by David Ellingsworth <da...@identd.dyndns.org>.
> What *exactly* should we do with these three files to reproduce the error?
> (If you can package the answer in script (or transcript) form, that's
> best.)  I tried
>
>        svn add wc1\trunk\test.txt
>        svn commit wc1 -m "add"
>        rm -f wc1\trunk\test.txt
>        cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
>        svn diff wc1 > out
>        vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
>        svn revert wc1\trunk\test.txt
>        patch -d wc1\trunk < out
>        diff -u wc1\trunk\test*.txt
>
> but it didn't cause any error message, and the 'diff -u' at the end also
> found no differences (the expected result).  Results are the same with
> both 1.5 and trunk.
>
> Daniel
>

The steps to reproduce are as follows:

svn add test.txt
svn commit  -m "add"
cp test_v2.txt test.txt
svn diff > patchfile
svn revert test.txt
patch -p0 < patchfile

There's a possibility this could be a platform issue as I am using
Windows XP. TortoiseSVN was used to create the repository, svn client
version 1.5.5 from Colabnet was used to add/commit/diff/revert the
file, and patch version 2.5 distributed with msysgit 1.6.1 preview was
used to patch the file. Please retest this on an Windows box please.

Regards,

David Ellingsworth

Re: svn diff produces a patch which does not reapply cleanly

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
David Ellingsworth wrote on Tue, 6 Jan 2009 at 19:57 -0500:
> While using TortoiseSVN 1.5.6 build 14908, I encountered an error
> while trying to apply a patch with TortoiseMerge that was previously
> created using TortoiseSVN's "Create Patch" feature. While I was unable
> to apply the patch with TortoiseMerge, I did succeed while using the
> standard patch command, but not without any fuzz.
> 
> The reply to the issue I posted on TortioseSVN"s user mailing list
> indicates this is an error in svn's core since the patch generated is
> equivalent to "svn diff file > patchfile". I have verified this using
> svn client 1.5.1 and 1.5.5.
> 
> Attached are some files I created which are capable of reliably
> reproducing the problem. The files are as follows: the original
> file(test.txt), the updated file(test_v2.txt), and the associated
> patch file generated from svn diff(test.patch).
> 

What *exactly* should we do with these three files to reproduce the error? 
(If you can package the answer in script (or transcript) form, that's 
best.)  I tried

	svn add wc1\trunk\test.txt
	svn commit wc1 -m "add"
	rm -f wc1\trunk\test.txt
	cp wc1\trunk\test_v2.txt wc1\trunk\test.txt
	svn diff wc1 > out
	vim -Nu NONE -c "%s/\r//" -c "wq ++ff=dos" out
	svn revert wc1\trunk\test.txt
	patch -d wc1\trunk < out
	diff -u wc1\trunk\test*.txt

but it didn't cause any error message, and the 'diff -u' at the end also 
found no differences (the expected result).  Results are the same with 
both 1.5 and trunk.

Daniel


    
> For reference purposes, the original report posted to TortioseSVN's
> user mailing list can be found here:
> http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=1007806
> 
> Regards,
> 
> David Ellingsworth
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1009661