[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: SVN patch IGNORES file without newline at end of file

From: cz02 <cz02_at_cdak.net>
Date: Tue, 16 Oct 2012 14:03:17 +0200

On 2012-10-16 11:41, Johan Corveleyn wrote:
> On Tue, Oct 16, 2012 at 11:35 AM, cz02 <cz02_at_cdak.net> wrote:
>> On 2012-10-16 10:52, Johan Corveleyn wrote:
>>>
>>> On Mon, Oct 15, 2012 at 9:12 PM, cz02<cz02_at_cdak.net> wrote:
>>>>
>>>>> Please verify this bug report:
>>>>>
>>>>> I have two identical files aaa.txt and bbb.txt except that aaa.txt has
>>>>> no
>>>>> "newline at end of file".
>>>>>
>>>>> When applying a patch (created with svn diff > p.patch) my modifications
>>>>> for
>>>>> aaa.txt are simply ignored with no error or warning!
>>>>>
>>>>>
>>>>>>> svn patch p.patch
>>>>
>>>>>
>>>>> U bbb.txt
>>>>>
>>>>> If I remove the line "\ No newline at end of file" from the patch file
>>>>> and
>>>>> apply it again (after reverting), everything works as expected:
>>>>>
>>>>>
>>>>>>> svn patch p2.patch
>>>>
>>>>>
>>>>> U aaa.txt
>>>>> U bbb.txt
>>>>>
>>>>> To reproduce simply create an empty repository and add aaa.txt and
>>>>> bbb.txt
>>>>> then try to apply the patches.
>>>>> Sample files attached.
>>>>>
>>>>> OS: Windows 7 sp1
>>>>> svn, version 1.7.7 (r1393599) - by SilkSVN
>>>>> compiled Oct 8 2012, 10:42:55
>>>>>
>>>>> I tried to get this verified on the users group but only found out that
>>>>> the
>>>>> issue does not exist on Unix - might be a Windows only bug.
>>>
>>> I can't reproduce this. I'm on Windows 7 sp1 too, with svn 1.7.7
>>> (SlikSVN).
>>>
>>> I tried two variations: one where svn:eol-style=native would be set
>>> automatically by my normal auto-props settings. And one where I
>>> disable auto-props before adding the files. Neither of the variations
>>> had the problem that you observed. So I'm not sure what could be
>>> different on your machine vs. my setup.
>>>
>>> Here is a transcript of what I did (in cmd.exe):
>>> [[[
>>> ### First attempt, with my regular auto-props setting
>>> C:\Temp\testje>svnadmin create repos
>>>
>>> C:\Temp\testje>svn cofile:///C:/Temp/testje/repos wc
>>>
>>> Checked out revision 0.
>>>
>>> C:\Temp\testje>cd wc
>>>
>>> C:\Temp\testje\wc>copy ..\*.txt .
>>> ..\aaa.txt
>>> ..\bbb.txt
>>> 2 file(s) copied.
>>>
>>> C:\Temp\testje\wc>dir
>>> Volume in drive C is Default
>>> Volume Serial Number is A65F-CF5B
>>>
>>> Directory of C:\Temp\testje\wc
>>>
>>> 16-10-2012 10:33 <DIR> .
>>> 16-10-2012 10:33 <DIR> ..
>>> 11-10-2012 12:12 52 aaa.txt
>>> 11-10-2012 12:12 54 bbb.txt
>>> 2 File(s) 106 bytes
>>> 2 Dir(s) 156.481.060.864 bytes free
>>>
>>> C:\Temp\testje\wc>svn add aaa.txt bbb.txt
>>> A aaa.txt
>>> A bbb.txt
>>>
>>> C:\Temp\testje\wc>svn pl -v aaa.txt
>>> Properties on 'aaa.txt':
>>> svn:eol-style
>>> native
>>>
>>> C:\Temp\testje\wc>svn commit -m"adding files"
>>> Adding aaa.txt
>>> Adding bbb.txt
>>> Transmitting file data ..
>>> Committed revision 1.
>>>
>>> C:\Temp\testje\wc>svn up
>>> Updating '.':
>>> At revision 1.
>>>
>>> C:\Temp\testje\wc>svn st
>>>
>>> C:\Temp\testje\wc>cat ..\p.patch
>>> Index: aaa.txt
>>> ===================================================================
>>> --- aaa.txt (revision 912)
>>> +++ aaa.txt (working copy)
>>> @@ -2,6 +2,6 @@
>>> {
>>> void bar()
>>> {
>>> - //dummy
>>> + //more
>>> }
>>> }
>>> \ No newline at end of file
>>> Index: bbb.txt
>>> ===================================================================
>>> --- bbb.txt (revision 912)
>>> +++ bbb.txt (working copy)
>>> @@ -2,6 +2,6 @@
>>> {
>>> void bar()
>>> {
>>> - //dummy
>>> + //more
>>> }
>>> }
>>>
>>> C:\Temp\testje\wc>svn patch ..\p.patch
>>> U aaa.txt
>>> U bbb.txt
>>>
>>> C:\Temp\testje\wc>svn revert *.txt
>>> Reverted 'aaa.txt'
>>> Reverted 'bbb.txt'
>>>
>>> C:\Temp\testje\wc>svn patch ..\p2.patch
>>> U aaa.txt
>>> U bbb.txt
>>>
>>> C:\Temp\testje\wc>svn revert *.txt
>>> Reverted 'aaa.txt'
>>> Reverted 'bbb.txt'
>>>
>>>
>>> ### Second attempt, disabling auto-props
>>> C:\Temp\testje\wc>cd ..
>>>
>>> C:\Temp\testje>svnadmin create repos2
>>>
>>> C:\Temp\testje>svn cofile:///C:/Temp/testje/repos2 wc2
>>>
>>> Checked out revision 0.
>>>
>>> C:\Temp\testje>cd wc2
>>>
>>> C:\Temp\testje\wc2>copy ..\*.txt .
>>> ..\aaa.txt
>>> ..\bbb.txt
>>> 2 file(s) copied.
>>>
>>> C:\Temp\testje\wc2>svn add --config-option
>>> config:miscellany:enable-auto-props=no aaa.txt bbb.txt
>>> A aaa.txt
>>> A bbb.txt
>>>
>>> C:\Temp\testje\wc2>svn pl -v aaa.txt
>>>
>>> C:\Temp\testje\wc2>svn commit -m"adding files"
>>> Adding aaa.txt
>>> Adding bbb.txt
>>> Transmitting file data ..
>>> Committed revision 1.
>>>
>>> C:\Temp\testje\wc2>svn up
>>> Updating '.':
>>> At revision 1.
>>>
>>> C:\Temp\testje\wc2>dir
>>> Volume in drive C is Default
>>> Volume Serial Number is A65F-CF5B
>>>
>>> Directory of C:\Temp\testje\wc2
>>>
>>> 16-10-2012 10:40 <DIR> .
>>> 16-10-2012 10:40 <DIR> ..
>>> 11-10-2012 12:12 52 aaa.txt
>>> 11-10-2012 12:12 54 bbb.txt
>>> 2 File(s) 106 bytes
>>> 2 Dir(s) 157.020.934.144 bytes free
>>>
>>> C:\Temp\testje\wc2>svn patch ..\p.patch
>>> U aaa.txt
>>> U bbb.txt
>>>
>>> C:\Temp\testje\wc2>svn revert *.txt
>>> Reverted 'aaa.txt'
>>> Reverted 'bbb.txt'
>>>
>>> C:\Temp\testje\wc2>svn patch ..\p2.patch
>>> U aaa.txt
>>> U bbb.txt
>>> ]]]
>>>
>>> -- Johan
>>>
>>
>> That's very strange because even if I follow your steps my "aaa.txt" file
>> still does not get updated:
>>
>> Y:\test2\wc2>svn patch p.patch
>> U bbb.txt
>>
>> Y:\test2\wc2>
>>
>> My machine is plain Windows 7 Enterprise with a few developement tools
>> installed (Visual Studio).
>>
>> So I also tested this on a Windows 2003 Server machine which still has SVN
>> 1.7.4 and it gave me the same result:
>>
>> V:\temp\wc2>svn patch p.patch
>> U bbb.txt
>>
>> V:\temp\wc2>svn --version
>> svn, version 1.7.4 (r1295709)
>> compiled Mar 5 2012, 09:29:21
>>
>> Any ideas what I can do to isolate the problem?
>
> Hm, strange. Did you follow my steps exactly? Did you perform the 'svn
> up' right after committing the added files (and before applying the
> patch)? That might make a difference, because without that 'svn
> update' you'll have a mixed revision working copy (the parent
> directory will still be on the revision before the add) --- the 'svn
> update' brings everything to a uniform revision.
>

Yes, I did "svn up".

I've tried changing the patchfile and found that if I remove the \r\n
after "\ No newline at end of file" (making it "\ No newline at end of
fileIndex: bbb.txt") it will work!

The patchfile is now clearly invalid but it makes svn patch the changes
to aaa.txt:

Y:\test2\wc2>svn patch p3-noeol.patch
U aaa.txt
U bbb.txt

also aaa.txt will now contain a newline at the end of the file!

I guess the problem must occur somewhere in parse-diff.c:

       /* Lines starting with a backslash are comments, such as
        * "\ No newline at end of file". */
       if (line->data[0] == '\\')
         {
           if (in_hunk &&
               ((!*is_property &&
                 strcmp(line->data, "\\ No newline at end of file") == 0) ||
                (*is_property &&
                 strcmp(line->data, "\\ No newline at end of property")
== 0)))
             {
               char eolbuf[2];
               apr_size_t len;
               apr_off_t off;
               apr_off_t hunk_text_end;

               /* Comment terminates the hunk text and says the hunk text
                * has no trailing EOL. Snip off trailing EOL which is part
                * of the patch file but not part of the hunk text. */
               off = last_line - 2;
               SVN_ERR(svn_io_file_seek(apr_file, APR_SET, &off, iterpool));
               len = sizeof(eolbuf);
               SVN_ERR(svn_io_file_read_full2(apr_file, eolbuf, len, &len,
                                              &eof, iterpool));
               if (eolbuf[0] == '\r' && eolbuf[1] == '\n')
                 hunk_text_end = last_line - 2;
               else if (eolbuf[1] == '\n' || eolbuf[1] == '\r')
                 hunk_text_end = last_line - 1;
               else
                 hunk_text_end = last_line;

               if (last_line_type == original_line && original_end == 0)
                 original_end = hunk_text_end;
               else if (last_line_type == modified_line && modified_end
== 0)
                 modified_end = hunk_text_end;
               else if (last_line_type == context_line)
                 {
                   if (original_end == 0)
                     original_end = hunk_text_end;
                   if (modified_end == 0)
                     modified_end = hunk_text_end;
                   break;
                 }

               SVN_ERR(svn_io_file_seek(apr_file, APR_SET, &pos, iterpool));
             }

           continue;
         }

...

possibly here:

   if (hunk_seen && start < end)
     {
       ...
     }
   else
     /* Something went wrong, just discard the result. */
     *hunk = NULL;

bye, chris

Received on 2012-10-16 14:03:50 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.