You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2016/01/21 14:51:26 UTC

svn commit: r1725948 - /subversion/trunk/subversion/libsvn_client/patch.c

Author: stsp
Date: Thu Jan 21 13:51:26 2016
New Revision: 1725948

URL: http://svn.apache.org/viewvc?rev=1725948&view=rev
Log:
Improve the behaviour of 'svn patch' when a reject file cannot be created.

* subversion/libsvn_client/patch.c
  (write_out_rejected_hunks): Add 'root_abspath' argument. If the reject
   file cannot be created because an intermediate directory is missing,
   try to create the reject file in the working copy root instead.
   Previously, this was a fatal error condition and aborted patching.
   This problem can happen when trying to apply a patch to the wrong directory.
  (apply_patches): Pass root_abspath to write_out_rejected_hunks().

Modified:
    subversion/trunk/subversion/libsvn_client/patch.c

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1725948&r1=1725947&r2=1725948&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Thu Jan 21 13:51:26 2016
@@ -3305,6 +3305,7 @@ install_patched_target(patch_target_t *t
  */
 static svn_error_t *
 write_out_rejected_hunks(patch_target_t *target,
+                         const char *root_abspath,
                          svn_boolean_t dry_run,
                          apr_pool_t *scratch_pool)
 {
@@ -3312,17 +3313,33 @@ write_out_rejected_hunks(patch_target_t
     {
       /* Write out rejected hunks, if any. */
       apr_file_t *reject_file;
+      svn_error_t *err;
 
-      SVN_ERR(svn_io_open_uniquely_named(&reject_file, NULL,
-                                         svn_dirent_dirname(
-                                              target->local_abspath,
-                                              scratch_pool),
-                                         svn_dirent_basename(
-                                              target->local_abspath,
-                                              NULL),
-                                         ".svnpatch.rej",
-                                         svn_io_file_del_none,
-                                         scratch_pool, scratch_pool));
+      err = svn_io_open_uniquely_named(&reject_file, NULL,
+                                       svn_dirent_dirname(target->local_abspath,
+                                                          scratch_pool),
+                                       svn_dirent_basename(
+                                         target->local_abspath,
+                                         NULL),
+                                       ".svnpatch.rej",
+                                       svn_io_file_del_none,
+                                       scratch_pool, scratch_pool);
+      if (err && APR_STATUS_IS_ENOENT(err->apr_err))
+        {
+          /* The hunk applies to a file in a directory which does not exist.
+           * Put the reject file into the working copy root instead. */
+          svn_error_clear(err);
+          SVN_ERR(svn_io_open_uniquely_named(&reject_file, NULL,
+                                             root_abspath,
+                                             svn_dirent_basename(
+                                               target->local_abspath,
+                                               NULL),
+                                             ".svnpatch.rej",
+                                             svn_io_file_del_none,
+                                             scratch_pool, scratch_pool));
+        }
+      else
+        SVN_ERR(err);
 
       SVN_ERR(svn_stream_reset(target->reject_stream));
 
@@ -3678,7 +3695,8 @@ apply_patches(/* The path to the patch f
                     SVN_ERR(install_patched_prop_targets(target, ctx,
                                                          dry_run, iterpool));
 
-                  SVN_ERR(write_out_rejected_hunks(target, dry_run, iterpool));
+                  SVN_ERR(write_out_rejected_hunks(target, root_abspath,
+                                                   dry_run, iterpool));
 
                   APR_ARRAY_PUSH(targets_info,
                                  patch_target_info_t *) = target_info;