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

[PATCH] partly fix for issue 1711: make svn_path_decompose support Windows paths

From: Lieven Govaerts <lgo_at_mobsol.be>
Date: 2006-09-24 18:41:15 CEST

Hi,

I'm trying to fix issue 1711 by making all svn_path functions support
Windows paths.

Attached you'll find a patch for svn_path_decompose. Basically I've
reimplemented that function as a wrapper around apr_filepath_root.

There's no new regression test because this function is currently only
used in the 'mucc' tool in contrib. I did expand the unit tests for this
function.

There's one more function left to convert to be able to close issue
1711, that'll come in the next hours/days.

regards,

Lieven.

[[[
Make svn_path_decompose support Windows paths. Basically this is a
reimplementation of this function, but now based on apr_filepath_root.

* subversion/libsvn_subr/path.c
   (svn_path_decompose): make this function a wrapper around
    apr_filepath_root

* subversion/tests/libsvn_subr/path-test.c
   (test_decompose): added extra testcases for Window paths and special
    characters.
]]]

Index: subversion/libsvn_subr/path.c
===================================================================
--- subversion/libsvn_subr/path.c (revision 21621)
+++ subversion/libsvn_subr/path.c (working copy)
@@ -732,6 +732,9 @@
                    apr_pool_t *pool)
 {
   apr_size_t i, oldi;
+ apr_status_t status;
+ const char *rel_path_apr, *root_path;
+ svn_error_t *err;
 
   apr_array_header_t *components =
     apr_array_make(pool, 1, sizeof(const char *));
@@ -741,30 +744,33 @@
   if (SVN_PATH_IS_EMPTY(path))
     return components; /* ### Should we return a "" component? */
 
- /* If PATH is absolute, store the '/' as the first component. */
- i = oldi = 0;
- if (path[i] == '/')
+ /* Check if PATH is absolute */
+ err = svn_path_cstring_from_utf8(&rel_path_apr, path, pool);
+ if (err)
     {
- char dirsep = '/';
+ svn_error_clear(err);
+ return NULL;
+ }
+ status = apr_filepath_root(&root_path, &rel_path_apr, 0, pool);
 
- *((const char **) apr_array_push(components))
- = apr_pstrmemdup(pool, &dirsep, sizeof(dirsep));
+ /* If PATH is absolute, store the root path as the first component. */
+ if (status != APR_ERELATIVE)
+ *((const char **) apr_array_push(components)) = root_path;
 
- i++;
- oldi++;
- if (path[i] == '\0') /* path is a single '/' */
- return components;
- }
+ if (rel_path_apr[0] == '\0') /* PATH is a root path */
+ return components;
 
+ /* Now handle the relative part of the path */
+ i = oldi = 0;
   do
     {
- if ((path[i] == '/') || (path[i] == '\0'))
+ if ((rel_path_apr[i] == '/') || (rel_path_apr[i] == '\0'))
         {
- if (SVN_PATH_IS_PLATFORM_EMPTY(path + oldi, i - oldi))
+ if (SVN_PATH_IS_PLATFORM_EMPTY(rel_path_apr + oldi, i - oldi))
             *((const char **) apr_array_push(components)) = SVN_EMPTY_PATH;
           else
             *((const char **) apr_array_push(components))
- = apr_pstrmemdup(pool, path + oldi, i - oldi);
+ = apr_pstrmemdup(pool, rel_path_apr + oldi, i - oldi);
 
           i++;
           oldi = i; /* skipping past the dirsep */
@@ -772,7 +778,7 @@
         }
       i++;
     }
- while (path[i-1]);
+ while (rel_path_apr[i-1]);
 
   return components;
 }
Index: subversion/tests/libsvn_subr/path-test.c
===================================================================
--- subversion/tests/libsvn_subr/path-test.c (revision 21625)
+++ subversion/tests/libsvn_subr/path-test.c (working copy)
@@ -695,9 +695,19 @@
     "/foo", "/", "foo", NULL,
     "/foo/bar", "/", "foo", "bar", NULL,
     "foo/bar", "foo", "bar", NULL,
+ "/ab/df", "/", "ab", "df", NULL,
 
     /* Are these canonical? Should the middle bits produce SVN_EMPTY_PATH? */
     "foo/bar", "foo", "bar", NULL,
+#if defined(WIN32)
+ "X:/", "X:/", NULL,
+ "X:/abc", "X:/", "abc", NULL,
+ "X:/abc/def", "X:/", "abc", "def", NULL,
+ "X:", "X:", NULL,
+ "X:abc", "X:", "abc", NULL,
+ "X:abc/def", "X:", "abc", "def", NULL,
+ "X:ab/df", "X:", "ab", "df", NULL,
+#endif
     NULL,
   };
   int i = 0;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Sep 24 18:41:35 2006

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.