You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2015/09/30 13:35:05 UTC

svn commit: r1706005 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Author: rhuijben
Date: Wed Sep 30 11:35:04 2015
New Revision: 1706005

URL: http://svn.apache.org/viewvc?rev=1706005&view=rev
Log:
Don't create new files in 'svn patch' when a (git style) diff describes that
an existing target should only be modified.

* subversion/libsvn_client/patch.c
  (apply_one_patch,
   install_patched_prop_targets): Stop creating files for explicit
     modifications.

* subversion/tests/cmdline/patch_tests.py
  (patch_adds_executability_nocontents2): Remove XFail. Fix expectations.
  (patch_empty_vs_delete): Extend test.

Modified:
    subversion/trunk/subversion/libsvn_client/patch.c
    subversion/trunk/subversion/tests/cmdline/patch_tests.py

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1706005&r1=1706004&r2=1706005&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Wed Sep 30 11:35:04 2015
@@ -2759,7 +2759,8 @@ apply_one_patch(patch_target_t **patch_t
             target->skipped = TRUE;
           }
         }
-      else if (patched_file.size > 0 && working_file.size == 0)
+      else if (patched_file.size > 0 && working_file.size == 0
+               && patch->operation == svn_diff_op_unchanged)
         {
           /* The patch has created a file. */
           if (target->locally_deleted)
@@ -3155,29 +3156,48 @@ install_patched_prop_targets(patch_targe
           continue;
         }
 
+
       /* If the patch target doesn't exist yet, the patch wants to add an
        * empty file with properties set on it. So create an empty file and
        * add it to version control. But if the patch was in the 'git format'
        * then the file has already been added.
        *
-       * ### How can we tell whether the patch really wanted to create
-       * ### an empty directory? */
-      if (! target->has_text_changes
-          && target->kind_on_disk == svn_node_none
-          && ! target->added)
+       * We only do this if the patch file didn't set an explicit operation.
+       *
+       * If there are text changes then we already handled these cases when
+       * constructing the patched file.
+       */
+      if (target->operation == svn_diff_op_unchanged
+          && !target->has_text_changes)
         {
-          if (! dry_run)
+          if (target->kind_on_disk == svn_node_none
+              && ! target->added
+              && ! target->replaced)
             {
-              SVN_ERR(svn_io_file_create_empty(target->local_abspath,
-                                               scratch_pool));
-              SVN_ERR(svn_wc_add_from_disk3(ctx->wc_ctx, target->local_abspath,
-                                            NULL /*props*/,
-                                            FALSE /* skip checks */,
-                                            /* suppress notification */
-                                            NULL, NULL,
-                                            iterpool));
+              if (! dry_run)
+                {
+                  SVN_ERR(svn_io_file_create_empty(target->local_abspath,
+                                                   scratch_pool));
+                  SVN_ERR(svn_wc_add_from_disk3(ctx->wc_ctx, target->local_abspath,
+                                                NULL /*props*/,
+                                                FALSE /* skip checks */,
+                                                /* suppress notification */
+                                                NULL, NULL,
+                                                iterpool));
+                }
+              if (target->locally_deleted)
+                target->replaced = TRUE;
+              else
+                target->added = TRUE;
             }
-          target->added = TRUE;
+        }
+      
+      if (target->kind_on_disk == svn_node_none
+          && !target->added
+          && !target->replaced)
+        {
+          target->skipped = TRUE;
+          break;
         }
 
       /* Attempt to set the property, and reject all hunks if this

Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=1706005&r1=1706004&r2=1706005&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Wed Sep 30 11:35:04 2015
@@ -6006,7 +6006,6 @@ def patch_adds_executability_nocontents(
                                        expected_status, expected_skip,
                                        [], True, True, '--reverse-diff')
 
-@XFail()
 def patch_adds_executability_nocontents2(sbox):
   "patch adds svn:executable, without contents 2"
 
@@ -6025,10 +6024,9 @@ def patch_adds_executability_nocontents2
   })
   expected_disk = svntest.main.greek_state.copy()
   expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
-  expected_status.tweak('iota', status=' M')
 
   expected_skip = wc.State(wc_dir, {
-    'new' : Item(verb='Skipped')
+    'new' : Item(verb='Skipped missing target')
   })
 
   # This creates 'new', while a skip or reject is expected
@@ -6492,6 +6490,52 @@ def patch_empty_vs_delete(sbox):
                                        expected_status, expected_skip,
                                        [], True, True)
 
+  # # Not needed. Result of previous test
+  #svntest.actions.run_and_verify_svn(None, [],
+  #                                   'rm', '--force', sbox.ospath('iota'))
+
+  # Ok, and now let's check what happens on reverse diffs with nothing
+  # there
+
+  # Git empty patch -> skip... target not found
+  expect_no_output = svntest.wc.State(wc_dir, {})
+  expect_skip_iota = svntest.wc.State(wc_dir, {
+    'iota' : Item(verb='Skipped')
+  })
+  svntest.actions.run_and_verify_patch(wc_dir, empty_git_patch,
+                                       expect_no_output, expected_disk,
+                                       expected_status, expect_skip_iota,
+                                       [], True, True,
+                                       '--reverse-diff')
+
+  # # Not needed. Result of previous test
+  #svntest.actions.run_and_verify_svn(None, [],
+  #                                   'rm', '--force', sbox.ospath('iota'))
+
+  # Unified empty patch -> Create iota
+  expected_output.tweak('iota', status='A ')
+  expected_status.tweak('iota', status='R ')
+  expected_disk.add({
+    'iota' : Item(contents="This is the file 'iota'.\n")
+  })
+  svntest.actions.run_and_verify_patch(wc_dir, empty_patch,
+                                       expected_output, expected_disk,
+                                       expected_status, expected_skip,
+                                       [], True, True,
+                                       '--strip', strip_count,
+                                       '--reverse-diff')
+  # And retry
+  expected_output.tweak('iota', status='G ')
+  svntest.actions.run_and_verify_patch(wc_dir, empty_patch,
+                                       expected_output, expected_disk,
+                                       expected_status, expected_skip,
+                                       [], True, True,
+                                       '--strip', strip_count,
+                                       '--reverse-diff')
+
+  svntest.actions.run_and_verify_svn(None, [],
+                                     'rm', '--force', sbox.ospath('iota'))
+
 ########################################################################
 #Run the tests