Author: julianfoad
Date: Fri Jun 17 15:07:26 2011
New Revision: 1136908
URL: http://svn.apache.org/viewvc?rev=1136908&view=rev
Log:
Re-implement *_is_ancestor() in terms of *_skip_ancestor(), reducing the
amount of code and weeding out some bugs such as this one (which was
untested):
svn_dirent_is_ancestor (X:, X:/) returned TRUE instead of FALSE
and two cases that were tested but the test expectations were inconsistent
with *_skip_ancestor().
* subversion/libsvn_subr/dirent_uri.c
(is_ancestor): Remove.
(uri_skip_ancestor): New, extracted from ...
(svn_uri_skip_ancestor): ... here.
(svn_dirent_is_ancestor, svn_relpath__is_ancestor, svn_uri__is_ancestor):
Re-implement in terms of their respective _skip_ancestor functions.
* subversion/tests/libsvn_subr/dirent_uri-test.c
(test_dirent_is_ancestor, test_uri_is_ancestor): Correct some
expectations: "//srv" is not an ancestor of "//srv/shr/fld" and
"http://" is not an ancestor of "http://test" according to the rules.
Add a new test case for "X:" versus "X:/".
Modified:
subversion/trunk/subversion/libsvn_subr/dirent_uri.c
subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c
Modified: subversion/trunk/subversion/libsvn_subr/dirent_uri.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/dirent_uri.c?rev=1136908&r1=1136907&r2=1136908&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/dirent_uri.c (original)
+++ subversion/trunk/subversion/libsvn_subr/dirent_uri.c Fri Jun 17 15:07:26
2011
@@ -819,43 +819,6 @@ is_child(path_type_t type, const char *p
return NULL;
}
-/* FIXME: no doc string */
-static svn_boolean_t
-is_ancestor(path_type_t type, const char *path1, const char *path2)
-{
- apr_size_t path1_len;
-
- /* If path1 is empty and path2 is not absolute, then path1 is an ancestor. */
- if (SVN_PATH_IS_EMPTY(path1))
- switch (type)
- {
- case type_dirent:
- return !dirent_is_rooted(path2);
- case type_relpath:
- return TRUE;
- case type_uri:
- return FALSE;
- default:
- return path2[0] != '/';
- }
-
- /* If path1 is a prefix of path2, then:
- - If path1 ends in a path separator,
- - If the paths are of the same length
- OR
- - path2 starts a new path component after the common prefix,
- then path1 is an ancestor. */
- path1_len = strlen(path1);
- if (strncmp(path1, path2, path1_len) == 0)
- return path1[path1_len - 1] == '/'
-#ifdef SVN_USE_DOS_PATHS
- || ((type == type_dirent) && path1[path1_len - 1] == ':')
-#endif
- || (path2[path1_len] == '/' || path2[path1_len] == '\0');
-
- return FALSE;
-}
-
/**** Public API functions ****/
@@ -1434,30 +1397,6 @@ svn_uri__is_child(const char *parent_uri
return relpath;
}
-svn_boolean_t
-svn_dirent_is_ancestor(const char *parent_dirent, const char *child_dirent)
-{
- return is_ancestor(type_dirent, parent_dirent, child_dirent);
-}
-
-svn_boolean_t
-svn_relpath__is_ancestor(const char *parent_relpath, const char *child_relpath)
-{
- assert(relpath_is_canonical(parent_relpath));
- assert(relpath_is_canonical(child_relpath));
-
- return is_ancestor(type_relpath, parent_relpath, child_relpath);
-}
-
-svn_boolean_t
-svn_uri__is_ancestor(const char *parent_uri, const char *child_uri)
-{
- assert(svn_uri_is_canonical(parent_uri, NULL));
- assert(svn_uri_is_canonical(child_uri, NULL));
-
- return is_ancestor(type_uri, parent_uri, child_uri);
-}
-
const char *
svn_dirent_skip_ancestor(const char *parent_dirent,
const char *child_dirent)
@@ -1536,10 +1475,10 @@ svn_relpath_skip_ancestor(const char *pa
}
-const char *
-svn_uri_skip_ancestor(const char *parent_uri,
- const char *child_uri,
- apr_pool_t *result_pool)
+/* */
+static const char *
+uri_skip_ancestor(const char *parent_uri,
+ const char *child_uri)
{
apr_size_t len = strlen(parent_uri);
@@ -1553,11 +1492,40 @@ svn_uri_skip_ancestor(const char *parent
return ""; /* parent_uri == child_uri */
if (child_uri[len] == '/')
- return svn_path_uri_decode(child_uri + len + 1, result_pool);
+ return child_uri + len + 1;
return NULL;
}
+const char *
+svn_uri_skip_ancestor(const char *parent_uri,
+ const char *child_uri,
+ apr_pool_t *result_pool)
+{
+ const char *result = uri_skip_ancestor(parent_uri, child_uri);
+
+ return result ? svn_path_uri_decode(result, result_pool) : NULL;
+}
+
+svn_boolean_t
+svn_dirent_is_ancestor(const char *parent_dirent, const char *child_dirent)
+{
+ return svn_dirent_skip_ancestor(parent_dirent, child_dirent) != NULL;
+}
+
+svn_boolean_t
+svn_relpath__is_ancestor(const char *parent_relpath, const char *child_relpath)
+{
+ return svn_relpath_skip_ancestor(parent_relpath, child_relpath) != NULL;
+}
+
+svn_boolean_t
+svn_uri__is_ancestor(const char *parent_uri, const char *child_uri)
+{
+ return uri_skip_ancestor(parent_uri, child_uri) != NULL;
+}
+
+
svn_boolean_t
svn_dirent_is_absolute(const char *dirent)
{
Modified: subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c?rev=1136908&r1=1136907&r2=1136908&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c Fri Jun 17
15:07:26 2011
@@ -1362,9 +1362,10 @@ test_dirent_is_ancestor(apr_pool_t *pool
{ "//srv/shr", "//srv", FALSE},
{ "//srv/shr", "//srv/shr/fld", TRUE },
{ "//srv/s r", "//srv/s r/fld", TRUE },
- { "//srv", "//srv/shr/fld", TRUE },
+ { "//srv", "//srv/shr/fld", FALSE },
{ "//srv/shr/fld", "//srv/shr", FALSE },
{ "//srv/shr/fld", "//srv2/shr/fld", FALSE },
+ { "X:", "X:/", FALSE},
{ "X:/", "X:/", TRUE},
{ "X:/foo", "X:/", FALSE},
{ "X:/", "X:/foo", TRUE},
@@ -1446,7 +1447,7 @@ test_uri_is_ancestor(apr_pool_t *pool)
{ "http://test", "http://test/foo", TRUE},
{ "http://test", "file://test/foo", FALSE},
{ "http://test", "http://testf", FALSE},
- { "http://", "http://test", TRUE},
+ { "http://", "http://test", FALSE},
};
for (i = 0; i < COUNT_OF(tests); i++)