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/06/15 20:04:21 UTC

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

Author: stsp
Date: Wed Jun 15 20:04:21 2016
New Revision: 1748626

URL: http://svn.apache.org/viewvc?rev=1748626&view=rev
Log:
Add conflict resolver APIs to support ambiguous server-side moves.

Make use of these new APIs in 'svn resolve'.

* subversion/include/svn_client.h
  (svn_client_conflict_option_get_moved_to_repos_relpath_candidates,
   svn_client_conflict_option_set_moved_to_repos_relpath): Declare.
  (svn_client_conflict_option_get_moved_to_abspath_candidates): Update docco.

* subversion/libsvn_client/conflicts.c
  (configure_option_incoming_move_file_merge): Properly handle the result
   of svn_sort__hash().
  (svn_client_conflict_option_get_moved_to_repos_relpath_candidates,
   svn_client_conflict_option_set_moved_to_repos_relpath): New API functions
    which allow overriding the assumed repository destination of a move.

* subversion/svn/conflict-callbacks.c
  (extra_resolver_options): Replace "c" option code with "w" and update this
   menu item's description. Add "d" for repository-side move destinations.
  (build_tree_conflict_options): Return a list of possible repository-side
   move destinations. Track "c" -> "w" option rename.
   Add the "d" option if applicable.
  (prompt_move_target_abspath): Rename to ...
  (prompt_move_target_path): .. this. Add 'paths_are_local' parameter and
   generalize this function to handle both wc and repos move target paths.
  (handle_tree_conflict): Add "d" option handling. Track "c" -> "w" rename.

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=1748626&r1=1748625&r2=1748626&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_client.h (original)
+++ subversion/trunk/subversion/include/svn_client.h Wed Jun 15 20:04:21 2016
@@ -4446,10 +4446,10 @@ svn_client_conflict_option_set_merged_pr
   const svn_string_t *merged_propval);
 
 /**
- * Get a list of possible moved-to abspaths in the working copy which can be
- * applied to the svn_client_conflict_option_incoming_move_file_text_merge
- * resolution @a option. (If a different option is passed in, this function
- * will raise an assertion failure.)
+ * Get a list of possible repository paths which can be applied to the
+ * svn_client_conflict_option_incoming_move_file_text_merge resolution
+ * @a option. (If a different option is passed in, this function will
+ * raise an assertion failure.)
  *
  * In some situations, there can be multiple possible destinations for an
  * incoming move. One such situation is where a file was copied and moved
@@ -4461,7 +4461,45 @@ svn_client_conflict_option_set_merged_pr
  *
  * The array is allocated in @a result_pool and will have "const char *"
  * elements pointing to strings also allocated in @a result_pool.
+ * All paths are relpaths, and relative to the repository root.
+ *
+ * @see svn_client_conflict_option_set_moved_to_repos_relpath()
+ * @since New in 1.10.
+ */
+svn_error_t *
+svn_client_conflict_option_get_moved_to_repos_relpath_candidates(
+  apr_array_header_t **possible_moved_to_repos_relpaths,
+  svn_client_conflict_option_t *option,
+  apr_pool_t *result_pool,
+  apr_pool_t *scratch_pool);
+
+/**
+ * Set the preferred moved target repository path for the
+ * svn_client_conflict_option_incoming_move_file_text_merge resolution option.
+ * 
+ * @a preferred_move_target_idx must be a valid index into the list returned
+ * by svn_client_conflict_option_get_moved_to_repos_relpath_candidates().
+ * 
+ * @since New in 1.10.
+ */
+svn_error_t *
+svn_client_conflict_option_set_moved_to_repos_relpath(
+  svn_client_conflict_option_t *option,
+  int preferred_move_target_idx,
+  apr_pool_t *scratch_pool);
+
+/**
+ * Get a list of possible moved-to abspaths in the working copy which can be
+ * applied to the svn_client_conflict_option_incoming_move_file_text_merge
+ * resolution @a option. (If a different option is passed in, this function
+ * will raise an assertion failure.)
  *
+ * All paths in the returned list correspond to the repository path which
+ * is assumed to be the destination of the incoming move operation.
+ * To support cases where this destination path is ambiguous, the client may
+ * call svn_client_conflict_option_get_moved_to_repos_relpath_candidates()
+ * before calling this function to let the user select a repository path first.
+ * 
  * If no possible moved-to paths can be found, return an empty array.
  * This doesn't mean that no move happened in the repository. It is possible
  * that the move destination is outside the scope of the current working copy,

Modified: subversion/trunk/subversion/libsvn_client/conflicts.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/conflicts.c?rev=1748626&r1=1748625&r2=1748626&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/conflicts.c (original)
+++ subversion/trunk/subversion/libsvn_client/conflicts.c Wed Jun 15 20:04:21 2016
@@ -7104,14 +7104,17 @@ configure_option_incoming_move_file_merg
             }
           if (apr_hash_count(details->wc_move_targets) > 0)
             {
+              svn_sort__item_t item;
+
               /* Initialize to the first possible move target. Hopefully,
                * in most cases there will only be one candidate anyway. */
               move_target_repos_relpaths = 
                 svn_sort__hash(details->wc_move_targets,
                                svn_sort_compare_items_as_paths,
                                scratch_pool);
-              details->move_target_repos_relpath =
-                APR_ARRAY_IDX(move_target_repos_relpaths, 0, const char *);
+              item = APR_ARRAY_IDX(move_target_repos_relpaths, 0,
+                                   svn_sort__item_t);
+              details->move_target_repos_relpath = item.key;
               details->wc_move_target_idx = 0;
             }
           else
@@ -7149,6 +7152,121 @@ configure_option_incoming_move_file_merg
 }
 
 svn_error_t *
+svn_client_conflict_option_get_moved_to_repos_relpath_candidates(
+  apr_array_header_t **possible_moved_to_repos_relpaths,
+  svn_client_conflict_option_t *option,
+  apr_pool_t *result_pool,
+  apr_pool_t *scratch_pool)
+{
+  svn_client_conflict_t *conflict = option->conflict;
+  struct conflict_tree_incoming_delete_details *details;
+  const char *victim_abspath;
+  apr_array_header_t *sorted_repos_relpaths;
+  int i;
+
+  SVN_ERR_ASSERT(svn_client_conflict_option_get_id(option) ==
+                 svn_client_conflict_option_incoming_move_file_text_merge);
+
+  victim_abspath = svn_client_conflict_get_local_abspath(conflict);
+  details = conflict->tree_conflict_incoming_details;
+  if (details == NULL || details->wc_move_targets == NULL)
+    return svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                             _("Getting a list of possible move targets "
+                               "requires details for tree conflict at '%s' "
+                               "to be fetched from the repository first"),
+                            svn_dirent_local_style(victim_abspath,
+                                                   scratch_pool));
+
+  /* Return a copy of the repos replath candidate list. */
+  sorted_repos_relpaths = svn_sort__hash(details->wc_move_targets,
+                                         svn_sort_compare_items_as_paths,
+                                         scratch_pool);
+
+  *possible_moved_to_repos_relpaths = apr_array_make(
+                                        result_pool,
+                                        sorted_repos_relpaths->nelts,
+                                        sizeof (const char *));
+  for (i = 0; i < sorted_repos_relpaths->nelts; i++)
+    {
+      svn_sort__item_t item;
+      const char *repos_relpath;
+
+      item = APR_ARRAY_IDX(sorted_repos_relpaths, i, svn_sort__item_t);
+      repos_relpath = item.key;
+      APR_ARRAY_PUSH(*possible_moved_to_repos_relpaths, const char *) =
+        apr_pstrdup(result_pool, repos_relpath);
+    }
+
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_client_conflict_option_set_moved_to_repos_relpath(
+  svn_client_conflict_option_t *option,
+  int preferred_move_target_idx,
+  apr_pool_t *scratch_pool)
+{
+  svn_client_conflict_t *conflict = option->conflict;
+  struct conflict_tree_incoming_delete_details *details;
+  const char *victim_abspath;
+  apr_array_header_t *move_target_repos_relpaths;
+  svn_sort__item_t item;
+  const char *move_target_repos_relpath;
+  apr_hash_index_t *hi;
+
+  SVN_ERR_ASSERT(svn_client_conflict_option_get_id(option) ==
+                 svn_client_conflict_option_incoming_move_file_text_merge);
+
+  victim_abspath = svn_client_conflict_get_local_abspath(conflict);
+  details = conflict->tree_conflict_incoming_details;
+  if (details == NULL || details->wc_move_targets == NULL)
+    return svn_error_createf(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
+                             _("Setting a move target requires details "
+                               "for tree conflict at '%s' to be fetched "
+                               "from the repository first"),
+                            svn_dirent_local_style(victim_abspath,
+                                                   scratch_pool));
+
+  if (preferred_move_target_idx < 0 ||
+      preferred_move_target_idx >= apr_hash_count(details->wc_move_targets))
+    return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                             _("Index '%d' is out of bounds of the possible "
+                               "move target list for '%s'"),
+                            preferred_move_target_idx,
+                            svn_dirent_local_style(victim_abspath,
+                                                   scratch_pool));
+
+  /* Translate the index back into a hash table key. */
+  move_target_repos_relpaths =
+    svn_sort__hash(details->wc_move_targets,
+                   svn_sort_compare_items_as_paths,
+                   scratch_pool);
+  item = APR_ARRAY_IDX(move_target_repos_relpaths, preferred_move_target_idx,
+                       svn_sort__item_t);
+  move_target_repos_relpath = item.key;
+  /* Find our copy of the hash key and remember the user's preference. */
+  for (hi = apr_hash_first(scratch_pool, details->wc_move_targets);
+       hi != NULL;
+       hi = apr_hash_next(hi))
+    {
+      const char *repos_relpath = apr_hash_this_key(hi);
+
+      if (strcmp(move_target_repos_relpath, repos_relpath) == 0)
+        {
+          details->move_target_repos_relpath = repos_relpath;
+          return SVN_NO_ERROR;
+        }
+    }
+
+  return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                           _("Repository path '%s' not found in list of "
+                             "possible move targets for '%s'"),
+                           move_target_repos_relpath,
+                           svn_dirent_local_style(victim_abspath,
+                                                  scratch_pool));
+}
+
+svn_error_t *
 svn_client_conflict_option_get_moved_to_abspath_candidates(
   apr_array_header_t **possible_moved_to_abspaths,
   svn_client_conflict_option_t *option,

Modified: subversion/trunk/subversion/svn/conflict-callbacks.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/conflict-callbacks.c?rev=1748626&r1=1748625&r2=1748626&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/conflict-callbacks.c (original)
+++ subversion/trunk/subversion/svn/conflict-callbacks.c Wed Jun 15 20:04:21 2016
@@ -511,8 +511,12 @@ static const resolver_option_t extra_res
 {
   /* Translators: keep long_desc below 70 characters (wrap with a left
      margin of 9 spaces if needed) */
-  { "c",  N_("choose move destination"),
-          N_("choose a move target path from a list of possible targets"),
+  { "d",  N_("set repository move destination path"),
+          N_("pick repository move target from list of possible targets"),
+                                  svn_client_conflict_option_undefined },
+
+  { "w",  N_("set working copy move destination path"),
+          N_("pick working copy move target from list of possible targets"),
                                   svn_client_conflict_option_undefined },
 
   { "h",  N_("help"),             N_("show this help (also '?')"),
@@ -1422,11 +1426,13 @@ handle_prop_conflicts(svn_boolean_t *res
 
 /* Set *OPTIONS to an array of resolution options for CONFLICT. */
 static svn_error_t *
-build_tree_conflict_options(resolver_option_t **options,
-                            apr_array_header_t **possible_moved_to_abspaths,
-                            svn_client_conflict_t *conflict,
-                            apr_pool_t *result_pool,
-                            apr_pool_t *scratch_pool)
+build_tree_conflict_options(
+  resolver_option_t **options,
+  apr_array_header_t **possible_moved_to_repos_relpaths,
+  apr_array_header_t **possible_moved_to_abspaths,
+  svn_client_conflict_t *conflict,
+  apr_pool_t *result_pool,
+  apr_pool_t *scratch_pool)
 {
   resolver_option_t *opt;
   const resolver_option_t *o;
@@ -1443,6 +1449,7 @@ build_tree_conflict_options(resolver_opt
            ARRAY_LEN(extra_resolver_options);
   *options = apr_pcalloc(result_pool, sizeof(*opt) * (nopt + 1));
   *possible_moved_to_abspaths = NULL;
+  *possible_moved_to_repos_relpaths = NULL;
 
   opt = *options;
   iterpool = svn_pool_create(scratch_pool);
@@ -1472,18 +1479,28 @@ build_tree_conflict_options(resolver_opt
       opt++; 
 
       if (id == svn_client_conflict_option_incoming_move_file_text_merge)
-        SVN_ERR(svn_client_conflict_option_get_moved_to_abspath_candidates(
-                  possible_moved_to_abspaths, builtin_option,
-                  result_pool, iterpool));
+        {
+          SVN_ERR(
+            svn_client_conflict_option_get_moved_to_repos_relpath_candidates(
+              possible_moved_to_repos_relpaths, builtin_option,
+              result_pool, iterpool));
+          SVN_ERR(svn_client_conflict_option_get_moved_to_abspath_candidates(
+                    possible_moved_to_abspaths, builtin_option,
+                    result_pool, iterpool));
+        }
     }
 
   svn_pool_destroy(iterpool);
 
   for (o = extra_resolver_options_tree; o->code; o++)
     {
-      /* Add the move target choice option only if there are multiple
+      /* Add move target choice options only if there are multiple
        * move targets to choose from. */
-      if (strcmp(o->code, "c") == 0 &&
+      if (strcmp(o->code, "d") == 0 &&
+          (*possible_moved_to_repos_relpaths == NULL || 
+           (*possible_moved_to_repos_relpaths)->nelts <= 1))
+        continue;
+      if (strcmp(o->code, "w") == 0 &&
           (*possible_moved_to_abspaths == NULL || 
            (*possible_moved_to_abspaths)->nelts <= 1))
         continue;
@@ -1498,12 +1515,13 @@ build_tree_conflict_options(resolver_opt
 
 /* Make the user select a move target path for the moved-away VICTIM_ABSPATH. */
 static svn_error_t *
-prompt_move_target_abspath(int *preferred_move_target_idx,
-                           apr_array_header_t *possible_moved_to_abspaths,
-                           svn_cmdline_prompt_baton_t *pb,
-                           const char *victim_abspath,
-                           svn_client_ctx_t *ctx,
-                           apr_pool_t *scratch_pool)
+prompt_move_target_path(int *preferred_move_target_idx,
+                        apr_array_header_t *possible_moved_to_paths,
+                        svn_boolean_t paths_are_local,
+                        svn_cmdline_prompt_baton_t *pb,
+                        const char *victim_abspath,
+                        svn_client_ctx_t *ctx,
+                        apr_pool_t *scratch_pool)
 {
   const char *move_targets_prompt = "";
   const char *move_targets_list = "";
@@ -1521,26 +1539,52 @@ prompt_move_target_abspath(int *preferre
   iterpool = svn_pool_create(scratch_pool);
 
   /* Build the prompt. */
-  for (i = 0; i < possible_moved_to_abspaths->nelts; i++)
+  for (i = 0; i < possible_moved_to_paths->nelts; i++)
     {
-      const char *moved_to_abspath;
-      const char *moved_to_relpath;
-
       svn_pool_clear(iterpool);
 
-      moved_to_abspath = APR_ARRAY_IDX(possible_moved_to_abspaths, i,
-                                       const char *);
-      moved_to_relpath = svn_cl__local_style_skip_ancestor(
-                           wcroot_abspath, moved_to_abspath, iterpool),
-      move_targets_list = apr_psprintf(scratch_pool, "%s (%d): %s\n",
-                                       move_targets_list, i + 1,
-                                       moved_to_relpath);
-    }
-  move_targets_prompt =
-    apr_psprintf(scratch_pool,
-                 _("Possible destinations for moved-away '%s' are:\n%s"
-                   "Select a move target path by number: "),
-                 victim_relpath, move_targets_list);
+      if (paths_are_local)
+        {
+          const char *moved_to_abspath;
+          const char *moved_to_relpath;
+
+          moved_to_abspath = APR_ARRAY_IDX(possible_moved_to_paths, i,
+                                           const char *);
+          moved_to_relpath = svn_cl__local_style_skip_ancestor(
+                               wcroot_abspath, moved_to_abspath, iterpool),
+          move_targets_list = apr_psprintf(scratch_pool, "%s (%d): '%s'\n",
+                                           move_targets_list, i + 1,
+                                           moved_to_relpath);
+        }
+      else
+        {
+          const char *moved_to_repos_relpath;
+
+          moved_to_repos_relpath = APR_ARRAY_IDX(possible_moved_to_paths, i,
+                                                 const char *);
+          move_targets_list = apr_psprintf(scratch_pool, "%s (%d): '^/%s'\n",
+                                           move_targets_list, i + 1,
+                                           moved_to_repos_relpath);
+        }
+    }
+  if (paths_are_local)
+    move_targets_prompt =
+      apr_psprintf(scratch_pool,
+                   _("Possible working copy destinations for moved-away '%s' "
+                     "are:\n%s"
+                     "Only one destination can be a move; the others are "
+                     "copies.\n"
+                     "Specify the correct move target path by number: "),
+                   victim_relpath, move_targets_list);
+  else
+    move_targets_prompt =
+      apr_psprintf(scratch_pool,
+                   _("Possible repository destinations for moved-away '%s' "
+                     "are:\n%s"
+                     "Only one destination can be a move; the others are "
+                     "copies.\n"
+                     "Specify the correct move target path by number: "),
+                   victim_relpath, move_targets_list);
 
   /* Keep asking the user until we got a valid choice. */
   while (1)
@@ -1553,7 +1597,7 @@ prompt_move_target_abspath(int *preferre
       SVN_ERR(svn_cmdline_prompt_user2(&answer, move_targets_prompt,
                                        pb, iterpool));
       err = svn_cstring_strtoi64(&idx, answer, 1,
-                                 possible_moved_to_abspaths->nelts, 10);
+                                 possible_moved_to_paths->nelts, 10);
       if (err)
         {
           char buf[1024];
@@ -1595,6 +1639,7 @@ handle_tree_conflict(svn_boolean_t *reso
   const char *conflict_description;
   const char *local_change_description;
   const char *incoming_change_description;
+  apr_array_header_t *possible_moved_to_repos_relpaths;
   apr_array_header_t *possible_moved_to_abspaths;
 
   option_id = svn_client_conflict_option_unspecified;
@@ -1617,6 +1662,7 @@ handle_tree_conflict(svn_boolean_t *reso
                                 conflict_description));
 
   SVN_ERR(build_tree_conflict_options(&tree_conflict_options,
+                                      &possible_moved_to_repos_relpaths,
                                       &possible_moved_to_abspaths,
                                       conflict, scratch_pool, scratch_pool));
   iterpool = svn_pool_create(scratch_pool);
@@ -1638,15 +1684,16 @@ handle_tree_conflict(svn_boolean_t *reso
           *quit = TRUE;
           break;
         }
-      else if (strcmp(opt->code, "c") == 0)
+      else if (strcmp(opt->code, "d") == 0)
         {
           int preferred_move_target_idx;
           apr_array_header_t *options;
           svn_client_conflict_option_t *conflict_option;
 
-          SVN_ERR(prompt_move_target_abspath(&preferred_move_target_idx,
-                                             possible_moved_to_abspaths, pb,
-                                             local_abspath, ctx, iterpool));
+          SVN_ERR(prompt_move_target_path(&preferred_move_target_idx,
+                                          possible_moved_to_repos_relpaths,
+                                          FALSE,
+                                          pb, local_abspath, ctx, iterpool));
 
           /* Update preferred move target path. */
           SVN_ERR(svn_client_conflict_tree_get_resolution_options(&options,
@@ -1659,17 +1706,53 @@ handle_tree_conflict(svn_boolean_t *reso
               svn_client_conflict_option_incoming_move_file_text_merge);
           if (conflict_option)
             {
-              SVN_ERR(svn_client_conflict_option_set_moved_to_abspath(
+              SVN_ERR(svn_client_conflict_option_set_moved_to_repos_relpath(
                         conflict_option, preferred_move_target_idx, iterpool));
 
               /* Update option description. */
-              SVN_ERR(build_tree_conflict_options(&tree_conflict_options,
-                                                  &possible_moved_to_abspaths,
-                                                  conflict,
+              SVN_ERR(build_tree_conflict_options(
+                        &tree_conflict_options,
+                        &possible_moved_to_repos_relpaths,
+                        &possible_moved_to_abspaths,
+                        conflict,
                                                   scratch_pool, scratch_pool));
             }
           continue;
         }
+      else if (strcmp(opt->code, "w") == 0)
+        {
+          int preferred_move_target_idx;
+          apr_array_header_t *options;
+          svn_client_conflict_option_t *conflict_option;
+
+          SVN_ERR(prompt_move_target_path(&preferred_move_target_idx,
+                                           possible_moved_to_abspaths, TRUE,
+                                           pb, local_abspath, ctx, iterpool));
+
+          /* Update preferred move target path. */
+          SVN_ERR(svn_client_conflict_tree_get_resolution_options(&options,
+                                                                  conflict,
+                                                                  iterpool,
+                                                                  iterpool));
+          conflict_option =
+            svn_client_conflict_option_find_by_id( 
+              options,
+              svn_client_conflict_option_incoming_move_file_text_merge);
+          if (conflict_option)
+            {
+              SVN_ERR(svn_client_conflict_option_set_moved_to_abspath(
+                        conflict_option, preferred_move_target_idx, iterpool));
+
+              /* Update option description. */
+              SVN_ERR(build_tree_conflict_options(
+                        &tree_conflict_options,
+                        &possible_moved_to_repos_relpaths,
+                        &possible_moved_to_abspaths,
+                        conflict,
+                        scratch_pool, scratch_pool));
+            }
+          continue;
+        }
       else if (opt->choice != svn_client_conflict_option_undefined)
         {
           option_id = opt->choice;