Merged various commits to backport needed functionality

commit 0250746db6dff924106ff5ad0e1a9867997f2534
Author: C. Michael Pilato <cmpilato@apache.org>
Date:   Mon Jan 24 21:46:43 2011 +0000

 * subversion/include/private/svn_fspath.h,
 * svnubversion/libsvn_subr/dirent_uri.c
   (svn_urlpath__canonicalize): New function

commit 32aee9b5abcec0d24560ba3a80c6a0f73cea73c1
Author: C. Michael Pilato <cmpilato@apache.org>
Date:   Fri Jan 28 02:15:41 2011 +0000

 use svn_uri_canonicalize in svn_urlpath__canonicalize

commit f8ae3db36633435ba4b8a5921a830a8c6f8ad61d
Author: C. Michael Pilato <cmpilato@apache.org>
Date:   Mon Jan 24 20:59:24 2011 +0000

    * subversion/include/private/svn_fspath.h: new file

commit 8709a6322bce537bc3dd377c3ceb50bcaa78c297
Author: C. Michael Pilato <cmpilato@apache.org>
Date:   Wed Jan 19 20:25:45 2011 +0000

    * subversion/include/svn_dirent_uri.h,
    * subversion/libsvn_subr/dirent_uri.c
      (svn_fspath__canonicalize): New function.

commit fdc615b6722e1f91ed4b1e8b06533c6a0125944c
Author: Bert Huiben <rhuijben@apache.org>
Date:   Thu Sep 17 12:10:41 2009 +0000

    * subversion/include/svn_dirent_uri.h
    (svn_relpath_canonicalize): New function
    * subversion/libsvn_subr/dirent_uri.c
    (path_type_t): Add relpath type
    (internal_style): Add check for relpaths.
    (canonicalize, is_ancestor): Check for relpaths.
    (svn_relpath_canonicalize): New function
    
---
 subversion/include/private/svn_fspath.h |   50 ++++++++++++++++++++++++++++++
 subversion/include/svn_dirent_uri.h     |   34 ++++++++++++++++++++
 subversion/libsvn_subr/dirent_uri.c     |   53 +++++++++++++++++++++++++++++---
 3 files changed, 133 insertions(+), 4 deletions(-)

Index: subversion-1.6.17/subversion/libsvn_subr/dirent_uri.c
===================================================================
--- subversion-1.6.17.orig/subversion/libsvn_subr/dirent_uri.c
+++ subversion-1.6.17/subversion/libsvn_subr/dirent_uri.c
@@ -47,7 +47,8 @@
 /* Path type definition. Used only by internal functions. */
 typedef enum {
   type_uri,
-  type_dirent
+  type_dirent,
+  type_relpath
 } path_type_t;
 
 
@@ -75,8 +76,16 @@ internal_style(path_type_t type, const c
     }
 #endif
 
-  return type == type_uri ? svn_uri_canonicalize(path, pool)
-                          : svn_dirent_canonicalize(path, pool);
+    switch (type)
+    {
+        case type_dirent:
+            return svn_dirent_canonicalize(path, pool);
+        case type_relpath:
+            return svn_relpath_canonicalize(path, pool);
+        case type_uri:
+        default:
+            return svn_uri_canonicalize(path, pool);
+    }
   /* FIXME: Should also remove trailing /.'s, if the style says so. */
 }
 
@@ -281,7 +290,7 @@ canonicalize(path_type_t type, const cha
         }
     }
 
-  if (! url)
+  if (! url && type != type_relpath)
     {
       src = path;
       /* If this is an absolute path, then just copy over the initial
@@ -1194,3 +1203,39 @@ svn_uri_is_canonical(const char *uri, ap
 
   return TRUE;
 }
+
+const char *
+svn_fspath__canonicalize(const char *fspath,
+                         apr_pool_t *pool)
+{
+  if ((fspath[0] == '/') && (fspath[1] == '\0'))
+    return "/";
+
+  return apr_pstrcat(pool, "/", svn_relpath_canonicalize(fspath, pool), NULL);
+}
+
+const char *
+svn_relpath_canonicalize(const char *relpath, apr_pool_t *pool)
+{
+  return canonicalize(type_relpath, relpath, pool);;
+}
+
+
+/* -------------- The urlpath API (see private/svn_fspath.h) ------------- */
+
+const char *
+svn_urlpath__canonicalize(const char *uri,
+                          apr_pool_t *pool)
+{
+  if (svn_path_is_url(uri))
+    {
+      uri = svn_uri_canonicalize(uri, pool);
+    }
+  else
+    {
+      uri = svn_fspath__canonicalize(uri, pool);
+      uri = svn_path_uri_decode(uri, pool);
+      uri = svn_path_uri_encode(uri, pool);
+    }
+  return uri;
+}
Index: subversion-1.6.17/subversion/include/private/svn_fspath.h
===================================================================
--- /dev/null
+++ subversion-1.6.17/subversion/include/private/svn_fspath.h
@@ -0,0 +1,50 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file svn_fspath.h
+ * @brief Implementation of path manipulation functions similar to
+ *        those in svn_dirent_uri.h (which see for details) but for
+ *        the private fspath class of paths.
+ */
+
+#ifndef SVN_FSPATH_H
+#define SVN_FSPATH_H
+
+#include <apr.h>
+#include <apr_pools.h>
+
+#include "svn_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+ /* Like svn_fspath__canonicalize(), but this one accepts both full
+    URLs and URL path-portions. */
+ const char *
+ svn_urlpath__canonicalize(const char *uri, apr_pool_t *pool);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* SVN_FSPATH_H */
Index: subversion-1.6.17/subversion/include/svn_dirent_uri.h
===================================================================
--- subversion-1.6.17.orig/subversion/include/svn_dirent_uri.h
+++ subversion-1.6.17/subversion/include/svn_dirent_uri.h
@@ -218,6 +218,40 @@ svn_boolean_t
 svn_dirent_is_ancestor(const char *path1,
                        const char *path2);
 
+/** This function is similar to svn_relpath_canonicalize(), except
+ * that it returns an fspath (which is essentially just a relpath
+ * tacked onto a leading forward slash).
+ *
+ * The returned fspath may be statically allocated or allocated from
+ * @a pool.
+ *
+ * @since New in 1.7, backported.
+ */
+const char *
+svn_fspath__canonicalize(const char *fspath,
+                         apr_pool_t *pool);
+
+/** Return a new relpath like @a relpath, but transformed such that some types
+ * of relpath specification redundancies are removed.
+ *
+ * This involves collapsing redundant "/./" elements, removing
+ * multiple adjacent separator characters, removing trailing
+ * separator characters, and possibly other semantically inoperative
+ * transformations.
+ *
+ * This functions supports relpaths.
+ *
+ * The returned relpath may be statically allocated or allocated from @a
+ * pool.
+ *
+ * @since New in 1.7, backported.
+ */
+const char *
+svn_relpath_canonicalize(const char *uri,
+                         apr_pool_t *pool);
+
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
