Author: stefan2
Date: Sat Feb 23 00:48:40 2013
New Revision: 1449260

URL: http://svn.apache.org/r1449260
Log:
For now (1.8), make svn_fs__canonicalize_abspath always allocate the result
in POOL and re-introduce svn_fs__is_canonical_abspath as a way of checking
that the path content would change.

In the future (1.9), we will hopefully be able to rev the FS API layer and
eliminate the need for canonicalization with the FS implementation.

* subversion/include/private/svn_fs_util.h
  (svn_fs__is_canonical_abspath): re-introduce
  (svn_fs__canonicalize_abspath): update docstring

* subversion/libsvn_fs_util/fs-util.c
  (svn_fs__is_canonical_abspath): implement
  (svn_fs__canonicalize_abspath): always duplicate PATH; optimize string
   termination code

* subversion/libsvn_fs_fs/tree.c
  (open_path,
   get_dag): update 

Suggested by: cmpilato

Modified:
    subversion/trunk/subversion/include/private/svn_fs_util.h
    subversion/trunk/subversion/libsvn_fs_fs/tree.c
    subversion/trunk/subversion/libsvn_fs_util/fs-util.c

Modified: subversion/trunk/subversion/include/private/svn_fs_util.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_fs_util.h?rev=1449260&r1=1449259&r2=1449260&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_fs_util.h (original)
+++ subversion/trunk/subversion/include/private/svn_fs_util.h Sat Feb 23 
00:48:40 2013
@@ -35,9 +35,13 @@
 extern "C" {
 #endif /* __cplusplus */
 
-/* If the filesystem PATH is not already in canonical form,  return a
-   canonicalized version of it, allocated in POOL.  Otherwise, return
-   PATH directly.
+/* Returns whether PATH is in canonical form as defined by
+   svn_fs__canonicalize_abspath().
+ */
+svn_boolean_t
+svn_fs__is_canonical_abspath(const char *path);
+
+/* 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

Modified: subversion/trunk/subversion/libsvn_fs_fs/tree.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/tree.c?rev=1449260&r1=1449259&r2=1449260&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/tree.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/tree.c Sat Feb 23 00:48:40 2013
@@ -913,7 +913,7 @@ open_path(parent_path_t **parent_path_p,
      directly at the parent node, if the caller did not requested the full
      parent chain. */
   const char *directory;
-  assert(path == svn_fs__canonicalize_abspath(path, pool));
+  assert(svn_fs__is_canonical_abspath(path));
   if (flags & open_path_node_only)
     {
       directory = svn_dirent_dirname(path, pool);
@@ -1177,10 +1177,9 @@ get_dag(dag_node_t **dag_node_p,
   if (! node)
     {
       /* Canonicalize the input PATH. */
-      const char *canon_path = svn_fs__canonicalize_abspath(path, pool);
-      if (canon_path != path)
+      if (! svn_fs__is_canonical_abspath(path))
         {
-          path = canon_path;
+          path = svn_fs__canonicalize_abspath(path, pool);
 
           /* Try again with the corrected path. */
           SVN_ERR(dag_node_cache_get(&node, root, path, needs_lock_cache,

Modified: subversion/trunk/subversion/libsvn_fs_util/fs-util.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_util/fs-util.c?rev=1449260&r1=1449259&r2=1449260&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_util/fs-util.c (original)
+++ subversion/trunk/subversion/libsvn_fs_util/fs-util.c Sat Feb 23 00:48:40 
2013
@@ -62,6 +62,21 @@ is_canonical_abspath(const char *path, s
   return TRUE;
 }
 
+svn_boolean_t
+svn_fs__is_canonical_abspath(const char *path)
+{
+  /* No PATH?  No problem. */
+  if (! path)
+    return TRUE;
+
+  /* Empty PATH?  That's just "/". */
+  if (! *path)
+    return FALSE;
+
+  /* detailed checks */
+  return is_canonical_abspath(path, strlen(path));
+}
+
 const char *
 svn_fs__canonicalize_abspath(const char *path, apr_pool_t *pool)
 {
@@ -81,11 +96,11 @@ svn_fs__canonicalize_abspath(const char 
   /* Non-trivial cases.  Maybe, the path already is canonical after all? */
   path_len = strlen(path);
   if (is_canonical_abspath(path, path_len))
-    return path;
+    return apr_pstrmemdup(pool, path, path_len);
 
   /* Now, the fun begins.  Alloc enough room to hold PATH with an
      added leading '/'. */
-  newpath = apr_pcalloc(pool, path_len + 2);
+  newpath = apr_palloc(pool, path_len + 2);
 
   /* No leading slash?  Fix that. */
   if (*path != '/')
@@ -120,6 +135,8 @@ svn_fs__canonicalize_abspath(const char 
      the root directory case)? */
   if ((newpath[newpath_i - 1] == '/') && (newpath_i > 1))
     newpath[newpath_i - 1] = '\0';
+  else
+    newpath[newpath_i] = '\0';
 
   return newpath;
 }


Reply via email to