You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2012/11/28 02:05:23 UTC

svn commit: r1414492 - in /subversion/branches/in-repo-authz/subversion: include/svn_path.h libsvn_client/cmdline.c libsvn_subr/path.c tests/libsvn_subr/path-test.c

Author: breser
Date: Wed Nov 28 01:05:22 2012
New Revision: 1414492

URL: http://svn.apache.org/viewvc?rev=1414492&view=rev
Log:
On the in-repo-authz branch: Make two functions for dealing with repos relative
urls public APIs.

* subversion/libsvn_client/cmdline.c
  (arg_is_repos_relative_url,resolve_repos_relative_url): Removed
  (svn_client_args_to_target_array2): Use svn_path_is_repos_relative_url() and
    svn_path_resolve_repos_relative_url()

* subversion/libsvn_subr/path.c
  subversion/include/svn_path.h
  (svn_path_is_repos_relative_url,svn_path_resolve_repos_relative_url): Add, they
    are almost exactly the same as the old private functions that used to be in
    cmdline.c

* subversion/libsvn_subr/path-test.c
  (test_path_is_repos_relative_url, test_path_resolve_repos_relative_url): Add.
  (test_funcs): Add test_path_is_repos_relative_url() and
    test_path_resolve_repos_relative_url() to the tests to run.


Modified:
    subversion/branches/in-repo-authz/subversion/include/svn_path.h
    subversion/branches/in-repo-authz/subversion/libsvn_client/cmdline.c
    subversion/branches/in-repo-authz/subversion/libsvn_subr/path.c
    subversion/branches/in-repo-authz/subversion/tests/libsvn_subr/path-test.c

Modified: subversion/branches/in-repo-authz/subversion/include/svn_path.h
URL: http://svn.apache.org/viewvc/subversion/branches/in-repo-authz/subversion/include/svn_path.h?rev=1414492&r1=1414491&r2=1414492&view=diff
==============================================================================
--- subversion/branches/in-repo-authz/subversion/include/svn_path.h (original)
+++ subversion/branches/in-repo-authz/subversion/include/svn_path.h Wed Nov 28 01:05:22 2012
@@ -670,6 +670,58 @@ svn_path_cstring_to_utf8(const char **pa
 
 /** @} */
 
+
+/** Repository relative URLs
+ *
+ * @defgroup svn_path_repos_relative_urls Repository relative URLs
+ * @{
+ */
+
+
+/**
+ * Return true iff @a path is a repository-relative URL: specifically that
+ * it starts with the characters "^/"
+ *
+ * @a path is in UTF-8 encoding.
+ *
+ * Does not check whether @a path is a properly URI-encoded, canonical, or
+ * valid in any other way.
+ *
+ * @since New in 1.8.
+ */
+svn_boolean_t
+svn_path_is_repos_relative_url(const char *path);
+
+/**
+ * Set @a absolute_url to the absolute URL represented by @a relative_url
+ * relative to @a repos_root_url.  @a absolute_url will be allocated in
+ * @a pool.
+ *
+ * @a absolute_url will end with a peg revision specifier if @a relative_url
+ * did.
+ *
+ * @a relative_url is in repository-relative syntax: "^/[REL-URL][@PEG]"
+ *
+ * @a repos_root_url is the absolute url of the repository root.
+ *
+ * All strings are in UTF-8 encoding.
+ *
+ * @a repos_root_url and @a relative_url do not have to be properly
+ * URI-encoded, canonical, or valid in any other way.  The caller is expected
+ * to perform canonicalization on @a absolute_url after the call to the
+ * function.
+ *
+ * @since New in 1.8.
+ */
+svn_error_t *
+svn_path_resolve_repos_relative_url(const char **absolute_url,
+                                    const char *relative_url,
+                                    const char *repos_root_url,
+                                    apr_pool_t *pool);
+
+
+/** @} */
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: subversion/branches/in-repo-authz/subversion/libsvn_client/cmdline.c
URL: http://svn.apache.org/viewvc/subversion/branches/in-repo-authz/subversion/libsvn_client/cmdline.c?rev=1414492&r1=1414491&r2=1414492&view=diff
==============================================================================
--- subversion/branches/in-repo-authz/subversion/libsvn_client/cmdline.c (original)
+++ subversion/branches/in-repo-authz/subversion/libsvn_client/cmdline.c Wed Nov 28 01:05:22 2012
@@ -43,51 +43,6 @@
 
 #define DEFAULT_ARRAY_SIZE 5
 
-/* Return true iff ARG is a repository-relative URL: specifically that
- * it starts with the characters "^/".
- * ARG is in UTF-8 encoding.
- * Do not check whether ARG is properly URI-encoded, canonical, or valid
- * in any other way. */
-static svn_boolean_t
-arg_is_repos_relative_url(const char *arg)
-{
-  return (0 == strncmp("^/", arg, 2));
-}
-
-/* Set *ABSOLUTE_URL to the absolute URL represented by RELATIVE_URL
- * relative to REPOS_ROOT_URL.
- * *ABSOLUTE_URL will end with a peg revision specifier if RELATIVE_URL did.
- * RELATIVE_URL is in repository-relative syntax:
- * "^/[REL-URL][@PEG]",
- * REPOS_ROOT_URL is the absolute URL of the repository root.
- * All strings are in UTF-8 encoding.
- * Allocate *ABSOLUTE_URL in POOL.
- *
- * REPOS_ROOT_URL and RELATIVE_URL do not have to be properly URI-encoded,
- * canonical, or valid in any other way.  The caller is expected to perform
- * canonicalization on *ABSOLUTE_URL after the call to the function.
- */
-static svn_error_t *
-resolve_repos_relative_url(const char **absolute_url,
-                           const char *relative_url,
-                           const char *repos_root_url,
-                           apr_pool_t *pool)
-{
-  if (! arg_is_repos_relative_url(relative_url))
-    return svn_error_createf(SVN_ERR_BAD_URL, NULL,
-                             _("Improper relative URL '%s'"),
-                             relative_url);
-
-  /* No assumptions are made about the canonicalization of the input
-   * arguments, it is presumed that the output will be canonicalized after
-   * this function, which will remove any duplicate path separator.
-   */
-  *absolute_url = apr_pstrcat(pool, repos_root_url, relative_url + 1,
-                              (char *)NULL);
-
-  return SVN_NO_ERROR;
-}
-
 
 /* Attempt to find the repository root url for TARGET, possibly using CTX for
  * authentication.  If one is found and *ROOT_URL is not NULL, then just check
@@ -189,7 +144,7 @@ svn_client_args_to_target_array2(apr_arr
       SVN_ERR(svn_utf_cstring_to_utf8(&utf8_target,
                                       raw_target, pool));
 
-      if (arg_is_repos_relative_url(utf8_target))
+      if (svn_path_is_repos_relative_url(utf8_target))
         rel_url_found = TRUE;
 
       APR_ARRAY_PUSH(input_targets, const char *) = utf8_target;
@@ -204,7 +159,7 @@ svn_client_args_to_target_array2(apr_arr
           const char *utf8_target = APR_ARRAY_IDX(known_targets,
                                                   i, const char *);
 
-          if (arg_is_repos_relative_url(utf8_target))
+          if (svn_path_is_repos_relative_url(utf8_target))
             rel_url_found = TRUE;
 
           APR_ARRAY_PUSH(input_targets, const char *) = utf8_target;
@@ -220,7 +175,7 @@ svn_client_args_to_target_array2(apr_arr
       /* Relative urls will be canonicalized when they are resolved later in
        * the function
        */
-      if (arg_is_repos_relative_url(utf8_target))
+      if (svn_path_is_repos_relative_url(utf8_target))
         {
           APR_ARRAY_PUSH(output_targets, const char *) = utf8_target;
         }
@@ -367,7 +322,7 @@ svn_client_args_to_target_array2(apr_arr
           const char *target = APR_ARRAY_IDX(output_targets, i,
                                              const char *);
 
-          if (arg_is_repos_relative_url(target))
+          if (svn_path_is_repos_relative_url(target))
             {
               const char *abs_target;
               const char *true_target;
@@ -376,8 +331,9 @@ svn_client_args_to_target_array2(apr_arr
               SVN_ERR(svn_opt__split_arg_at_peg_revision(&true_target, &peg_rev,
                                                          target, pool));
 
-              SVN_ERR(resolve_repos_relative_url(&abs_target, true_target,
-                                                 root_url, pool));
+              SVN_ERR(svn_path_resolve_repos_relative_url(&abs_target,
+                                                          true_target,
+                                                          root_url, pool));
 
               SVN_ERR(svn_opt__arg_canonicalize_url(&true_target, abs_target,
                                                     pool));

Modified: subversion/branches/in-repo-authz/subversion/libsvn_subr/path.c
URL: http://svn.apache.org/viewvc/subversion/branches/in-repo-authz/subversion/libsvn_subr/path.c?rev=1414492&r1=1414491&r2=1414492&view=diff
==============================================================================
--- subversion/branches/in-repo-authz/subversion/libsvn_subr/path.c (original)
+++ subversion/branches/in-repo-authz/subversion/libsvn_subr/path.c Wed Nov 28 01:05:22 2012
@@ -1281,3 +1281,34 @@ svn_path_splitext(const char **path_root
   if (path_ext)
     *path_ext = "";
 }
+
+
+/* Repository relative URLs (^/). */
+
+svn_boolean_t
+svn_path_is_repos_relative_url(const char *path)
+{
+  return (0 == strncmp("^/", path, 2));
+}
+
+svn_error_t *
+svn_path_resolve_repos_relative_url(const char **absolute_url,
+                                    const char *relative_url,
+                                    const char *repos_root_url,
+                                    apr_pool_t *pool)
+{
+  if (! svn_path_is_repos_relative_url(relative_url))
+    return svn_error_createf(SVN_ERR_BAD_URL, NULL,
+                             _("Improper relative URL '%s'"),
+                             relative_url);
+
+  /* No assumptions are made about the canonicalization of the inut
+   * arguments, it is presumed that the output will be canonicalized after
+   * this function, which will remove any duplicate path separator.
+   */
+  *absolute_url = apr_pstrcat(pool, repos_root_url, relative_url + 1,
+                              (char *)NULL);
+
+  return SVN_NO_ERROR;
+}
+

Modified: subversion/branches/in-repo-authz/subversion/tests/libsvn_subr/path-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/in-repo-authz/subversion/tests/libsvn_subr/path-test.c?rev=1414492&r1=1414491&r2=1414492&view=diff
==============================================================================
--- subversion/branches/in-repo-authz/subversion/tests/libsvn_subr/path-test.c (original)
+++ subversion/branches/in-repo-authz/subversion/tests/libsvn_subr/path-test.c Wed Nov 28 01:05:22 2012
@@ -1625,6 +1625,71 @@ test_path_condense_targets(apr_pool_t *p
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_path_is_repos_relative_url(apr_pool_t *pool)
+{
+  int i;
+  struct {
+    const char* path;
+    svn_boolean_t result;
+  } tests[] = {
+    { "^/A",           TRUE },
+    { "http://host/A", FALSE },
+    { "/A/B",          FALSE },
+  };
+
+  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
+    {
+      svn_boolean_t result = svn_path_is_repos_relative_url(tests[i].path);
+
+      if (tests[i].result != result)
+        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+                                 "svn_path_is_repos_relative_url(\"%s\")"
+                                 " returned \"%s\" expected \"%s\"",
+                                 tests[i].path,
+                                 result ? "TRUE" : "FALSE",
+                                 tests[i].result ? "TRUE" : "FALSE");
+    }
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+test_path_resolve_repos_relative_url(apr_pool_t *pool)
+{
+  int i;
+  struct {
+    const char *relative_url;
+    const char *repos_root_url;
+    const char *absolute_url;
+  } tests[] = {
+    { "^/A", "file:///Z/X", "file:///Z/X/A" },
+    { "^/A", "file:///Z/X/", "file:///Z/X//A" }, /* doesn't canonicalize */
+    { "^/A@2", "file:///Z/X", "file:///Z/X/A@2" }, /* peg rev */
+    { "^/A", "/Z/X", "/Z/X/A" }, /* doesn't verify repos_root is URL */
+  };
+
+  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
+    {
+      const char *result;
+
+      SVN_ERR(svn_path_resolve_repos_relative_url(&result,
+                                                  tests[i].relative_url,
+                                                  tests[i].repos_root_url,
+                                                  pool));
+
+      if (strcmp(tests[i].absolute_url,result))
+        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+                                 "svn_path_resolve_repos_relative_url(\"%s\","
+                                 "\"%s\") returned \"%s\" expected \"%s\"",
+                                 tests[i].relative_url,
+                                 tests[i].repos_root_url,
+                                 result, tests[i].absolute_url);
+    }
+  
+  return SVN_NO_ERROR;
+}
+
 
 /* local define to support XFail-ing tests on Windows/Cygwin only */
 #ifdef SVN_USE_DOS_PATHS
@@ -1689,5 +1754,9 @@ struct svn_test_descriptor_t test_funcs[
                    "test svn_path_internal_style"),
     SVN_TEST_PASS2(test_path_condense_targets,
                    "test svn_path_condense_targets"),
+    SVN_TEST_PASS2(test_path_is_repos_relative_url,
+                   "test svn_path_is_repos_relative_url"),
+    SVN_TEST_PASS2(test_path_resolve_repos_relative_url,
+                   "test svn_path_resolve_repos_relative_url"),
     SVN_TEST_NULL
   };