You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2013/01/18 16:32:52 UTC

svn commit: r1435195 - in /subversion/trunk/subversion: libsvn_wc/merge.c tests/cmdline/merge_tests.py

Author: julianfoad
Date: Fri Jan 18 15:32:52 2013
New Revision: 1435195

URL: http://svn.apache.org/viewvc?rev=1435195&view=rev
Log:
Teach the file merge code to recognize keyword translation even in 'binary'
files.  Fixes issue #4221 "Trivial merge of a binary file with svn:keywords
raises a conflict".  The problem was that in deciding whether a trivial
merge is possible, it wasn't detranslating keywords in the working file
before comparing with the incoming left and right files.

* subversion/libsvn_wc/merge.c
  (detranslate_wc_file): Detranslate keywords even in 'binary' files.

* subversion/tests/cmdline/merge_tests.py
  (merge_binary_file_with_keywords): Extend to test multiple permutations.

Modified:
    subversion/trunk/subversion/libsvn_wc/merge.c
    subversion/trunk/subversion/tests/cmdline/merge_tests.py

Modified: subversion/trunk/subversion/libsvn_wc/merge.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/merge.c?rev=1435195&r1=1435194&r2=1435195&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/merge.c (original)
+++ subversion/trunk/subversion/libsvn_wc/merge.c Fri Jan 18 15:32:52 2013
@@ -99,39 +99,48 @@ get_prop(const apr_array_header_t *prop_
 
    Effect for svn:mime-type:
 
-     The value for svn:mime-type affects the translation wrt keywords
-     and eol-style settings.
+     If svn:mime-type is considered 'binary', we ignore svn:eol-style (but
+     still translate keywords).
 
      I) both old and new mime-types are texty
         -> just do the translation dance (as lined out below)
+           ### actually we do a shortcut with just one translation:
+           detranslate with the old keywords and ... eol-style
+           (the new re+detranslation is a no-op w.r.t. keywords [1])
 
      II) the old one is texty, the new one is binary
         -> detranslate with the old eol-style and keywords
-           (the new re+detranslation is a no-op)
+           (the new re+detranslation is a no-op [1])
 
      III) the old one is binary, the new one texty
-        -> detranslate with the new eol-style
-           (the old detranslation is a no-op)
+        -> detranslate with the old keywords and new eol-style
+           (the old detranslation is a no-op w.r.t. eol, and
+            the new re+detranslation is a no-op w.r.t. keywords [1])
 
      IV) the old and new ones are binary
-        -> don't detranslate, just make a straight copy
-
+        -> detranslate with the old keywords
+           (the new re+detranslation is a no-op [1])
 
    Effect for svn:eol-style
 
-     I) On add or change use the new value
+     I) On add or change of svn:eol-style, use the new value
 
      II) otherwise: use the old value (absent means 'no translation')
 
-
    Effect for svn:keywords
 
-     Always use old settings (re+detranslation are no-op)
+     Always use the old settings (re+detranslation are no-op [1]).
 
+     [1] Translation of keywords from repository normal form to WC form and
+         back is normally a no-op, but is not a no-op if text contains a kw
+         that is only enabled by the new props and is present in non-
+         contracted form (such as "$Rev: 1234 $").  If we want to catch this
+         case we should detranslate with both the old & the new keywords
+         together.
 
    Effect for svn:special
 
-     Always use the old settings (same reasons as for svn:keywords)
+     Always use the old settings (re+detranslation are no-op).
 
   Sets *DETRANSLATED_ABSPATH to the path to the detranslated file,
   this may be the same as SOURCE_ABSPATH if FORCE_COPY is FALSE and no
@@ -173,18 +182,22 @@ detranslate_wc_file(const char **detrans
     new_is_binary = new_mime_value && svn_mime_type_is_binary(new_mime_value);;
   }
 
-  /* See if we need to do a straight copy: old and new mime-types are binary */
+  /* See what translations we want to do */
   if (old_is_binary && new_is_binary)
     {
-      /* this is case IV above */
-      keywords = NULL;
+      /* Case IV. Old and new props 'binary': detranslate keywords only */
+      SVN_ERR(svn_wc__get_translate_info(NULL, NULL, &keywords, NULL,
+                                         mt->db, mt->local_abspath,
+                                         mt->old_actual_props, TRUE,
+                                         scratch_pool, scratch_pool));
+      /* ### Why override 'special'? Elsewhere it has precedence. */
       special = FALSE;
       eol = NULL;
       style = svn_subst_eol_style_none;
     }
   else if (!old_is_binary && new_is_binary)
     {
-      /* Old props indicate texty, new props indicate binary:
+      /* Case II. Old props indicate texty, new props indicate binary:
          detranslate keywords and old eol-style */
       SVN_ERR(svn_wc__get_translate_info(&style, &eol,
                                          &keywords,
@@ -195,7 +208,7 @@ detranslate_wc_file(const char **detrans
     }
   else
     {
-      /* New props indicate texty, regardless of old props */
+      /* Case I & III. New props indicate texty, regardless of old props */
 
       /* In case the file used to be special, detranslate specially */
       SVN_ERR(svn_wc__get_translate_info(&style, &eol,
@@ -230,11 +243,6 @@ detranslate_wc_file(const char **detrans
               eol = NULL;
               style = svn_subst_eol_style_none;
             }
-
-          /* In case there were keywords, detranslate with keywords
-             (iff we were texty) */
-          if (old_is_binary)
-            keywords = NULL;
         }
     }
 

Modified: subversion/trunk/subversion/tests/cmdline/merge_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/merge_tests.py?rev=1435195&r1=1435194&r2=1435195&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/merge_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/merge_tests.py Fri Jan 18 15:32:52 2013
@@ -17872,11 +17872,11 @@ def merge_with_externals_with_mergeinfo(
     A_path)
 
 #----------------------------------------------------------------------
-# Test for issue #4221 'Trivial merge of a binary file with svn:keywords
-# raises a conflict'.
+# Test merging 'binary' files with keyword expansion enabled.
+# Tests issue #4221 'Trivial merge of a binary file with svn:keywords
+# raises a conflict', among other cases.
 @SkipUnless(server_has_mergeinfo)
 @Issue(4221)
-@XFail()
 def merge_binary_file_with_keywords(sbox):
   "merge binary file with keywords"
 
@@ -17884,32 +17884,66 @@ def merge_binary_file_with_keywords(sbox
   os.chdir(sbox.wc_dir)
   sbox.wc_dir = ''
 
-  # make a 'binary' file with keyword expansion enabled
-  svntest.main.file_write('foo', "Line 1 with $Revision: $ keyword.\n")
-  sbox.simple_add('foo')
-  sbox.simple_propset('svn:mime-type', 'application/octet-stream', 'foo')
-  sbox.simple_propset('svn:keywords', 'Revision', 'foo')
+  # Some binary files, and some binary files that will become text files.
+  # 'mod_src' means a content change on the branch (the merge source);
+  # 'mod_tgt' means a content change on the original (the merge target);
+  # 'to_txt' means svn:mime-type removed on the branch (the merge source).
+  file_mod_both           = 'A/B/E/alpha'
+  file_mod_src            = 'A/D/G/pi'
+  file_mod_tgt            = 'A/D/G/rho'
+  file_mod_none           = 'A/D/G/tau'
+  file_mod_both_to_txt    = 'A/B/E/beta'
+  file_mod_src_to_txt     = 'A/D/H/chi'
+  file_mod_tgt_to_txt     = 'A/D/H/psi'
+  file_mod_none_to_txt    = 'A/D/H/omega'
+  files_bin = [ file_mod_both, file_mod_src, file_mod_tgt, file_mod_none ]
+  files_txt = [ file_mod_both_to_txt, file_mod_src_to_txt,
+                file_mod_tgt_to_txt, file_mod_none_to_txt ]
+  files = files_bin + files_txt
+
+  # make some 'binary' files with keyword expansion enabled
+  for f in files:
+    svntest.main.file_append(sbox.ospath(f), "With $Revision: $ keyword.\n")
+    sbox.simple_propset('svn:mime-type', 'application/octet-stream', f)
+    sbox.simple_propset('svn:keywords', 'Revision', f)
   sbox.simple_commit()
 
-  # branch the file
-  sbox.simple_copy('foo', 'bar')
-  sbox.simple_commit()
+  # branch the files
+  sbox.simple_repo_copy('A', 'A2')
+  sbox.simple_update()
 
-  # modify the branched version (although the bug shows even if we modify
-  # just the original version -- or neither, which is a completely
-  # degenerate 'merge' case)
-  # ### Perhaps a dir merge would behave differently from a single-file merge?
-  svntest.main.file_append('bar', "Line 2.\n")
+  # Modify the branched (source) and/or original (target) versions. Remove
+  # the svn:mime-type from the 'to_txt' files on the branch.
+  # The original bug in issue #4221 gave a conflict if we modified either
+  # version or neither (using a single-file merge test case).
+  for f in [ file_mod_both, file_mod_both_to_txt,
+             file_mod_src, file_mod_src_to_txt ]:
+    f_branch = 'A2' + f[1:]
+    svntest.main.file_append(sbox.ospath(f_branch), "Incoming mod.\n")
+  for f in [ file_mod_both, file_mod_both_to_txt,
+             file_mod_tgt, file_mod_tgt_to_txt ]:
+    svntest.main.file_append(sbox.ospath(f), "Mod on merge target.\n")
+  for f in files_txt:
+    f_branch = 'A2' + f[1:]
+    sbox.simple_propdel('svn:mime-type', f_branch)
   sbox.simple_commit()
+  sbox.simple_update()
 
   # merge back
   svntest.actions.run_and_verify_svn(
     None,
     expected_merge_output([[3,4]],
-                          ['U    foo\n',
-                           ' U   foo\n'],
-                          target='foo'),
-    [], 'merge', '^/bar', 'foo')
+                          ['C    ' + sbox.ospath(file_mod_both) + '\n',
+                           'U    ' + sbox.ospath(file_mod_src) + '\n',
+                          #'     ' + sbox.ospath(file_mod_tgt) + '\n',
+                          #'     ' + sbox.ospath(file_mod_none) + '\n',
+                           'CU   ' + sbox.ospath(file_mod_both_to_txt) + '\n',
+                           'UU   ' + sbox.ospath(file_mod_src_to_txt) + '\n',
+                           ' U   ' + sbox.ospath(file_mod_tgt_to_txt) + '\n',
+                           ' U   ' + sbox.ospath(file_mod_none_to_txt) + '\n',
+                           ' U   A\n'],
+                          text_conflicts=2),
+    [], 'merge', '^/A2', 'A')
 
 #----------------------------------------------------------------------
 # Test for issue #4155 'Merge conflict text of expanded keyword incorrect