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

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

From: Philip Martin <philip_at_codematters.co.uk>
Date: 2002-09-24 13:14:01 CEST

mark benedetto king <bking@inquira.com> writes:

I don't really like this approach, I'd prefer a command that contacts
the new repository, to ensure that we don't get invalid text-bases.
The current patch would be the only client command that, by design,
will allow the user to produce a corrupt working copy.

That said, here is a short review to help get this working with the
recent access baton changes :)

> 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. */

I don't like the optional access baton, just make it required. Yes,
there are already some optional ones (I put them in) but I'd like to
remove those and I don't think we should add more of them.

> +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);

Do we need to support the --nonrecursive option?

>
> /* 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);

Support --nonrecursive here as well?

> +
> +
> /* 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);

Need to support PATH being a file.

> +
> + if (! adm_access)
> + {
> + SVN_ERR (svn_wc_adm_open (&adm_access, NULL, path, TRUE, TRUE, pool));

Put this bit into svn_client_relocate.

> + root = TRUE;
> + }
> +
> + from_len = strlen(from);
> +
> + SVN_ERR (svn_wc_entries_read (&entries, path, FALSE, pool));

Need to pass ADM_ACCESS.

> +
> + 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);

You will need to add something like

            svn_wc_adm_access_t *subdir_access;
            SVN_ERR (svn_wc_adm_retrieve (&subdir_access, adm_access, subdir,
                                          pool));

> + SVN_ERR (svn_wc_relocate (subdir, adm_access, from, to, pool));

and pass subdir_access instead of adm_access.

> + }
> +
> + if (entry->url &&
> + (strncmp(entry->url, from, from_len) == 0))
> + entry->url = apr_psprintf (pool, "%s%s", to, entry->url + from_len);

You will be modifying the cache, but I think it's OK since you are
about to write it out again.

> + }
> +
> + SVN_ERR (svn_wc__entries_write (entries, path, pool));

Need to pass ADM_ACCESS.

> +
> + if (root)
> + svn_wc_adm_close(adm_access);

Put this bit into svn_client_relocate.

> +
> + 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);
> +

We need to support files, so don't bother with the above check. Just
do something like

     svn_wc_adm_access_t *adm_access;
     SVN_ERR (svn_wc_adm_probe_open (&adm_access, NULL, path, TRUE, recurse,
              pool));

> + return svn_wc_relocate (dir, NULL, from, to, pool);

Pass adm_access to svn_wc_relocate, and then close it.

     SVN_ERR (svn_wc_adm_close (adm_access));

> +}
> +
> +
> +
> +/*
> + * local variables:
> + * eval: (load-file "../../tools/dev/svn-dev.el")
> + * end: */

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 24 13:15:16 2002

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.