[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-30 23:48:41 CEST

mark benedetto king <bking@Inquira.Com> writes:

> Index: subversion/libsvn_wc/relocate.c
> ===================================================================
> --- subversion/libsvn_wc/relocate.c
> +++ subversion/libsvn_wc/relocate.c Mon Sep 30 16:26:04 2002
> @@ -0,0 +1,123 @@
[snip]
> +svn_error_t *
> +svn_wc_relocate (const char *path,
> + svn_wc_adm_access_t *adm_access,
> + const char *from,
> + const char *to,
> + svn_boolean_t recurse,
> + apr_pool_t *pool)
> +{
> + enum svn_node_kind kind;
> + apr_hash_t *entries = NULL;
> + apr_hash_index_t *hi;
> + svn_boolean_t is_file = FALSE;
> + char *base;
> + int from_len;
> +
> + SVN_ERR(svn_io_check_path(path, &kind, pool));
> +
> + if (kind == svn_node_file)
> + {
> + base = svn_path_basename(path, pool);
> + path = svn_path_remove_component_nts(path, pool);

svn_path_split_nts does both these, but I don't see why you are
changing path here, it doesn't get used for files.

> + is_file = TRUE;
> + }
> +
> + from_len = strlen(from);
> +
> + SVN_ERR(svn_wc_entries_read(&entries, adm_access, FALSE, pool));
> +
> + if (is_file)
> + {
> + const char *url;
> + svn_wc_entry_t *this_dir = apr_hash_get(entries,
> + SVN_WC_ENTRY_THIS_DIR,
> + APR_HASH_KEY_STRING);
> + svn_wc_entry_t *entry = apr_hash_get(entries, base, APR_HASH_KEY_STRING);
> + if (!this_dir)
> + return svn_error_create(SVN_ERR_ENTRY_NOT_FOUND, 0, NULL, pool,
> + "missing default entry");
> + if (!entry)
> + return svn_error_create(SVN_ERR_ENTRY_NOT_FOUND, 0, NULL, pool,
> + "missing entry");
> +
> + url = entry->url? entry->url : this_dir->url;

I don't understand this bit, if the file doesn't have an URL you are
using the parent directory's URL as the file URL. Does this work?

> + if (url &&
> + (strncmp(url, from, from_len) == 0))
> + entry->url = apr_psprintf (pool, "%s%s", to, url + from_len);
> +
> + SVN_ERR(svn_wc__entries_write (entries, adm_access, pool));
> +
> + return SVN_NO_ERROR;
> + }
> +
> + 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 (recurse
> + && (entry->kind == svn_node_dir)
> + && (strcmp(key, SVN_WC_ENTRY_THIS_DIR) != 0))
> + {
> + svn_wc_adm_access_t *subdir_access;
> + const char *subdir = svn_path_join (path, key, pool);
> + SVN_ERR(svn_wc_adm_retrieve(&subdir_access, adm_access, subdir,
> + pool));
> + SVN_ERR(svn_wc_relocate(subdir, subdir_access, from,
> + to, recurse, pool));
> + }
> +
> + if (entry->url &&
> + (strncmp(entry->url, from, from_len) == 0))
> + entry->url = apr_psprintf (pool, "%s%s", to, entry->url + from_len);

Here files don't fallback on the parent directory's URL, which I think
is correct but is different to the behaviour above.

> + }
> +
> + SVN_ERR(svn_wc__entries_write (entries, adm_access, pool));
> +
> + return SVN_NO_ERROR;
> +}
> +
> Index: subversion/libsvn_client/relocate.c
> ===================================================================
> --- subversion/libsvn_client/relocate.c
> +++ subversion/libsvn_client/relocate.c Tue Sep 24 17:27:07 2002
> @@ -0,0 +1,63 @@
[snip]
> +
> +/*** Code. ***/
> +
> +svn_error_t *
> +svn_client_relocate (const char *path,
> + const char *from,
> + const char *to,
> + svn_boolean_t recurse,
> + apr_pool_t *pool)
> +{
> + svn_wc_adm_access_t *adm_access;
> + svn_error_t *err;
> + svn_error_t *err2;
> +
> + SVN_ERR (svn_wc_adm_probe_open(&adm_access, NULL, path,
> + TRUE, recurse, pool));
> +
> + err = svn_wc_relocate(path, adm_access, from, to, recurse, pool);
> +
> + err2 = svn_wc_adm_close(adm_access);

You don't need err/err2, you can use SVN_ERR here. If an error occurs
a pool cleanup handler will close the access baton.

> +
> + return err ? err : err2;
> +}

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Sep 30 23:49:21 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.