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

[PATCH] implement "svn relocate", a subcommand for frobbing the wc's urls.

From: mark benedetto king <bking_at_inquira.com>
Date: 2002-09-18 19:54:35 CEST

New subcommand: "relocate". 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__relocate): Added subcommand prototype. Fixed
  alphabetical-order of resolve/revert.

* subversion/clients/cmdline/relocate-cmd.c
  New file. Includes implementation of svn_cl__relocate().

* subversion/clients/cmdline/main.c
  (svn_cl__cmd_table): Added entry for "relocate".

Index: subversion/include/svn_wc.h
===================================================================
--- subversion/include/svn_wc.h
+++ subversion/include/svn_wc.h Wed Sep 18 13:43:59 2002
@@ -1424,6 +1424,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 Wed Sep 18 12:23:17 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 Wed Sep 18 13:42:54 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 Wed Sep 18 13:44:22 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 Wed Sep 18 13:51:47 2002
@@ -137,8 +137,9 @@
   svn_cl__propget,
   svn_cl__proplist,
   svn_cl__propset,
- svn_cl__revert,
+ svn_cl__relocate,
   svn_cl__resolve,
+ svn_cl__revert,
   svn_cl__status,
   svn_cl__switch,
   svn_cl__update;
Index: subversion/clients/cmdline/relocate-cmd.c
===================================================================
--- subversion/clients/cmdline/relocate-cmd.c
+++ subversion/clients/cmdline/relocate-cmd.c Wed Sep 18 13:22:52 2002
@@ -0,0 +1,82 @@
+/*
+ * relocate-cmd.c -- Subversion relocate command
+ *
+ * ====================================================================
+ * 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_client.h"
+#include "svn_string.h"
+#include "svn_path.h"
+#include "svn_pools.h"
+#include "svn_error.h"
+#include "cl.h"
+
+
+
+/*** Code. ***/
+
+svn_error_t *
+svn_cl__relocate (apr_getopt_t *os,
+ svn_cl__opt_state_t *opt_state,
+ apr_pool_t *pool)
+{
+ apr_array_header_t *targets;
+ apr_pool_t *subpool;
+ const char *from;
+ const char *to;
+ int i;
+
+ SVN_ERR (svn_cl__args_to_target_array (&targets, os, opt_state,
+ FALSE, pool));
+
+ 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;
+}
+
+
+
+/*
+ * local variables:
+ * eval: (load-file "../../../tools/dev/svn-dev.el")
+ * end:
+ */
Index: subversion/clients/cmdline/main.c
===================================================================
--- subversion/clients/cmdline/main.c
+++ subversion/clients/cmdline/main.c Wed Sep 18 13:09:48 2002
@@ -353,6 +353,12 @@
     " foo/bar -r1234 http://example.com/repos/zag\n",
     {'F', 'q', svn_cl__targets_opt, 'R'} },
   
+ { "relocate", svn_cl__relocate, {0},
+ "Recursively change the TARGET working copies' internal URLs, replacing\n"
+ " all URLs that begin with FROM to begin with TO, instead.\n"
+ "usage: svn relocate [FROM] [TO] [TARGETS ...]\n",
+ {0} },
+
   { "revert", svn_cl__revert, {0},
     "Restore pristine working copy file (undo all local edits)\n"
     "usage: revert TARGET1 [TARGET2 [TARGET3 ... ]]\n\n"

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Sep 18 20:01:50 2002

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