Author: cmpilato
Date: Fri Oct 22 20:10:36 2010
New Revision: 1026475

URL: http://svn.apache.org/viewvc?rev=1026475&view=rev
Log:
Add an 'svn relocate' first-class subcommand.  For too long has relocate
functionality has been awkwardly tacked onto the back of 'svn switch'.

* subversion/svn/cl.h
  (svn_cl__relocate): New function.

* subversion/svn/main.c
  (svn_cl__cmd_table): Add 'relocate' subcommand entry.  Note that
    'svn switch --relocate' is deprecated.

* subversion/svn/relocate-cmd.c
  New file, implementing svn_cl__relocate().

* subversion/tests/cmdline/getopt_tests_data/svn--help_stdout,
* subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout,
* subversion/tests/cmdline/getopt_tests_data/svn_help_stdout
  Update expected test output.

* subversion/tests/cmdline/basic_tests.py
  (basic_relocate): Expand to tickle the new subcommand.

Added:
    subversion/trunk/subversion/svn/relocate-cmd.c   (with props)
Modified:
    subversion/trunk/subversion/svn/cl.h
    subversion/trunk/subversion/svn/main.c
    subversion/trunk/subversion/tests/cmdline/basic_tests.py
    subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn--help_stdout
    
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout
    subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_stdout

Modified: subversion/trunk/subversion/svn/cl.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/cl.h?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/cl.h (original)
+++ subversion/trunk/subversion/svn/cl.h Fri Oct 22 20:10:36 2010
@@ -270,6 +270,7 @@ svn_opt_subcommand_t
   svn_cl__propget,
   svn_cl__proplist,
   svn_cl__propset,
+  svn_cl__relocate,
   svn_cl__revert,
   svn_cl__resolve,
   svn_cl__resolved,

Modified: subversion/trunk/subversion/svn/main.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/main.c?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/main.c (original)
+++ subversion/trunk/subversion/svn/main.c Fri Oct 22 20:10:36 2010
@@ -999,6 +999,29 @@ const svn_opt_subcommand_desc2_t svn_cl_
      opt_force, opt_changelist },
     {{'F', N_("read property value from file ARG")}} },
 
+  { "relocate", svn_cl__relocate, {0}, N_
+    ("Relocate the working copy to point to a different URL.\n"
+     "usage: 1. relocate FROM-PREFIX TO-PREFIX [PATH...]\n"
+     "       2. relocate TO-URL [PATH]\n"
+     "\n"
+     "  Rewrite working copy URL metadata to reflect a syntactic change 
only.\n"
+     "  This is used when repository's root URL changes (such as a scheme\n"
+     "  or hostname change) but your working copy still reflects the same\n"
+     "  directory within the same repository.\n"
+     "\n"
+     "  1. FROM-PREFIX and TO-PREFIX are initial substrings of the working\n"
+     "     copy's current and new URLs, respectively.  (You may specify the\n"
+     "     complete old and new URLs if you wish.)  Use 'svn info' to 
determine\n"
+     "     the current working copy URL.\n"
+     "\n"
+     "  2. TO-URL is the (complete) new repository URL to use for for PATH.\n"
+     "\n"
+     "  Examples:\n"
+     "    svn relocate http:// svn:// project1 project2\n"
+     "    svn relocate http://www.example.com/repo/project \\\n"
+     "                 svn://svn.example.com/repo/project\n"),
+    {0} },
+
   { "resolve", svn_cl__resolve, {0}, N_
     ("Resolve conflicts on working copy files or directories.\n"
      "usage: resolve --accept=ARG [PATH...]\n"
@@ -1152,10 +1175,13 @@ const svn_opt_subcommand_desc2_t svn_cl_
      "     This is used when a repository's root URL changes (such as a 
scheme\n"
      "     or hostname change) but your working copy still reflects the same\n"
      "     directory within the same repository.  FROM-PREFIX and TO-PREFIX 
are\n"
-     "     initial substrings of the working copy's current and new root 
URLs,\n"
-     "     respectively.  (You may specify the complete old and new root URLs 
if\n"
-     "     you wish.)  Use 'svn info' to determine the current repository 
root\n"
-     "     URL of the working copy.\n"
+     "     initial substrings of the working copy's current and new URLs,\n"
+     "     respectively.  (You may specify the complete old and new URLs if 
you\n"
+     "     wish.)  Use 'svn info' to determine the current working copy URL.\n"
+     "\n"
+     "     Note: This syntax form -- in fact, the use of the --relocate 
option\n"
+     "           in general -- has been deprecated in favor of running\n"
+     "           'svn relocate FROM-PREFIX TO-PREFIX [PATH]'.\n"
      "\n"
      "  See also 'svn help update' for a list of possible characters\n"
      "  reporting the action taken.\n"

Added: subversion/trunk/subversion/svn/relocate-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/relocate-cmd.c?rev=1026475&view=auto
==============================================================================
--- subversion/trunk/subversion/svn/relocate-cmd.c (added)
+++ subversion/trunk/subversion/svn/relocate-cmd.c Fri Oct 22 20:10:36 2010
@@ -0,0 +1,108 @@
+/*
+ * relocate-cmd.c -- Update working tree administrative data to
+ *                   account for repository change-of-address.
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+
+/* ==================================================================== */
+
+
+
+/*** Includes. ***/
+
+#include "svn_wc.h"
+#include "svn_client.h"
+#include "svn_dirent_uri.h"
+#include "svn_path.h"
+#include "svn_error.h"
+#include "svn_pools.h"
+#include "cl.h"
+
+#include "svn_private_config.h"
+
+/*** Code. ***/
+
+/* This implements the `svn_opt_subcommand_t' interface. */
+svn_error_t *
+svn_cl__relocate(apr_getopt_t *os,
+                 void *baton,
+                 apr_pool_t *scratch_pool)
+{
+  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
+  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
+  apr_array_header_t *targets;
+  const char *from = NULL, *to = NULL, *path;
+
+  /* We've got two different syntaxes to support:
+
+     1. relocate FROM-PREFIX TO-PREFIX [PATH ...]
+     2. relocate TO-URL [PATH]
+  */
+  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
+                                                      opt_state->targets,
+                                                      ctx, scratch_pool));
+  if (targets->nelts < 1)
+    return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
+
+  /* If we have a single target, we're in form #2.  If we have two
+     targets and the first is a URL and the second is not, we're also
+     in form #2.  */
+  if ((targets->nelts == 1) ||
+      ((targets->nelts == 2)
+       && (svn_path_is_url(APR_ARRAY_IDX(targets, 0, const char *)))
+       && (! svn_path_is_url(APR_ARRAY_IDX(targets, 1, const char *)))))
+
+    {
+      to = APR_ARRAY_IDX(targets, 0, const char *);
+      path = (targets->nelts == 2) ? APR_ARRAY_IDX(targets, 1, const char *)
+                                   : "";
+
+      SVN_ERR(svn_client_url_from_path2(&from, path, ctx,
+                                        scratch_pool, scratch_pool));
+      SVN_ERR(svn_client_relocate2(path, from, to, ctx, scratch_pool));
+    }
+  /* ... Everything else is form #1. */
+  else
+    {
+      from = APR_ARRAY_IDX(targets, 0, const char *);
+      to = APR_ARRAY_IDX(targets, 1, const char *);
+
+      if (targets->nelts == 2)
+        {
+          SVN_ERR(svn_client_relocate2("", from, to, ctx, scratch_pool));
+        }
+      else
+        {
+          apr_pool_t *subpool = svn_pool_create(scratch_pool);
+          int i;
+
+          for (i = 2; i < targets->nelts; i++)
+            {
+              svn_pool_clear(subpool);
+              path = APR_ARRAY_IDX(targets, i, const char *);
+              SVN_ERR(svn_client_relocate2(path, from, to, ctx, subpool));
+            }
+          svn_pool_destroy(subpool);
+        }
+    }
+
+  return SVN_NO_ERROR;
+}

Propchange: subversion/trunk/subversion/svn/relocate-cmd.c
------------------------------------------------------------------------------
    svn:mime-type = text/x-csrc

Modified: subversion/trunk/subversion/tests/cmdline/basic_tests.py
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/basic_tests.py?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/basic_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/basic_tests.py Fri Oct 22 
20:10:36 2010
@@ -2633,6 +2633,17 @@ def basic_relocate(sbox):
                                      repo_url, other_repo_url, wc_dir)
   _verify_url(wc_dir, other_repo_url)
 
+  # ... and back again, using the newer 'svn relocate' subcommand.
+  svntest.actions.run_and_verify_svn(None, None, [], 'relocate',
+                                     other_repo_url, repo_url, wc_dir)
+  _verify_url(wc_dir, repo_url)
+
+  # To OTHER_REPO_URL again, this time with the single-URL form of
+  # 'svn relocate'.
+  svntest.actions.run_and_verify_svn(None, None, [], 'relocate',
+                                     other_repo_url, wc_dir)
+  _verify_url(wc_dir, other_repo_url)
+
   ### TODO: When testing ra_dav or ra_svn, do relocations between
   ### those and ra_local URLs.
 

Modified: 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn--help_stdout
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn--help_stdout?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn--help_stdout 
(original)
+++ 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn--help_stdout 
Fri Oct 22 20:10:36 2010
@@ -36,6 +36,7 @@ Available subcommands:
    propget (pget, pg)
    proplist (plist, pl)
    propset (pset, ps)
+   relocate
    resolve
    resolved
    revert

Modified: 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout
 (original)
+++ 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout
 Fri Oct 22 20:10:36 2010
@@ -123,10 +123,13 @@ usage: 1. switch u...@pegrev] [PATH]
      This is used when a repository's root URL changes (such as a scheme
      or hostname change) but your working copy still reflects the same
      directory within the same repository.  FROM-PREFIX and TO-PREFIX are
-     initial substrings of the working copy's current and new root URLs,
-     respectively.  (You may specify the complete old and new root URLs if
-     you wish.)  Use 'svn info' to determine the current repository root
-     URL of the working copy.
+     initial substrings of the working copy's current and new URLs,
+     respectively.  (You may specify the complete old and new URLs if you
+     wish.)  Use 'svn info' to determine the current working copy URL.
+
+     Note: This syntax form -- in fact, the use of the --relocate option
+           in general -- has been deprecated in favor of running
+           'svn relocate FROM-PREFIX TO-PREFIX [PATH]'.
 
   See also 'svn help update' for a list of possible characters
   reporting the action taken.

Modified: 
subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_stdout
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_stdout?rev=1026475&r1=1026474&r2=1026475&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_stdout 
(original)
+++ subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_stdout 
Fri Oct 22 20:10:36 2010
@@ -36,6 +36,7 @@ Available subcommands:
    propget (pget, pg)
    proplist (plist, pl)
    propset (pset, ps)
+   relocate
    resolve
    resolved
    revert


Reply via email to