On Tue, Feb 23, 2010 at 11:48:07PM +0100, Stefan Sperling wrote:
> Can you post the test?

I've attached the test.

Error cases
--------------
If there are lines in the target before the hunk we will get the error
of inconsistent line endings when applying the hunk lines. (Remove the #
from the first line of mu_contents and change hunk offset to run).
[[[
Testing nr 1 of eols list for patch_eol
Testing nr 2 of eols list for patch_eol
subversion/svn/patch-cmd.c:81: (apr_err=135000)
subversion/libsvn_client/patch.c:1463: (apr_err=135000)
subversion/libsvn_client/patch.c:1410: (apr_err=135000)
subversion/libsvn_client/patch.c:1093: (apr_err=135000)
subversion/libsvn_client/patch.c:932: (apr_err=135000)
subversion/libsvn_client/patch.c:799: (apr_err=135000)
subversion/libsvn_subr/subst.c:876: (apr_err=135000)
subversion/libsvn_subr/subst.c:643: (apr_err=135000)
svn: Inconsistent line ending style
]]]


If there are no lines in the target before the hunk we will get the
error when copying the remaining lines.
[[[
Testing nr 1 of eols list for patch_eol
Testing nr 2 of eols list for patch_eol
subversion/svn/patch-cmd.c:81: (apr_err=135000)
subversion/libsvn_client/patch.c:1463: (apr_err=135000)
subversion/libsvn_client/patch.c:1410: (apr_err=135000)
subversion/libsvn_client/patch.c:1100: (apr_err=135000)
subversion/libsvn_client/patch.c:830: (apr_err=135000)
subversion/libsvn_client/patch.c:799: (apr_err=135000)
subversion/libsvn_subr/subst.c:876: (apr_err=135000)
subversion/libsvn_subr/subst.c:643: (apr_err=135000)
svn: Inconsistent line ending style
]]]


Naive attempts without truly understanding the problem
--------------------------------------------------------
1) If I if-zero the error in libsvn_subr/subst.c:643 and have one line
before the hunk I get:
[[[
=============================================================
EXPECTED NODE FOUND:
=============================================================
 * Node name:   mu
    Path:       __SVN_ROOT_NODE/A/mu
It is a promotional program aimed at encouraging internet users;d.w
    Properties: {}
    Attributes: {}
    Children:  None (node is probably a file)
=============================================================
ACTUAL NODE FOUND:
=============================================================
 * Node name:   mu
    Path:       __SVN_ROOT_NODE/A/mu
It is a promotional program aimed at encouraging internet users;d.w
    Properties: {}
    Attributes: {}
    Children:  None (node is probably a file)
]]]

I wonder what 'd.w' means and why I'm not getting the full text?

2) If I catch SVN_ERR_IO_INCONSISTENT_EOL when we write to target->patched
the patch deletes the file A/mu! Appearantly there's more to this than
meets the eye!

Trying to understand the problem
----------------------------------
A translated stream expects that the stuff to be written will have
consistent line endings. It checks for consistent line endings by
comparing the eol with the first eol written to the stream. If the first
thing written is from the target, we will compare all subsequent eols
with the targets eol. If it's from the patch, we will compare all
subsequent eols with the patchs eol.

What to do
-------------
[ ] Add a flag to svn_subst_stream_translated() to allow for
    inconsistent line endings. It's ugly but what else can we do? We
    don't want to reinvent the quirky logic to translate streams.
[ ] [Placeholder for suggestions]

Maybe a separate issue
--------------------------
If we if-zero the error in libsvn_subr/subst.c:643 and have one line
directly after the hunk with just a newline, that newline is not
inserted when:
target has eol '\n' ('\012' on unix) and patch has eol '\015' ('\r').
target has eol '\012' and patch has eol '\015' ('\r')

If we have this, the newline is inserted:
[[[
The hunk content
A line from target with more than just a newline
A newline from target
]]]

Daniel
Index: subversion/tests/cmdline/patch_tests.py
===================================================================
--- subversion/tests/cmdline/patch_tests.py     (revision 915715)
+++ subversion/tests/cmdline/patch_tests.py     (arbetskopia)
@@ -1352,6 +1352,95 @@
                                        1, # dry-run
                                        '--reverse-diff')
 
+def patch_different_eol_without_props(sbox):
+  "apply a patch with different eols and no props"
+
+  sbox.build()
+  wc_dir = sbox.wc_dir
+
+  patch_file_path = 
tempfile.mkstemp(dir=os.path.abspath(svntest.main.temp_dir))[1]
+  mu_path = os.path.join(wc_dir, 'A', 'mu')
+
+  if os.name == 'nt':
+    crlf = '\n'
+  else:
+    crlf = '\r\n'
+
+  eols = [crlf, '\015', '\n', '\012']
+
+  for target_eol in eols:
+    i = 0
+    for patch_eol in eols:
+      i = i + 1 
+      print "Testing nr " + str(i) + " of eols list for patch_eol"
+      mu_contents = [
+        #"Dear internet user,", target_eol,
+        target_eol,
+        "We wish to congratulate you over your email success in our computer", 
target_eol,
+        "Balloting. This is a Millennium Scientific Electronic Computer Draw", 
target_eol,
+        "in which email addresses were used. All participants were selected", 
target_eol,
+        "through a computer ballot system drawn from over 100,000 company", 
target_eol,
+        "and 50,000,000 individual email addresses from all over the world.", 
target_eol,
+        "It is a promotional program aimed at encouraging internet users;", 
target_eol,
+        target_eol,
+      ]
+
+      # Set mu contents
+      svntest.main.file_write(mu_path, ''.join(mu_contents))
+
+      unidiff_patch = [
+        "Index: mu\n",
+        
"===================================================================\n",
+        "--- A/mu\t(revision 0)\n",
+        "+++ A/mu\t(revision 0)\n",
+        "@@ -1,6 +1,7 @@\n",
+        patch_eol,
+        " We wish to congratulate you over your email success in our 
computer", patch_eol,
+        " Balloting. This is a Millennium Scientific Electronic Computer 
Draw", patch_eol,
+        "+A new line here", patch_eol,
+        " in which email addresses were used. All participants were selected", 
patch_eol,
+        " through a computer ballot system drawn from over 100,000 company", 
patch_eol,
+        " and 50,000,000 individual email addresses from all over the world.", 
patch_eol,
+      ]
+
+      mu_contents = [
+        #"Dear internet user,", target_eol,
+        target_eol,
+        "We wish to congratulate you over your email success in our computer", 
target_eol,
+        "Balloting. This is a Millennium Scientific Electronic Computer Draw", 
target_eol,
+        "A new line here", target_eol,
+        "in which email addresses were used. All participants were selected", 
target_eol,
+        "through a computer ballot system drawn from over 100,000 company", 
target_eol,
+        "and 50,000,000 individual email addresses from all over the world.", 
target_eol,
+        "It is a promotional program aimed at encouraging internet users;", 
target_eol,
+        target_eol,
+      ]
+
+      svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
+
+      expected_output = [
+        'G         %s\n' % os.path.join(wc_dir, 'A', 'mu'),
+      ]
+      expected_disk = svntest.main.greek_state.copy()
+      expected_disk.tweak('A/mu', contents=''.join(mu_contents))
+
+      expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
+      expected_status.tweak('A/mu', status='M ', wc_rev=1)
+
+      expected_skip = wc.State('', { })
+
+      svntest.actions.run_and_verify_patch(wc_dir, 
os.path.abspath(patch_file_path),
+                                           expected_output,
+                                           expected_disk,
+                                           expected_status,
+                                           expected_skip,
+                                           None, # expected err
+                                           1, # check-props
+                                           1) # dry-run
+
+      expected_output = ["Reverted '" + mu_path + "'\n"]
+      svntest.actions.run_and_verify_svn(None, expected_output, [], 'revert', 
'-R', wc_dir)
+
 ########################################################################
 #Run the tests
 
@@ -1367,6 +1456,7 @@
               patch_keywords,
               patch_with_fuzz,
               patch_reverse,
+              patch_different_eol_without_props,
             ]
 
 if __name__ == '__main__':

Reply via email to