[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] implement "svn switch --only-rewrite-urls"

From: mark benedetto king <bking_at_inquira.com>
Date: 2002-09-24 04:42:58 CEST

New option for svn switch: "--only-rewrite-urls". Useful for when the URL
by which the repository must be referred to has changed. This happens most
frequently for mobile users.

* subversion/include/svn_wc.h
  (svn_wc_relocate): Prototype for new function.

* subversion/include/svn_client.h
  (svn_client_relocate): Prototype for new function.

* subversion/libsvn_wc/relocate.c
  New file. Includes implementation of svn_wc_relocate().

* subversion/libsvn_client/relocate.c
  New file. Includes implementation of svn_client_relocate().

* subversion/clients/cmdline/cl.h
  (svn_cl__only_rewrite_urls_opt): Added enum for only-rewrite-urls option.
  (svn_cl__opt_state_t): Added boolean member for only-rewrite-urls option.

* subversion/clients/cmdline/switch-cmd.c
  (svn_cl__switch): Call rewrite_urls() when appropriate.
  (rewrite_urls): Call svn_client_relocate().

* subversion/clients/cmdline/main.c
  (svn_cl__options): Added entry for long option "--only-rewrite-urls".
  (svn_cl__cmd_table): Added option for "switch" subcommand.
  (main): Modify opt_state appropriately when only-rewrite-urls option is
  specified.
 
* subversion/tests/clients/cmdline/getopt_tests_data/svn_help_log_switch_stdout
  Updated to reflect new option to "svn switch".

 
Index: subversion/include/svn_wc.h
===================================================================
--- subversion/include/svn_wc.h
+++ subversion/include/svn_wc.h Mon Sep 23 20:38:04 2002
@@ -1472,6 +1472,19 @@
                 svn_wc_adm_access_t *optional_adm_access,
                 apr_pool_t *pool);
 
+/* Recurse from PATH, changing repository references that begin with
+ FROM to begin with TO instead. Perform necessary allocations in
+ POOL.
+
+ ADM_ACCESS is an access baton for the directory containing
+ PATH. ADM_ACCESS can be NULL in which case the function will open and
+ close acess batons as required. */
+svn_error_t *
+svn_wc_relocate (const char *path,
+ svn_wc_adm_access_t *adm_access,
+ const char *from,
+ const char *to,
+ apr_pool_t *pool);
 
 /* Revert changes to PATH (perhaps in a RECURSIVE fashion). Perform
    necessary allocations in POOL.
Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h
+++ subversion/include/svn_client.h Mon Sep 23 20:38:04 2002
@@ -684,6 +684,15 @@
                     apr_pool_t *pool);
 
 
+/* Recursively modify a working copy directory DIR, changing any
+ repository URLs that begin with FROM to begin with TO instead. */
+svn_error_t *
+svn_client_relocate (const char *dir,
+ const char *from,
+ const char *to,
+ apr_pool_t *pool);
+
+
 /* Restore the pristine version of a working copy PATH, effectively
    undoing any local mods. If PATH is a directory, and RECURSIVE is
    TRUE, this will be a recursive operation.
Index: subversion/libsvn_wc/relocate.c
===================================================================
--- subversion/libsvn_wc/relocate.c
+++ subversion/libsvn_wc/relocate.c Mon Sep 23 20:38:04 2002
@@ -0,0 +1,101 @@
+/*
+ * relocate.c: do wc repos relocation
+ *
+ * ====================================================================
+ * Copyright (c) 2000-2002 CollabNet. All rights reserved.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://subversion.tigris.org/license-1.html.
+ * If newer versions of this license are posted there, you may use a
+ * newer version instead, at your option.
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals. For exact contribution history, see the revision
+ * history and logs, available at http://subversion.tigris.org/.
+ * ====================================================================
+ */
+
+
+
+#include "svn_wc.h"
+#include "svn_error.h"
+#include "svn_string.h"
+#include "svn_xml.h"
+#include "svn_pools.h"
+#include "svn_io.h"
+
+#include "wc.h"
+#include "entries.h"
+
+
+svn_error_t *
+svn_wc_relocate (const char *path,
+ svn_wc_adm_access_t *adm_access,
+ const char *from,
+ const char *to,
+ apr_pool_t *pool)
+{
+ apr_hash_t *entries = NULL;
+ apr_hash_index_t *hi;
+ enum svn_node_kind kind;
+ int is_wc;
+ int from_len;
+
+ svn_boolean_t root = FALSE;
+
+
+ SVN_ERR (svn_wc_check_wc (path, &is_wc, pool));
+ if (! is_wc)
+ return svn_error_createf
+ (SVN_ERR_WC_NOT_DIRECTORY, 0, NULL, pool,
+ "svn_wc_cleanup: %s is not a working copy directory", path);
+
+ if (! adm_access)
+ {
+ SVN_ERR (svn_wc_adm_open (&adm_access, NULL, path, TRUE, TRUE, pool));
+ root = TRUE;
+ }
+
+ from_len = strlen(from);
+
+ SVN_ERR (svn_wc_entries_read (&entries, path, FALSE, pool));
+
+ for (hi = apr_hash_first (pool, entries); hi; hi = apr_hash_next (hi))
+ {
+ const void *key;
+ void *val;
+ svn_wc_entry_t *entry;
+
+ apr_hash_this (hi, &key, NULL, &val);
+ entry = val;
+
+ if ((entry->kind == svn_node_dir)
+ && (strcmp (key, SVN_WC_ENTRY_THIS_DIR) != 0))
+ {
+ /* Recurse */
+ const char *subdir = svn_path_join (path, key, pool);
+ SVN_ERR (svn_wc_relocate (subdir, adm_access, from, to, pool));
+ }
+
+ if (entry->url &&
+ (strncmp(entry->url, from, from_len) == 0))
+ entry->url = apr_psprintf (pool, "%s%s", to, entry->url + from_len);
+ }
+
+ SVN_ERR (svn_wc__entries_write (entries, path, pool));
+
+ if (root)
+ svn_wc_adm_close(adm_access);
+
+ return SVN_NO_ERROR;
+}
+
+
+
+/*
+ * local variables:
+ * eval: (load-file "../../tools/dev/svn-dev.el")
+ * end:
+ */
+
Index: subversion/libsvn_client/relocate.c
===================================================================
--- subversion/libsvn_client/relocate.c
+++ subversion/libsvn_client/relocate.c Mon Sep 23 20:38:04 2002
@@ -0,0 +1,59 @@
+/*
+ * relocate.c: wrapper around wc relocation functionality.
+ *
+ * ====================================================================
+ * Copyright (c) 2000-2002 CollabNet. All rights reserved.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://subversion.tigris.org/license-1.html.
+ * If newer versions of this license are posted there, you may use a
+ * newer version instead, at your option.
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals. For exact contribution history, see the revision
+ * history and logs, available at http://subversion.tigris.org/.
+ * ====================================================================
+ */
+
+/* ==================================================================== */
+
+
+
+/*** Includes. ***/
+
+#include "svn_wc.h"
+#include "svn_client.h"
+#include "svn_string.h"
+#include "svn_pools.h"
+#include "svn_error.h"
+#include "svn_path.h"
+#include "client.h"
+
+
+
+/*** Code. ***/
+
+svn_error_t *
+svn_client_relocate (const char *dir,
+ const char *from,
+ const char *to,
+ apr_pool_t *pool)
+{
+ enum svn_node_kind kind;
+
+ SVN_ERR (svn_io_check_path (dir, &kind, pool));
+ if (kind != svn_node_dir)
+ return svn_error_createf (SVN_ERR_WC_NOT_DIRECTORY, 0, NULL, pool,
+ "Cannot relocate '%s' -- not a directory",
+ dir);
+
+ return svn_wc_relocate (dir, NULL, from, to, pool);
+}
+
+
+
+/*
+ * local variables:
+ * eval: (load-file "../../tools/dev/svn-dev.el")
+ * end: */
Index: subversion/clients/cmdline/cl.h
===================================================================
--- subversion/clients/cmdline/cl.h
+++ subversion/clients/cmdline/cl.h Mon Sep 23 20:44:07 2002
@@ -53,7 +53,8 @@
   svn_cl__xml_opt,
   svn_cl__strict_opt,
   svn_cl__no_ignore_opt,
- svn_cl__no_auth_cache_opt
+ svn_cl__no_auth_cache_opt,
+ svn_cl__only_rewrite_urls_opt
 } svn_cl__longopt_t;
 
 
@@ -93,6 +94,7 @@
   svn_boolean_t xml; /* output in xml, e.g., "svn log --xml" */
   svn_boolean_t no_ignore; /* disregard default ignores & svn:ignore's */
   svn_boolean_t no_auth_cache; /* do not cache authentication information */
+ svn_boolean_t only_rewrite_urls; /* rewrite urls (svn switch) */
 } svn_cl__opt_state_t;
 
 
Index: subversion/clients/cmdline/switch-cmd.c
===================================================================
--- subversion/clients/cmdline/switch-cmd.c
+++ subversion/clients/cmdline/switch-cmd.c Mon Sep 23 21:38:24 2002
@@ -21,18 +21,53 @@
 
 
 /*** Includes. ***/
-
 #include "svn_wc.h"
 #include "svn_client.h"
 #include "svn_string.h"
 #include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_error.h"
+#include "svn_pools.h"
 #include "cl.h"
 
 
 /*** Code. ***/
 
+static svn_error_t *
+rewrite_urls(apr_array_header_t *targets,
+ apr_pool_t *pool)
+{
+ apr_pool_t *subpool;
+ const char *from;
+ const char *to;
+ int i;
+
+ if (targets->nelts < 2)
+ return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, 0, 0, pool, "");
+
+ from = ((const char **) (targets->elts))[0];
+ to = ((const char **) (targets->elts))[1];
+
+ subpool = svn_pool_create (pool);
+
+ if (targets->nelts == 2)
+ {
+ SVN_ERR(svn_client_relocate ("", from, to, pool));
+ }
+ else
+ {
+ for (i = 2; i < targets->nelts; i++)
+ {
+ const char *target = ((const char **) (targets->elts))[i];
+ SVN_ERR (svn_client_relocate (target, from, to, subpool));
+ svn_pool_clear (subpool);
+ }
+ }
+
+ svn_pool_destroy (subpool);
+ return SVN_NO_ERROR;
+}
+
 
 svn_error_t *
 svn_cl__switch (apr_getopt_t *os,
@@ -53,6 +88,11 @@
      switch to ("switch_url"). */
   SVN_ERR (svn_cl__args_to_target_array (&targets, os, opt_state,
                                          FALSE, pool));
+
+ /* handle only-rewrite case specially */
+ if (opt_state->only_rewrite_urls)
+ return rewrite_urls (targets, pool);
+
   if ((targets->nelts < 1) || (targets->nelts > 2))
     return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, 0, 0, pool, "");
 
Index: subversion/clients/cmdline/main.c
===================================================================
--- subversion/clients/cmdline/main.c
+++ subversion/clients/cmdline/main.c Mon Sep 23 21:46:18 2002
@@ -77,6 +77,8 @@
                       "disregard default and svn:ignore property ignores"},
     {"no-auth-cache", svn_cl__no_auth_cache_opt, 0,
                       "do not cache authentication tokens"},
+ {"only-rewrite-urls", svn_cl__only_rewrite_urls_opt, 0,
+ "only rewrite urls; do not contact a repository"},
     {0, 0, 0}
   };
 
@@ -400,10 +402,12 @@
   
   { "switch", svn_cl__switch, {"sw"},
     "Update working copy to mirror a new URL\n"
- "usage: switch REPOS_URL [TARGET]\n\n"
+ "usage: switch REPOS_URL [TARGET] or\n"
+ " switch --only-rewrite-urls [FROM] [TO] [TARGET ...]\n\n"
     " Note: this is the way to move a working copy to a new branch.\n",
     { 'r', 'D', 'N', 'q', svn_cl__auth_username_opt,
- svn_cl__auth_password_opt, svn_cl__no_auth_cache_opt} },
+ svn_cl__auth_password_opt, svn_cl__no_auth_cache_opt,
+ svn_cl__only_rewrite_urls_opt } },
  
   { "update", svn_cl__update, {"up"},
     "Bring changes from the repository into the working copy.\n"
@@ -1131,6 +1135,9 @@
       case svn_cl__no_auth_cache_opt:
         opt_state.no_auth_cache = TRUE;
         break;
+ case svn_cl__only_rewrite_urls_opt:
+ opt_state.only_rewrite_urls = TRUE;
+ break;
       case 'x':
         err = svn_utf_cstring_to_utf8 (&opt_state.extensions, opt_arg,
                                        NULL, pool);
Index: subversion/tests/clients/cmdline/getopt_tests_data/svn_help_log_switch_stdout
===================================================================
--- subversion/tests/clients/cmdline/getopt_tests_data/svn_help_log_switch_stdout
+++ subversion/tests/clients/cmdline/getopt_tests_data/svn_help_log_switch_stdout Mon Sep 23 22:04:44 2002
@@ -39,4 +39,5 @@
   --username arg : specify a username ARG
   --password arg : specify a password ARG
   --no-auth-cache : do not cache authentication tokens
+ --only-rewrite-urls arg : only rewrite urls; do not contact a repository
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 24 04:50:25 2002

This is an archived mail posted to the Subversion Dev mailing list.