Author: julianfoad
Date: Thu Jun 16 11:14:21 2011
New Revision: 1136379
URL: http://svn.apache.org/viewvc?rev=1136379&view=rev
Log:
Simplify the semantics of svn_dirent_skip_ancestor() to return NULL if the
supposed child is not in fact a child.
* subversion/include/svn_dirent_uri.h,
subversion/libsvn_subr/dirent_uri.c
(svn_dirent_skip_ancestor): Return NULL if 'child' is not a child.
* subversion/tests/cmdline/entries-dump.c
(print_dir): Handle the case where the 'child' is not in fact a child.
* subversion/tests/libsvn_subr/dirent_uri-test.c
(test_dirent_skip_ancestor): Adjust the test accordingly.
* subversion/svn/cl.h,
subversion/svn/util.c
(svn_cl__local_style_skip_ancestor): New function, combining the old
semantics of svn_dirent_skip_ancestor() with more behaviour that all
callers want.
* subversion/svn/info-cmd.c
(print_info_xml, print_info): Use svn_cl__local_style_skip_ancestor().
* subversion/svn/notify.c
(notify): Same.
* subversion/svn/propget-cmd.c
(print_properties): Same.
* subversion/svn/update-cmd.c
(print_update_summary): Same.
Modified:
subversion/trunk/subversion/include/svn_dirent_uri.h
subversion/trunk/subversion/libsvn_subr/dirent_uri.c
subversion/trunk/subversion/svn/cl.h
subversion/trunk/subversion/svn/info-cmd.c
subversion/trunk/subversion/svn/notify.c
subversion/trunk/subversion/svn/propget-cmd.c
subversion/trunk/subversion/svn/update-cmd.c
subversion/trunk/subversion/svn/util.c
subversion/trunk/subversion/tests/cmdline/entries-dump.c
subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c
Modified: subversion/trunk/subversion/include/svn_dirent_uri.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_dirent_uri.h?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_dirent_uri.h (original)
+++ subversion/trunk/subversion/include/svn_dirent_uri.h Thu Jun 16 11:14:21
2011
@@ -629,14 +629,11 @@ svn_uri_is_ancestor(const char *parent_u
/** Return the relative path part of @a child_dirent that is below
* @a parent_dirent, or just "" if @a parent_dirent is equal to
- * @a child_dirent. If @a child_dirent is not below @a parent_dirent,
- * return @a child_dirent completely.
+ * @a child_dirent. If @a child_dirent is not below or equal to
+ * @a parent_dirent, return NULL.
*
- * This function assumes @a parent_dirent and @a child_dirent are both
- * absolute or relative in the same way.
- *
- * ### Returning the child in the no-match case is a bad idea when the
- * paths are relative; can be useful when they are absolute.
+ * If one of @a parent_dirent and @a child_dirent is absolute and
+ * the other relative, return NULL.
*
* @since New in 1.7.
*/
Modified: subversion/trunk/subversion/libsvn_subr/dirent_uri.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/dirent_uri.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/dirent_uri.c (original)
+++ subversion/trunk/subversion/libsvn_subr/dirent_uri.c Thu Jun 16 11:14:21
2011
@@ -1467,27 +1467,22 @@ svn_dirent_skip_ancestor(const char *par
apr_size_t root_len;
if (0 != memcmp(parent_dirent, child_dirent, len))
- return child_dirent; /* parent_dirent is no ancestor of child_dirent */
+ return NULL; /* parent_dirent is no ancestor of child_dirent */
if (child_dirent[len] == 0)
return ""; /* parent_dirent == child_dirent */
root_len = dirent_root_length(child_dirent, strlen(child_dirent));
if (root_len > len)
- return child_dirent; /* Different root */
+ return NULL; /* Different root */
- if (len == 1 && child_dirent[0] == '/')
- return child_dirent + 1;
+ if (root_len == len)
+ return child_dirent + len;
if (child_dirent[len] == '/')
return child_dirent + len + 1;
-#ifdef SVN_USE_DOS_PATHS
- if (root_len == len && len > 0 && child_dirent[len-1])
- return child_dirent + len;
-#endif
-
- return child_dirent;
+ return NULL;
}
const char *
Modified: subversion/trunk/subversion/svn/cl.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/cl.h?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/cl.h (original)
+++ subversion/trunk/subversion/svn/cl.h Thu Jun 16 11:14:21 2011
@@ -823,6 +823,16 @@ svn_cl__opt_parse_path(svn_opt_revision_
svn_error_t *
svn_cl__assert_homogeneous_target_type(const apr_array_header_t *targets);
+/* Return a copy of PATH, converted to the local path style, skipping
+ * PARENT_PATH if it is non-null and is a parent of or equal to PATH.
+ *
+ * This function assumes PARENT_PATH and PATH are both absolute "dirents"
+ * or both relative "dirents". */
+const char *
+svn_cl__local_style_skip_ancestor(const char *parent_path,
+ const char *path,
+ apr_pool_t *pool);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Modified: subversion/trunk/subversion/svn/info-cmd.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/info-cmd.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/info-cmd.c (original)
+++ subversion/trunk/subversion/svn/info-cmd.c Thu Jun 16 11:14:21 2011
@@ -94,12 +94,10 @@ print_info_xml(void *baton,
else
rev_str = apr_pstrdup(pool, _("Resource is not under version control."));
- if (path_prefix)
- target = svn_dirent_skip_ancestor(path_prefix, target);
-
/* "<entry ...>" */
svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "entry",
- "path", svn_dirent_local_style(target, pool),
+ "path", svn_cl__local_style_skip_ancestor(
+ path_prefix, target, pool),
"kind", svn_cl__node_kind_str_xml(info->kind),
"revision", rev_str,
NULL);
@@ -262,11 +260,9 @@ print_info(void *baton,
{
const char *path_prefix = baton;
- if (path_prefix)
- target = svn_dirent_skip_ancestor(path_prefix, target);
-
SVN_ERR(svn_cmdline_printf(pool, _("Path: %s\n"),
- svn_dirent_local_style(target, pool)));
+ svn_cl__local_style_skip_ancestor(
+ path_prefix, target, pool)));
/* ### remove this someday: it's only here for cmdline output
compatibility with svn 1.1 and older. */
Modified: subversion/trunk/subversion/svn/notify.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/notify.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/notify.c (original)
+++ subversion/trunk/subversion/svn/notify.c Thu Jun 16 11:14:21 2011
@@ -116,13 +116,11 @@ notify(void *baton, const svn_wc_notify_
else
{
if (n->path_prefix)
- path_local = svn_dirent_skip_ancestor(n->path_prefix, n->path);
- else if (nb->path_prefix)
- path_local = svn_dirent_skip_ancestor(nb->path_prefix, n->path);
- else
- path_local = n->path;
-
- path_local = svn_dirent_local_style(path_local, pool);
+ path_local = svn_cl__local_style_skip_ancestor(n->path_prefix, n->path,
+ pool);
+ else /* skip nb->path_prefix, if it's non-null */
+ path_local = svn_cl__local_style_skip_ancestor(nb->path_prefix,
n->path,
+ pool);
}
switch (n->action)
Modified: subversion/trunk/subversion/svn/propget-cmd.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/propget-cmd.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/propget-cmd.c (original)
+++ subversion/trunk/subversion/svn/propget-cmd.c Thu Jun 16 11:14:21 2011
@@ -135,12 +135,8 @@ print_properties(svn_stream_t *out,
/* Print the file name. */
if (! is_url)
- {
- if (path_prefix)
- filename = svn_dirent_skip_ancestor(path_prefix, filename);
-
- filename = svn_dirent_local_style(filename, iterpool);
- }
+ filename = svn_cl__local_style_skip_ancestor(path_prefix, filename,
+ iterpool);
/* In verbose mode, print exactly same as "proplist" does;
* otherwise, print a brief header. */
Modified: subversion/trunk/subversion/svn/update-cmd.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/update-cmd.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/update-cmd.c (original)
+++ subversion/trunk/subversion/svn/update-cmd.c Thu Jun 16 11:14:21 2011
@@ -83,14 +83,14 @@ print_update_summary(apr_array_header_t
/* Convert to an absolute path if it's not already. */
if (! svn_dirent_is_absolute(path))
SVN_ERR(svn_dirent_get_absolute(&path, path, iterpool));
- path = svn_dirent_local_style(svn_dirent_skip_ancestor(path_prefix,
- path), iterpool);
/* Print an update summary for this target, removing the current
working directory prefix from PATH (if PATH is at or under
$CWD), and converting the path to local style for display. */
SVN_ERR(svn_cmdline_printf(iterpool, _(" Updated '%s' to r%ld.\n"),
- path, rev));
+ svn_cl__local_style_skip_ancestor(
+ path_prefix, path, iterpool),
+ rev));
}
svn_pool_destroy(iterpool);
Modified: subversion/trunk/subversion/svn/util.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/util.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/util.c (original)
+++ subversion/trunk/subversion/svn/util.c Thu Jun 16 11:14:21 2011
@@ -1388,3 +1388,16 @@ svn_cl__assert_homogeneous_target_type(c
"targets"));
return err;
}
+
+const char *
+svn_cl__local_style_skip_ancestor(const char *parent_path,
+ const char *path,
+ apr_pool_t *pool)
+{
+ const char *relpath = NULL;
+
+ if (parent_path)
+ relpath = svn_dirent_skip_ancestor(parent_path, path);
+
+ return svn_dirent_local_style(relpath ? relpath : path, pool);
+}
Modified: subversion/trunk/subversion/tests/cmdline/entries-dump.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/entries-dump.c?rev=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/entries-dump.c (original)
+++ subversion/trunk/subversion/tests/cmdline/entries-dump.c Thu Jun 16
11:14:21 2011
@@ -177,17 +177,19 @@ print_dir(const char *local_abspath,
apr_pool_t *scratch_pool)
{
struct directory_walk_baton *bt = walk_baton;
+ const char *path;
if (kind != svn_node_dir)
return SVN_NO_ERROR;
- printf("%s\n",
- svn_dirent_local_style(
- svn_dirent_join(bt->prefix_path,
- svn_dirent_skip_ancestor(bt->root_abspath,
- local_abspath),
- scratch_pool),
- scratch_pool));
+ /* If LOCAL_ABSPATH a child of or equal to ROOT_ABSPATH, then display
+ a relative path starting with PREFIX_PATH. */
+ path = svn_dirent_skip_ancestor(bt->root_abspath, local_abspath);
+ if (path)
+ path = svn_dirent_join(bt->prefix_path, path, scratch_pool);
+ else
+ path = local_abspath;
+ printf("%s\n", svn_dirent_local_style(path, scratch_pool));
return SVN_NO_ERROR;
}
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=1136379&r1=1136378&r2=1136379&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c Thu Jun 16
11:14:21 2011
@@ -1476,18 +1476,18 @@ test_dirent_skip_ancestor(apr_pool_t *po
const char *result;
} tests[] = {
{ "/foo", "/foo/bar", "bar"},
- { "/foo/bar", "/foot/bar", "/foot/bar"},
+ { "/foo/bar", "/foot/bar", NULL },
{ "/foo", "/foo", ""},
- { "/foo", "/foot", "/foot"},
- { "/foot", "/foo", "/foo"},
+ { "/foo", "/foot", NULL },
+ { "/foot", "/foo", NULL },
{ "", "foo", "foo"},
- { "", "/foo", "/foo"},
+ { "", "/foo", NULL },
{ "/", "/foo", "foo"},
- { "/foo/bar/bla", "/foo/bar", "/foo/bar"},
+ { "/foo/bar/bla", "/foo/bar", NULL },
{ "/foo/bar", "/foo/bar/bla", "bla"},
- { "foo/bar", "foo", "foo"},
- { "/foo/bar", "foo", "foo"},
- { "/", "bar/bla", "bar/bla"},
+ { "foo/bar", "foo", NULL },
+ { "/foo/bar", "foo", NULL },
+ { "/", "bar/bla", NULL },
#ifdef SVN_USE_DOS_PATHS
{ "A:/foo", "A:/foo/bar", "bar"},
{ "A:/foo", "A:/foot", "A:/foot"},
@@ -1506,7 +1506,9 @@ test_dirent_skip_ancestor(apr_pool_t *po
const char* retval;
retval = svn_dirent_skip_ancestor(tests[i].path1, tests[i].path2);
- if (strcmp(tests[i].result, retval))
+ if ((tests[i].result == NULL)
+ ? (retval != NULL)
+ : (retval == NULL || strcmp(tests[i].result, retval) != 0))
return svn_error_createf(
SVN_ERR_TEST_FAILED, NULL,
"svn_dirent_skip_ancestor (%s, %s) returned %s instead of %s",