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/05/27 15:26:30 UTC

svn commit: r1745765 - in /subversion/trunk/subversion: include/svn_client.h libsvn_client/conflicts.c svn/conflict-callbacks.c

Author: stsp
Date: Fri May 27 15:26:30 2016
New Revision: 1745765

URL: http://svn.apache.org/viewvc?rev=1745765&view=rev
Log:
Add a new conflict resolver option which ignores an incoming deletion.

Update, merge, and switch operations already prepare the working copy for this
resolution choice when flagging the conflict. So this new option is very similar
to accepting the current workng copy state. However, it makes sense to provide
this option seperately because it's an obvious way of phrasing the resolution
approach and mirrors the "ignore incoming addition" option we've already got.

The option also performs some additional sanity checks before resolving to
the current working copy state, so that the user is forced to choose the
"accept current working copy state" option instead if the working copy was
put into some unexpected state since the conflict was flagged.

* subversion/include/svn_client.h
  (svn_client_conflict_option_incoming_delete_ignore): New option ID.
  (resolve_incoming_delete_ignore): New conflict resolution function.
  (configure_option_incoming_delete_ignore): New. Configures the new option.
  (svn_client_conflict_tree_get_resolution_options): Enable the new option.

* subversion/svn/conflict-callbacks.c
  (builtin_resolver_options): Hook up the new option to interactive conflict menu.

Modified:
    subversion/trunk/subversion/include/svn_client.h
    subversion/trunk/subversion/libsvn_client/conflicts.c
    subversion/trunk/subversion/svn/conflict-callbacks.c

Modified: subversion/trunk/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_client.h?rev=1745765&r1=1745764&r2=1745765&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_client.h (original)
+++ subversion/trunk/subversion/include/svn_client.h Fri May 27 15:26:30 2016
@@ -4419,6 +4419,9 @@ typedef enum svn_client_conflict_option_
   svn_client_conflict_option_merge_incoming_added_dir_replace,
   svn_client_conflict_option_merge_incoming_added_dir_replace_and_merge,
 
+  /* Options for incoming delete vs any */
+  svn_client_conflict_option_incoming_delete_ignore,
+
 } svn_client_conflict_option_id_t;
 
 /**

Modified: subversion/trunk/subversion/libsvn_client/conflicts.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/conflicts.c?rev=1745765&r1=1745764&r2=1745765&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/conflicts.c (original)
+++ subversion/trunk/subversion/libsvn_client/conflicts.c Fri May 27 15:26:30 2016
@@ -4419,6 +4419,199 @@ resolve_merge_incoming_added_dir_replace
                                                           scratch_pool));
 }
 
+/* Implements conflict_option_resolve_func_t. */
+static svn_error_t *
+resolve_incoming_delete_ignore(svn_client_conflict_option_t *option,
+                               svn_client_conflict_t *conflict,
+                               apr_pool_t *scratch_pool)
+{
+  svn_client_conflict_option_id_t option_id;
+  const char *local_abspath;
+  const char *lock_abspath;
+  svn_client_ctx_t *ctx = conflict->ctx;
+  svn_wc_operation_t operation;
+  const char *wcroot_abspath;
+  svn_error_t *err;
+
+  option_id = svn_client_conflict_option_get_id(option);
+  local_abspath = svn_client_conflict_get_local_abspath(conflict);
+
+  SVN_ERR(svn_wc__get_wcroot(&wcroot_abspath, ctx->wc_ctx,
+                             local_abspath, scratch_pool,
+                             scratch_pool));
+
+  SVN_ERR(svn_wc__acquire_write_lock_for_resolve(&lock_abspath, ctx->wc_ctx,
+                                                 local_abspath,
+                                                 scratch_pool, scratch_pool));
+
+  /* We assume update/merge/switch operations leave the working copy in a
+   * state which prefers the local change and cancels the deletion.
+   * Run a quick sanity check and error out if it looks as if the
+   * working copy was modified since, even though it's not easy to make
+   * such modifications without also clearing the conflict marker. */
+  operation = svn_client_conflict_get_operation(conflict);
+  if (operation == svn_wc_operation_update || operation == svn_wc_operation_switch)
+    {
+      struct conflict_tree_incoming_delete_details *details;
+      svn_boolean_t is_copy;
+      svn_revnum_t copyfrom_rev;
+      const char *copyfrom_repos_relpath;
+
+      details = conflict->tree_conflict_incoming_details;
+      if (details == NULL)
+        {
+          err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                   _("Conflict resolution option '%d' requires "
+                                     "details for tree conflict at '%s' to be "
+                                     "fetched from the repository."),
+                                  option->id,
+                                  svn_dirent_local_style(local_abspath,
+                                                         scratch_pool));
+          goto unlock_wc;
+        }
+
+      /* Ensure that the item is a copy of itself from before it was deleted.
+       * Update and switch are supposed to set this up when flagging the conflict. */
+      err = svn_wc__node_get_origin(&is_copy, &copyfrom_rev,
+                                    &copyfrom_repos_relpath,
+                                    NULL, NULL, NULL, NULL,
+                                    ctx->wc_ctx, local_abspath, FALSE,
+                                    scratch_pool, scratch_pool);
+      if (err)
+        goto unlock_wc;
+
+      if (!is_copy)
+        err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                _("Cannot resolve tree conflict on '%s' by ignoring "
+                                  "the incoming deletion (expected a copied item, "
+                                  "but the item is not a copy)"),
+                                svn_dirent_local_style(
+                                  svn_dirent_skip_ancestor(wcroot_abspath,
+                                                           conflict->local_abspath),
+                                  scratch_pool));
+      else if (details->deleted_rev == SVN_INVALID_REVNUM &&
+               details->added_rev == SVN_INVALID_REVNUM)
+        err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                _("Could not find the revision in which '%s' was "
+                                  "deleted from the repository"),
+                                svn_dirent_local_style(
+                                  svn_dirent_skip_ancestor(wcroot_abspath,
+                                                           conflict->local_abspath),
+                                  scratch_pool));
+      else if (details->deleted_rev != SVN_INVALID_REVNUM &&
+               copyfrom_rev >= details->deleted_rev)
+        err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                _("Cannot resolve tree conflict on '%s' by "
+                                  "ignoring the incoming deletion (expected an "
+                                  "item copied from a revision smaller than "
+                                  "r%ld, but the item was copied from r%ld)"),
+                                svn_dirent_local_style(
+                                  svn_dirent_skip_ancestor(
+                                    wcroot_abspath, conflict->local_abspath),
+                                  scratch_pool),
+                                details->deleted_rev, copyfrom_rev);
+
+      else if (details->added_rev != SVN_INVALID_REVNUM &&
+               copyfrom_rev < details->added_rev)
+        err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                _("Cannot resolve tree conflict on '%s' by "
+                                  "ignoring the incoming deletion (expected an "
+                                  "item copied from a revision larger than r%ld, "
+                                  "but the item was copied from r%ld)"),
+                                svn_dirent_local_style(
+                                  svn_dirent_skip_ancestor(
+                                    wcroot_abspath, conflict->local_abspath),
+                                  scratch_pool),
+                                 details->added_rev, copyfrom_rev);
+
+      else if (operation == svn_wc_operation_update &&
+               strcmp(copyfrom_repos_relpath, details->repos_relpath) != 0)
+        err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                _("Cannot resolve tree conflict on '%s' by "
+                                  "ignoring the incoming deletion (expected an "
+                                  "item copied from '^/%s', but the item was "
+                                  "copied from '^/%s@%ld')"),
+                                svn_dirent_local_style(
+                                  svn_dirent_skip_ancestor(
+                                    wcroot_abspath, conflict->local_abspath),
+                                  scratch_pool),
+                                details->repos_relpath,
+                                copyfrom_repos_relpath, copyfrom_rev);
+      else if (operation == svn_wc_operation_switch)
+        {
+          const char *old_repos_relpath;
+
+          err = svn_client_conflict_get_incoming_old_repos_location(
+                  &old_repos_relpath, NULL, NULL, conflict,
+                  scratch_pool, scratch_pool);
+          if (err)
+            goto unlock_wc;
+
+          if (strcmp(copyfrom_repos_relpath, old_repos_relpath) != 0)
+            err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                    _("Cannot resolve tree conflict on '%s' by "
+                                      "ignoring the incoming deletion (expected an "
+                                      "item copied from '^/%s', but the item was "
+                                      "copied from '^/%s@%ld')"),
+                                    svn_dirent_local_style(
+                                      svn_dirent_skip_ancestor(
+                                        wcroot_abspath, conflict->local_abspath),
+                                      scratch_pool),
+                                    old_repos_relpath,
+                                    copyfrom_repos_relpath, copyfrom_rev);
+        }
+
+      if (err)
+        goto unlock_wc;
+    }
+  else if (operation == svn_wc_operation_merge)
+    {
+      svn_node_kind_t victim_node_kind;
+      svn_node_kind_t on_disk_kind;
+
+      /* For merge, all we can do is ensure that the item still exists. */
+      victim_node_kind = svn_client_conflict_tree_get_victim_node_kind(conflict);
+      err = svn_io_check_path(local_abspath, &on_disk_kind, scratch_pool);
+      if (err)
+        goto unlock_wc;
+
+      if (victim_node_kind != on_disk_kind)
+          err = svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                                  _("Cannot resolve tree conflict on '%s' by "
+                                    "ignoring the incoming deletion (expected "
+                                    "node kind '%s' but found '%s')"),
+                                  svn_dirent_local_style(
+                                    svn_dirent_skip_ancestor(
+                                      wcroot_abspath, conflict->local_abspath),
+                                    scratch_pool),
+                                  svn_node_kind_to_word(victim_node_kind),
+                                  svn_node_kind_to_word(on_disk_kind));
+      if (err)
+        goto unlock_wc;
+    }
+
+  /* Resolve to the current working copy state. */
+  err = svn_wc__del_tree_conflict(ctx->wc_ctx, local_abspath, scratch_pool);
+
+  /* svn_wc__del_tree_conflict doesn't handle notification for us */
+  if (ctx->notify_func2)
+    ctx->notify_func2(ctx->notify_baton2,
+                      svn_wc_create_notify(local_abspath,
+                                           svn_wc_notify_resolved_tree,
+                                           scratch_pool),
+                      scratch_pool);
+
+unlock_wc:
+  err = svn_error_compose_create(err, svn_wc__release_write_lock(ctx->wc_ctx,
+                                                                 lock_abspath,
+                                                                 scratch_pool));
+  SVN_ERR(err);
+
+  conflict->resolution_tree = option_id;
+
+  return SVN_NO_ERROR;
+}
+
 /* Resolver options for a text conflict */
 static const svn_client_conflict_option_t text_conflict_options[] =
 {
@@ -5162,6 +5355,47 @@ configure_option_merge_incoming_added_di
   return SVN_NO_ERROR;
 }
 
+/* Configure 'incoming delete ignore' resolution option for a tree conflict. */
+static svn_error_t *
+configure_option_incoming_delete_ignore(svn_client_conflict_t *conflict,
+                                        apr_array_header_t *options,
+                                        apr_pool_t *scratch_pool)
+{
+  svn_wc_operation_t operation;
+  svn_wc_conflict_action_t incoming_change;
+  svn_wc_conflict_reason_t local_change;
+  const char *incoming_new_repos_relpath;
+  svn_revnum_t incoming_new_pegrev;
+
+  operation = svn_client_conflict_get_operation(conflict);
+  incoming_change = svn_client_conflict_get_incoming_change(conflict);
+  local_change = svn_client_conflict_get_local_change(conflict);
+  SVN_ERR(svn_client_conflict_get_incoming_new_repos_location(
+            &incoming_new_repos_relpath, &incoming_new_pegrev,
+            NULL, conflict, scratch_pool,
+            scratch_pool));
+
+  if (incoming_change == svn_wc_conflict_action_delete)
+    {
+      svn_client_conflict_option_t *option;
+      const char *wcroot_abspath;
+
+      option = apr_pcalloc(options->pool, sizeof(*option));
+      option->id = svn_client_conflict_option_incoming_delete_ignore;
+      SVN_ERR(svn_wc__get_wcroot(&wcroot_abspath, conflict->ctx->wc_ctx,
+                                 conflict->local_abspath, scratch_pool,
+                                 scratch_pool));
+      option->description =
+        apr_psprintf(options->pool, _("ignore the deletion of '^/%s@%ld'"),
+          incoming_new_repos_relpath, incoming_new_pegrev);
+      option->conflict = conflict;
+      option->do_resolve_func = resolve_incoming_delete_ignore;
+      APR_ARRAY_PUSH(options, const svn_client_conflict_option_t *) = option;
+    }
+
+  return SVN_NO_ERROR;
+}
+
 svn_error_t *
 svn_client_conflict_tree_get_resolution_options(apr_array_header_t **options,
                                                 svn_client_conflict_t *conflict,
@@ -5205,6 +5439,8 @@ svn_client_conflict_tree_get_resolution_
                                                             scratch_pool));
   SVN_ERR(configure_option_merge_incoming_added_dir_replace_and_merge(
             conflict, *options, scratch_pool));
+  SVN_ERR(configure_option_incoming_delete_ignore(conflict, *options,
+                                                  scratch_pool));
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/svn/conflict-callbacks.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/conflict-callbacks.c?rev=1745765&r1=1745764&r2=1745765&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/conflict-callbacks.c (original)
+++ subversion/trunk/subversion/svn/conflict-callbacks.c Fri May 27 15:26:30 2016
@@ -438,6 +438,11 @@ static const resolver_option_t builtin_r
     svn_client_conflict_option_merge_incoming_added_dir_replace },
   { "M", N_("replace my directory with incoming directory and merge"), NULL,
     svn_client_conflict_option_merge_incoming_added_dir_replace_and_merge },
+
+  /* Options for incoming delete vs any. */
+  { "i", N_("ignore incoming deletion"), NULL,
+    svn_client_conflict_option_incoming_delete_ignore },
+
   { NULL }
 };