You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2010/09/26 20:51:54 UTC

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

Author: dannas
Date: Sun Sep 26 18:51:54 2010
New Revision: 1001493

URL: http://svn.apache.org/viewvc?rev=1001493&view=rev
Log:
Add support for deleting empty files with svn patch.

This only works if the patch file is using the git unidiff extensions.

* subversion/tests/cmdline/patch_tests.py
  (patch_git_add_file): Rename this..
  (patch_git_empty_files): .. To this to reflect that we're now both adding
    and deleting empty files.
  (test_list): Use the new function name.

* subversion/libsvn_client/patch.c
  (init_patch_target): Set the target->deleted to a preliminary TRUE if
    the parser has been able to determine the patch operation, e.g. the
    patch was in the git format. Update a todo comment.
  (apply_patches): For empty deleted files we don't have any text changes
    but still want to apply our patch.

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=1001493&r1=1001492&r2=1001493&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Sun Sep 26 18:51:54 2010
@@ -631,13 +631,16 @@ init_patch_target(patch_target_t **patch
                                                    scratch_pool));
         }
 
-      /* ### Is it ok to set target->added here? Isn't the target supposed to
-       * ### be marked as added after it's been proven that it can be added?
-       * ### One alternative is to include a git_added flag. Or maybe we
-       * ### should have kept the patch field in patch_target_t? Then we
-       * ### could have checked for target->patch->operation == added */
+      /* ### Is it ok to set the operation of the target already here? Isn't
+       * ### the target supposed to be marked with an operation after we have
+       * ### determined that the changes will apply cleanly to the WC? Maybe
+       * ### we should have kept the patch field in patch_target_t to be
+       * ### able to distinguish between 'what the patch says we should do' 
+       * ### and 'what we can do with the given state of our WC'. */
       if (patch->operation == svn_diff_op_added)
         target->added = TRUE;
+      else if (patch->operation == svn_diff_op_deleted)
+        target->deleted = TRUE;
 
       SVN_ERR(svn_stream_open_unique(&patched_raw,
                                      &target->patched_path, NULL,
@@ -2639,7 +2642,9 @@ apply_patches(void *baton,
 
               if (! target->skipped)
                 {
-                  if (target->has_text_changes || target->added)
+                  if (target->has_text_changes 
+                      || target->added 
+                      || target->deleted)
                     SVN_ERR(install_patched_target(target, btn->abs_wc_path,
                                                    btn->ctx, btn->dry_run,
                                                    iterpool));

Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=1001493&r1=1001492&r2=1001493&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Sun Sep 26 18:51:54 2010
@@ -2987,7 +2987,7 @@ def patch_prop_with_fuzz(sbox):
                                        1, # check-props
                                        1) # dry-run
 
-def patch_git_add_file(sbox):
+def patch_git_empty_files(sbox):
   "patch that contains empty files"
 
   sbox.build()
@@ -3001,18 +3001,25 @@ def patch_git_add_file(sbox):
     "===================================================================\n",
     "diff --git a/new b/new\n",
     "new file mode 10644\n",
+    "Index: iota\n",
+    "===================================================================\n",
+    "diff --git a/iota b/iota\n",
+    "deleted file mode 10644\n",
   ]
 
   svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
 
   expected_output = [
     'A         %s\n' % os.path.join(wc_dir, 'new'),
+    'D         %s\n' % os.path.join(wc_dir, 'iota'),
   ]
   expected_disk = svntest.main.greek_state.copy()
   expected_disk.add({'new' : Item(contents="")})
+  expected_disk.remove('iota')
 
   expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
   expected_status.add({'new' : Item(status='A ', wc_rev=0)})
+  expected_status.tweak('iota', status='D ')
 
   expected_skip = wc.State('', { })
 
@@ -3380,7 +3387,7 @@ test_list = [ None,
               patch_add_path_with_props,
               patch_prop_offset,
               patch_prop_with_fuzz,
-              patch_git_add_file,
+              patch_git_empty_files,
               patch_old_target_names,
               patch_reverse_revert,
             ]