subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1206724 - in /subversion/trunk/subversion: libsvn_diff/parse-diff.c tests/cmdline/patch_tests.py
Date Sun, 27 Nov 2011 14:41:57 GMT
Author: stsp
Date: Sun Nov 27 14:41:56 2011
New Revision: 1206724

URL: http://svn.apache.org/viewvc?rev=1206724&view=rev
Log:
Fix issue #3991, "'svn patch' deletes random lines with patch files missing
trailing newline".

Contrary to UNIX patch behaviour, I decided not to have 'svn patch' error
out on hunks that end at EOF before EOL was found. Instead of throwing an
error 'svn patch' writes the final line without terminating it with EOL.
The output of 'svn diff' clearly marks the missing EOL. Users can fix up
the patched result as required.

Another approach suggested in #3991 was to automatically fix up the line
by appending an EOL. There are two problems with this:
  1) We don't know if the short line read from the hunk text was complete.
     E.g. the last line of the patch might originally have been "foobar\n" and
     cut short to just "foo". Writing "foo" instead of "foo\n" to the patched
     result seems more reasonable in this case.
  2) Adding the EOL would require more extensive changes. So far, content
     written to the patched result is also present in the patch file.
     We'd have to remember that a final EOL is missing and fake it, which
     requires more state to keep than simply omiting the EOL.

* subversion/libsvn_diff/parse-diff.c
  (parse_next_hunk): Update current file position even if at EOF.
    If hunk text ends at EOF set the end of the hunk text range to the
    last byte of the file.

* subversion/tests/cmdline/patch_tests.py
  (patch_lacking_trailing_eol): Adjust text expections and remove XFail marker.

Modified:
    subversion/trunk/subversion/libsvn_diff/parse-diff.c
    subversion/trunk/subversion/tests/cmdline/patch_tests.py

Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=1206724&r1=1206723&r2=1206724&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original)
+++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Sun Nov 27 14:41:56 2011
@@ -632,12 +632,9 @@ parse_next_hunk(svn_diff_hunk_t **hunk,
       SVN_ERR(readline(apr_file, &line, NULL, &eof, APR_SIZE_MAX,
                        iterpool, iterpool));
 
-      if (! eof)
-        {
-          /* Update line offset for next iteration. */
-          pos = 0;
-          SVN_ERR(svn_io_file_seek(apr_file, APR_CUR, &pos, iterpool));
-        }
+      /* Update line offset for next iteration. */
+      pos = 0;
+      SVN_ERR(svn_io_file_seek(apr_file, APR_CUR, &pos, iterpool));
 
       /* Lines starting with a backslash are comments, such as
        * "\ No newline at end of file". */
@@ -733,9 +730,17 @@ parse_next_hunk(svn_diff_hunk_t **hunk,
             }
           else
             {
-              /* The start of the current line marks the first byte
-               * after the hunk text. */
-              end = last_line;
+              if (eof)
+                {
+                  /* The hunk ends at EOF. */
+                  end = pos;
+                }
+              else
+                {
+                  /* The start of the current line marks the first byte
+                   * after the hunk text. */
+                  end = last_line;
+                }
 
               break; /* Hunk was empty or has been read. */
             }

Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=1206724&r1=1206723&r2=1206724&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Sun Nov 27 14:41:56 2011
@@ -3614,7 +3614,6 @@ def patch_moved_away(sbox):
                                        1, # check-props
                                        1) # dry-run
 
-@XFail()
 @Issue(3991)
 def patch_lacking_trailing_eol(sbox):
   "patch file lacking trailing eol"
@@ -3649,12 +3648,11 @@ def patch_lacking_trailing_eol(sbox):
 
   expected_output = [
     'U         %s\n' % os.path.join(wc_dir, 'iota'),
-    'svn: W[0-9]+: .*', # warning about appending a newline to iota's last line
   ]
 
   # Expect a newline to be appended
   expected_disk = svntest.main.greek_state.copy()
-  expected_disk.tweak('iota', contents=iota_contents+"Some more bytes\n")
+  expected_disk.tweak('iota', contents=iota_contents + "Some more bytes")
 
   expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
   expected_status.tweak('iota', status='M ')



Mime
View raw message