Index: subversion/include/private/svn_fs_util.h =================================================================== --- subversion/include/private/svn_fs_util.h (revision 0) +++ subversion/include/private/svn_fs_util.h (revision 0) @@ -0,0 +1,42 @@ +/* + * svn_fs_util.h: Declarations for the APIs of libsvn_fs_util to be + * consumed by only fs_* libs. + * + * ==================================================================== + * Copyright (c) 2007 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/. + * ==================================================================== + */ + +#ifndef SVN_FS_UTIL_H +#define SVN_FS_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Return a canonicalized version of a filesystem PATH, allocated in + POOL. While the filesystem API is pretty flexible about the + incoming paths (they must be UTF-8 with '/' as separators, but they + don't have to begin with '/', and multiple contiguous '/'s are + ignored) we want any paths that are physically stored in the + underlying database to look consistent. Specifically, absolute + filesystem paths should begin with '/', and all redundant and trailing '/' + characters be removed. */ +const char * +svn_fs__canonicalize_abspath(const char *path, apr_pool_t *pool); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* SVN_FS_UTIL_H */ Index: subversion/libsvn_fs_fs/tree.c =================================================================== --- subversion/libsvn_fs_fs/tree.c (revision 24297) +++ subversion/libsvn_fs_fs/tree.c (working copy) @@ -1,7 +1,7 @@ /* tree.c : tree-like filesystem, built on DAG filesystem * * ==================================================================== - * Copyright (c) 2000-2006 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -50,6 +50,7 @@ #include "id.h" #include "private/svn_fs_merge_info.h" +#include "private/svn_fs_util.h" #include "../libsvn_fs/fs-loader.h" @@ -650,7 +651,7 @@ dag_node_t *here; /* The directory we're currently looking at. */ parent_path_t *parent_path; /* The path from HERE up to the root. */ const char *rest; /* The portion of PATH we haven't traversed yet. */ - const char *canon_path = svn_fs_fs__canonicalize_abspath(path, pool); + const char *canon_path = svn_fs__canonicalize_abspath(path, pool); const char *path_so_far = "/"; /* Make a parent_path item for the root node, using its own current @@ -872,7 +873,7 @@ dag_node_t *node = NULL; /* Canonicalize the input PATH. */ - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); /* If ROOT is a revision root, we'll look for the DAG in our cache. */ node = dag_node_cache_get(root, path, pool); @@ -915,7 +916,7 @@ apr_pool_t *pool) { SVN_ERR(svn_fs_fs__add_change(fs, txn_id, - svn_fs_fs__canonicalize_abspath(path, pool), + svn_fs__canonicalize_abspath(path, pool), noderev_id, change_kind, text_mod, prop_mod, copyfrom_rev, copyfrom_path, pool)); @@ -1152,7 +1153,7 @@ children of the root are received without a leading slash (e.g. "/file.txt" is received as "file.txt"), so must be made absolute. */ - const char *canon_path = svn_fs_fs__canonicalize_abspath(path, pool); + const char *canon_path = svn_fs__canonicalize_abspath(path, pool); SVN_ERR(root->fs->vtable->open_txn(&txn, root->fs, txn_id, pool)); @@ -2061,7 +2062,7 @@ to_path, pool)); /* Canonicalize the copyfrom path. */ - from_canonpath = svn_fs_fs__canonicalize_abspath(from_path, pool); + from_canonpath = svn_fs__canonicalize_abspath(from_path, pool); SVN_ERR(svn_fs_fs__dag_copy(to_parent_path->parent->node, to_parent_path->entry, @@ -2803,7 +2804,7 @@ /* Okay, all seems well. Build our history object and return it. */ *history_p = assemble_history(root->fs, - svn_fs_fs__canonicalize_abspath(path, pool), + svn_fs__canonicalize_abspath(path, pool), root->rev, FALSE, NULL, SVN_INVALID_REVNUM, pool); return SVN_NO_ERROR; Index: subversion/libsvn_fs_fs/fs.c =================================================================== --- subversion/libsvn_fs_fs/fs.c (revision 24297) +++ subversion/libsvn_fs_fs/fs.c (working copy) @@ -278,68 +278,6 @@ return svn_io_remove_dir2(path, FALSE, pool); } - - -/* Miscellany */ - -const char * -svn_fs_fs__canonicalize_abspath(const char *path, apr_pool_t *pool) -{ - char *newpath; - int path_len; - int path_i = 0, newpath_i = 0; - svn_boolean_t eating_slashes = FALSE; - - /* No PATH? No problem. */ - if (! path) - return NULL; - - /* Empty PATH? That's just "/". */ - if (! *path) - return apr_pstrdup(pool, "/"); - - /* Now, the fun begins. Alloc enough room to hold PATH with an - added leading '/'. */ - path_len = strlen(path); - newpath = apr_pcalloc(pool, path_len + 2); - - /* No leading slash? Fix that. */ - if (*path != '/') - { - newpath[newpath_i++] = '/'; - } - - for (path_i = 0; path_i < path_len; path_i++) - { - if (path[path_i] == '/') - { - /* The current character is a '/'. If we are eating up - extra '/' characters, skip this character. Else, note - that we are now eating slashes. */ - if (eating_slashes) - continue; - eating_slashes = TRUE; - } - else - { - /* The current character is NOT a '/'. If we were eating - slashes, we need not do that any more. */ - if (eating_slashes) - eating_slashes = FALSE; - } - - /* Copy the current character into our new buffer. */ - newpath[newpath_i++] = path[path_i]; - } - - /* Did we leave a '/' attached to the end of NEWPATH (other than in - the root directory case)? */ - if ((newpath[newpath_i - 1] == '/') && (newpath_i > 1)) - newpath[newpath_i - 1] = '\0'; - - return newpath; -} - static const svn_version_t * fs_version(void) { Index: subversion/libsvn_fs_fs/fs.h =================================================================== --- subversion/libsvn_fs_fs/fs.h (revision 24297) +++ subversion/libsvn_fs_fs/fs.h (working copy) @@ -1,7 +1,7 @@ /* fs.h : interface to Subversion filesystem, private to libsvn_fs * * ==================================================================== - * Copyright (c) 2000-2006 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -123,18 +123,6 @@ } fs_fs_data_t; -/* Return a canonicalized version of a filesystem PATH, allocated in - POOL. While the filesystem API is pretty flexible about the - incoming paths (they must be UTF-8 with '/' as separators, but they - don't have to begin with '/', and multiple contiguous '/'s are - ignored) we want any paths that are physically stored in the - underlying database to look consistent. Specifically, absolute - filesystem paths should begin with '/', and all redundant and trailing '/' - characters be removed. */ -const char * -svn_fs_fs__canonicalize_abspath(const char *path, apr_pool_t *pool); - - /*** Filesystem Transaction ***/ typedef struct { Index: subversion/libsvn_fs_fs/lock.c =================================================================== --- subversion/libsvn_fs_fs/lock.c (revision 24297) +++ subversion/libsvn_fs_fs/lock.c (working copy) @@ -1,7 +1,7 @@ /* lock.c : functions for manipulating filesystem locks. * * ==================================================================== - * Copyright (c) 2000-2004 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -37,6 +37,7 @@ #include "fs_fs.h" #include "../libsvn_fs/fs-loader.h" +#include "private/svn_fs_util.h" #include "svn_private_config.h" /* Names of special lock directories in the fs_fs filesystem. */ @@ -651,7 +652,7 @@ svn_boolean_t have_write_lock, apr_pool_t *pool) { - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); if (recurse) { /* Discover all locks at or below the path. */ @@ -854,7 +855,7 @@ struct lock_baton lb; SVN_ERR(svn_fs_fs__check_fs(fs)); - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); lb.lock_p = lock_p; lb.fs = fs; @@ -900,7 +901,7 @@ struct unlock_baton ub; SVN_ERR(svn_fs_fs__check_fs(fs)); - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); ub.fs = fs; ub.path = path; @@ -920,7 +921,7 @@ apr_pool_t *pool) { SVN_ERR(svn_fs_fs__check_fs(fs)); - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); return get_lock_helper(fs, lock_p, path, FALSE, pool); } @@ -935,7 +936,7 @@ const char *digest_path; SVN_ERR(svn_fs_fs__check_fs(fs)); - path = svn_fs_fs__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); /* Get the top digest path in our tree of interest, and then walk it. */ digest_path = digest_path_from_path(fs, path, pool); Index: subversion/libsvn_fs_base/tree.c =================================================================== --- subversion/libsvn_fs_base/tree.c (revision 24297) +++ subversion/libsvn_fs_base/tree.c (working copy) @@ -1,7 +1,7 @@ /* tree.c : tree-like filesystem, built on DAG filesystem * * ==================================================================== - * Copyright (c) 2000-2006 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -58,6 +58,7 @@ #include "bdb/copies-table.h" #include "../libsvn_fs/fs-loader.h" #include "private/svn_fs_merge_info.h" +#include "private/svn_fs_util.h" /* ### I believe this constant will become internal to reps-strings.c. @@ -728,7 +729,7 @@ dag_node_t *here; /* The directory we're currently looking at. */ parent_path_t *parent_path; /* The path from HERE up to the root. */ const char *rest; /* The portion of PATH we haven't traversed yet. */ - const char *canon_path = svn_fs_base__canonicalize_abspath(path, pool); + const char *canon_path = svn_fs__canonicalize_abspath(path, pool); const char *path_so_far = "/"; /* Make a parent_path item for the root node, using its own current @@ -950,7 +951,7 @@ dag_node_t *node = NULL; /* Canonicalize the input PATH. */ - path = svn_fs_base__canonicalize_abspath(path, pool); + path = svn_fs__canonicalize_abspath(path, pool); /* If ROOT is a revision root, we'll look for the DAG in our cache. */ node = dag_node_cache_get(root, path, pool); @@ -989,7 +990,7 @@ apr_pool_t *pool) { change_t change; - change.path = svn_fs_base__canonicalize_abspath(path, pool); + change.path = svn_fs__canonicalize_abspath(path, pool); change.noderev_id = noderev_id; change.kind = change_kind; change.text_mod = text_mod; @@ -1342,7 +1343,7 @@ children of the root are received without a leading slash (e.g. "/file.txt" is received as "file.txt"), so must be made absolute. */ - const char *canon_path = svn_fs_base__canonicalize_abspath(args->path, + const char *canon_path = svn_fs__canonicalize_abspath(args->path, trail->pool); SVN_ERR(svn_fs_base__set_txn_merge_info(args->root->fs, txn_id, canon_path, args->value, trail, trail->pool)); @@ -3912,8 +3913,7 @@ /* Okay, all seems well. Build our history object and return it. */ *history_p = assemble_history(root->fs, - svn_fs_base__canonicalize_abspath(path, - pool), + svn_fs__canonicalize_abspath(path, pool), root->rev, FALSE, NULL, SVN_INVALID_REVNUM, pool); return SVN_NO_ERROR; Index: subversion/libsvn_fs_base/fs.c =================================================================== --- subversion/libsvn_fs_base/fs.c (revision 24297) +++ subversion/libsvn_fs_base/fs.c (working copy) @@ -1,7 +1,7 @@ /* fs.c --- creating, opening and closing filesystems * * ==================================================================== - * Copyright (c) 2000-2006 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -1166,68 +1166,6 @@ return SVN_NO_ERROR; } - - -/* Miscellany */ - -const char * -svn_fs_base__canonicalize_abspath(const char *path, apr_pool_t *pool) -{ - char *newpath; - int path_len; - int path_i = 0, newpath_i = 0; - svn_boolean_t eating_slashes = FALSE; - - /* No PATH? No problem. */ - if (! path) - return NULL; - - /* Empty PATH? That's just "/". */ - if (! *path) - return apr_pstrdup(pool, "/"); - - /* Now, the fun begins. Alloc enough room to hold PATH with an - added leading '/'. */ - path_len = strlen(path); - newpath = apr_pcalloc(pool, path_len + 2); - - /* No leading slash? Fix that. */ - if (*path != '/') - { - newpath[newpath_i++] = '/'; - } - - for (path_i = 0; path_i < path_len; path_i++) - { - if (path[path_i] == '/') - { - /* The current character is a '/'. If we are eating up - extra '/' characters, skip this character. Else, note - that we are now eating slashes. */ - if (eating_slashes) - continue; - eating_slashes = TRUE; - } - else - { - /* The current character is NOT a '/'. If we were eating - slashes, we need not do that any more. */ - if (eating_slashes) - eating_slashes = FALSE; - } - - /* Copy the current character into our new buffer. */ - newpath[newpath_i++] = path[path_i]; - } - - /* Did we leave a '/' attached to the end of NEWPATH (other than in - the root directory case)? */ - if ((newpath[newpath_i - 1] == '/') && (newpath_i > 1)) - newpath[newpath_i - 1] = '\0'; - - return newpath; -} - static const svn_version_t * base_version(void) { Index: subversion/libsvn_fs_base/fs.h =================================================================== --- subversion/libsvn_fs_base/fs.h (revision 24297) +++ subversion/libsvn_fs_base/fs.h (working copy) @@ -1,7 +1,7 @@ /* fs.h : interface to Subversion filesystem, private to libsvn_fs * * ==================================================================== - * Copyright (c) 2000-2004 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -74,18 +74,6 @@ } base_fs_data_t; -/* Return a canonicalized version of a filesystem PATH, allocated in - POOL. While the filesystem API is pretty flexible about the - incoming paths (they must be UTF-8 with '/' as separators, but they - don't have to begin with '/', and multiple contiguous '/'s are - ignored) we want any paths that are physically stored in the - underlying database to look consistent. Specifically, absolute - filesystem paths should begin with '/', and all redundant and trailing '/' - characters be removed. */ -const char * -svn_fs_base__canonicalize_abspath(const char *path, apr_pool_t *pool); - - /*** Filesystem Revision ***/ typedef struct { Index: subversion/libsvn_fs_base/lock.c =================================================================== --- subversion/libsvn_fs_base/lock.c (revision 24297) +++ subversion/libsvn_fs_base/lock.c (working copy) @@ -1,7 +1,7 @@ /* lock.c : functions for manipulating filesystem locks. * * ==================================================================== - * Copyright (c) 2000-2004 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -29,6 +29,7 @@ #include "bdb/locks-table.h" #include "bdb/lock-tokens-table.h" #include "../libsvn_fs/fs-loader.h" +#include "private/svn_fs_util.h" /* Add LOCK and its associated LOCK_TOKEN (associated with PATH) as @@ -217,7 +218,7 @@ SVN_ERR(svn_fs_base__check_fs(fs)); args.lock_p = lock; - args.path = svn_fs_base__canonicalize_abspath(path, pool); + args.path = svn_fs__canonicalize_abspath(path, pool); args.token = token; args.comment = comment; args.is_dav_comment = is_dav_comment; @@ -305,7 +306,7 @@ SVN_ERR(svn_fs_base__check_fs(fs)); - args.path = svn_fs_base__canonicalize_abspath(path, pool); + args.path = svn_fs__canonicalize_abspath(path, pool); args.token = token; args.break_lock = break_lock; return svn_fs_base__retry_txn(fs, txn_body_unlock, &args, pool); @@ -379,7 +380,7 @@ SVN_ERR(svn_fs_base__check_fs(fs)); - args.path = svn_fs_base__canonicalize_abspath(path, pool); + args.path = svn_fs__canonicalize_abspath(path, pool); args.lock_p = lock; return svn_fs_base__retry_txn(fs, txn_body_get_lock, &args, pool); } @@ -413,7 +414,7 @@ struct locks_get_args args; SVN_ERR(svn_fs_base__check_fs(fs)); - args.path = svn_fs_base__canonicalize_abspath(path, pool); + args.path = svn_fs__canonicalize_abspath(path, pool); args.get_locks_func = get_locks_func; args.get_locks_baton = get_locks_baton; return svn_fs_base__retry_txn(fs, txn_body_get_locks, &args, pool); Index: subversion/libsvn_fs_base/dag.c =================================================================== --- subversion/libsvn_fs_base/dag.c (revision 24297) +++ subversion/libsvn_fs_base/dag.c (working copy) @@ -1,7 +1,7 @@ /* dag.c : DAG-like interface filesystem, private to libsvn_fs * * ==================================================================== - * Copyright (c) 2000-2006 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -46,6 +46,7 @@ #include "bdb/strings-table.h" #include "private/svn_fs_merge_info.h" +#include "private/svn_fs_util.h" #include "../libsvn_fs/fs-loader.h" #include "svn_private_config.h" @@ -1350,7 +1351,7 @@ reserved above. */ SVN_ERR(svn_fs_bdb__create_copy (fs, copy_id, - svn_fs_base__canonicalize_abspath(from_path, pool), + svn_fs__canonicalize_abspath(from_path, pool), from_txn_id, id, copy_kind_real, trail, pool)); /* Finally, add the COPY_ID to the transaction's list of copies Index: subversion/libsvn_fs_util/fs-util.c =================================================================== --- subversion/libsvn_fs_util/fs-util.c (revision 0) +++ subversion/libsvn_fs_util/fs-util.c (revision 0) @@ -0,0 +1,95 @@ +/* fs-util.c : internal utility functions used by both FSFS and BDB back + * ends. + * + * ==================================================================== + * Copyright (c) 2007 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 +#include +#include +#include +#include + +#include +#include + +#include + +#include "svn_fs.h" +#include "svn_path.h" +#include "svn_private_config.h" + +#include "../libsvn_fs/fs-loader.h" + +/* Miscellany */ + +const char * +svn_fs__canonicalize_abspath(const char *path, apr_pool_t *pool) +{ + char *newpath; + int path_len; + int path_i = 0, newpath_i = 0; + svn_boolean_t eating_slashes = FALSE; + + /* No PATH? No problem. */ + if (! path) + return NULL; + + /* Empty PATH? That's just "/". */ + if (! *path) + return apr_pstrdup(pool, "/"); + + /* Now, the fun begins. Alloc enough room to hold PATH with an + added leading '/'. */ + path_len = strlen(path); + newpath = apr_pcalloc(pool, path_len + 2); + + /* No leading slash? Fix that. */ + if (*path != '/') + { + newpath[newpath_i++] = '/'; + } + + for (path_i = 0; path_i < path_len; path_i++) + { + if (path[path_i] == '/') + { + /* The current character is a '/'. If we are eating up + extra '/' characters, skip this character. Else, note + that we are now eating slashes. */ + if (eating_slashes) + continue; + eating_slashes = TRUE; + } + else + { + /* The current character is NOT a '/'. If we were eating + slashes, we need not do that any more. */ + if (eating_slashes) + eating_slashes = FALSE; + } + + /* Copy the current character into our new buffer. */ + newpath[newpath_i++] = path[path_i]; + } + + /* Did we leave a '/' attached to the end of NEWPATH (other than in + the root directory case)? */ + if ((newpath[newpath_i - 1] == '/') && (newpath_i > 1)) + newpath[newpath_i - 1] = '\0'; + + return newpath; +} + Index: subversion/tests/libsvn_fs_base/fs-base-test.c =================================================================== --- subversion/tests/libsvn_fs_base/fs-base-test.c (revision 24297) +++ subversion/tests/libsvn_fs_base/fs-base-test.c (working copy) @@ -1,7 +1,7 @@ /* fs-test.c --- tests for the filesystem * * ==================================================================== - * Copyright (c) 2000-2004 CollabNet. All rights reserved. + * Copyright (c) 2000-2007 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 @@ -33,6 +33,7 @@ #include "../../libsvn_fs_base/bdb/txn-table.h" #include "../../libsvn_fs_base/bdb/nodes-table.h" +#include "private/svn_fs_util.h" #include "../../libsvn_delta/delta.h" #define SET_STR(ps, s) ((ps)->data = (s), (ps)->len = strlen(s)) @@ -1152,7 +1153,7 @@ { "///foo///bar///baz///", "/foo/bar/baz" }, }; - *msg = "test svn_fs_base__canonicalize_abspath"; + *msg = "test svn_fs__canonicalize_abspath"; if (msg_only) return SVN_NO_ERROR; @@ -1161,7 +1162,7 @@ { const char *input = paths[i][0]; const char *output = paths[i][1]; - const char *actual = svn_fs_base__canonicalize_abspath(input, pool); + const char *actual = svn_fs__canonicalize_abspath(input, pool); if ((! output) && (! actual)) continue;