You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2010/10/22 20:00:15 UTC

svn commit: r1026434 - in /subversion/trunk/subversion: include/svn_wc.h libsvn_wc/relocate.c tests/cmdline/switch_tests.py

Author: cmpilato
Date: Fri Oct 22 18:00:14 2010
New Revision: 1026434

URL: http://svn.apache.org/viewvc?rev=1026434&view=rev
Log:
Restore a piece of lost functionality from 'svn switch --relocate',
namely the ability to specify a mere URL prefix as the FROM and TO
bits rather than having to provide full URLs.  It turns out that being
able to do 'svn switch --relocate http https TARGET' is really handy
(and possible in previous Subversion versions).  This work is also
required to restore compatibility with previous versions of the
relevant APIs.

* subversion/tests/cmdline/switch_tests.py
  (relocate_beyond_repos_root): Update expected failure strings.

* subversion/include/svn_wc.h
  (svn_wc_relocate4): Update docstring to not add unnecessary new
    requirements over the previous version thereof.

* subversion/libsvn_wc/relocate.c
  (svn_wc_relocate4): Rework the input validation to add unnecessary
    restrictions.

Modified:
    subversion/trunk/subversion/include/svn_wc.h
    subversion/trunk/subversion/libsvn_wc/relocate.c
    subversion/trunk/subversion/tests/cmdline/switch_tests.py

Modified: subversion/trunk/subversion/include/svn_wc.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_wc.h?rev=1026434&r1=1026433&r2=1026434&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_wc.h (original)
+++ subversion/trunk/subversion/include/svn_wc.h Fri Oct 22 18:00:14 2010
@@ -6633,9 +6633,10 @@ typedef svn_error_t *(*svn_wc_relocation
 
 /** Recursively change repository references at @a wcroot_abspath
  * (which is the root directory of a working copy).  The pre-change
- * URL should be @a from, and the post-change URL will be @a to.  @a
- * validator (and its baton, @a validator_baton), will be called for
- * the newly generated base URL and calculated repo root.
+ * URL should begin with @a from, and the post-change URL will begin
+ * with @a to.  @a validator (and its baton, @a validator_baton), will
+ * be called for the newly generated base URL and calculated repo
+ * root.
  *
  * @a wc_ctx is an working copy context.
  *

Modified: subversion/trunk/subversion/libsvn_wc/relocate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/relocate.c?rev=1026434&r1=1026433&r2=1026434&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/relocate.c (original)
+++ subversion/trunk/subversion/libsvn_wc/relocate.c Fri Oct 22 18:00:14 2010
@@ -82,9 +82,9 @@ svn_wc_relocate4(svn_wc_context_t *wc_ct
 {
   svn_wc__db_kind_t kind;
   const char *repos_relpath;
-  const char *old_repos_root;
-  const char *old_url;
-  const char *new_repos_root;
+  const char *old_repos_root, *old_url;
+  const char *new_repos_root, *new_url;
+  int from_len, old_url_len;
   const char *uuid;
   svn_boolean_t is_wc_root;
 
@@ -129,16 +129,28 @@ svn_wc_relocate4(svn_wc_context_t *wc_ct
                             _("Cannot relocate a single file"));
 
   old_url = svn_uri_join(old_repos_root, repos_relpath, scratch_pool);
-  if (strcmp(old_url, from) != 0)
-    return svn_error_create(SVN_ERR_WC_INVALID_RELOCATION, NULL,
-                            _("Given source URL invalid"));
+  old_url_len = strlen(old_url);
+  from_len = strlen(from);
+  if ((from_len > old_url_len) || (strncmp(old_url, from, strlen(from)) != 0))
+    return svn_error_createf(SVN_ERR_WC_INVALID_RELOCATION, NULL,
+                             _("Invalid source URL prefix: '%s' (does not "
+                               "overlap target's URL '%s')"),
+                             from, old_url);
+  
+  if (old_url_len == from_len)
+    new_url = to;
+  else
+    new_url = apr_pstrcat(scratch_pool, to, old_url + from_len, NULL);
+  if (! svn_path_is_url(new_url))
+    return svn_error_createf(SVN_ERR_WC_INVALID_RELOCATION, NULL,
+                             _("Invalid destination URL: '%s'"), new_url);
 
-  new_repos_root = uri_remove_components(to, repos_relpath, scratch_pool);
+  new_repos_root = uri_remove_components(new_url, repos_relpath, scratch_pool);
   if (!new_repos_root)
     return svn_error_createf(SVN_ERR_WC_INVALID_RELOCATION, NULL,
-                             _("Given destination URL invalid: '%s'"), to);
+                             _("Invalid destination URL: '%s'"), new_url);
 
-  SVN_ERR(validator(validator_baton, uuid, to, new_repos_root, scratch_pool));
+  SVN_ERR(validator(validator_baton, uuid, new_url, new_repos_root, scratch_pool));
 
   return svn_error_return(svn_wc__db_global_relocate(wc_ctx->db, local_abspath,
                                                      new_repos_root,

Modified: subversion/trunk/subversion/tests/cmdline/switch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/switch_tests.py?rev=1026434&r1=1026433&r2=1026434&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/switch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/switch_tests.py Fri Oct 22 18:00:14 2010
@@ -1068,18 +1068,17 @@ def relocate_beyond_repos_root(sbox):
   
   svntest.main.copy_repos(repo_dir, other_repo_dir, 1, 0)
   
-
   # A relocate that changes the repo path part of the URL shouldn't work.
   # This tests for issue #2380.
   svntest.actions.run_and_verify_svn(None, None,
-                                     ".*Given destination URL invalid.*",
+                                     ".*Invalid destination URL.*",
                                      'switch', '--relocate',
                                      A_url, other_B_url, A_wc_dir)
 
   # Another way of trying to change the fs path, leading to an invalid
   # repository root.
   svntest.actions.run_and_verify_svn(None, None,
-                                     ".*Given source URL invalid.*",
+                                     ".*is not the root.*",
                                      'switch', '--relocate',
                                      repo_url, other_B_url, A_wc_dir)
 



Re: svn commit: r1026434 - in /subversion/trunk/subversion: include/svn_wc.h libsvn_wc/relocate.c tests/cmdline/switch_tests.py

Posted by Blair Zajac <bl...@orcaware.com>.
On Oct 22, 2010, at 11:00 AM, cmpilato@apache.org wrote:

> Author: cmpilato
> Date: Fri Oct 22 18:00:14 2010
> New Revision: 1026434
> 
> URL: http://svn.apache.org/viewvc?rev=1026434&view=rev
> Log:
> Restore a piece of lost functionality from 'svn switch --relocate',
> namely the ability to specify a mere URL prefix as the FROM and TO
> bits rather than having to provide full URLs.  It turns out that being
> able to do 'svn switch --relocate http https TARGET' is really handy
> (and possible in previous Subversion versions).  This work is also
> required to restore compatibility with previous versions of the
> relevant APIs.

Great, thanks!  That is a very useful piece of functionality.  We have a svn sever on port 81 that we've moved to port 80, so a simple

svn switch --relocate http://svn:81/ http://svn/

is very easy.

Blair