You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2010/06/29 10:28:30 UTC

svn commit: r958872 - in /subversion/trunk/subversion: include/ libsvn_subr/ tests/ tests/libsvn_client/ tests/libsvn_ra_local/ tests/libsvn_subr/ tests/libsvn_wc/

Author: rhuijben
Date: Tue Jun 29 08:28:29 2010
New Revision: 958872

URL: http://svn.apache.org/viewvc?rev=958872&view=rev
Log:
Following up on the introduction of svn_uri_get_dirent_from_file_url(),
introduce svn_uri_get_file_url_from_dirent() to make it easier to convert
a dirent in a canonical url in a compatible way.

* subversion/include/svn_dirent_uri.h
  (svn_uri_get_dirent_from_file_url): Add '*' for doxygen.
  (svn_uri_get_file_url_from_dirent): New function.

* subversion/libsvn_subr/dirent_uri.c
  (svn_uri_get_file_url_from_dirent): New function.

* subversion/tests/libsvn_client/client-test.c
  (test_patch): Use svn_uri_get_file_url_from_dirent instead
    of using local variant.

* subversion/tests/libsvn_ra_local/ra-local-test.c
  (make_and_open_local_repos, check_split_url):
    Use svn_uri_get_file_url_from_dirent().

* subversion/tests/libsvn_subr/dirent_uri-test.c
  (test_dirent_from_file_url,
   test_dirent_from_file_url_errors): Fix test output.
  (test_file_url_from_dirent): New function.
  (test_funcs): Add test_file_url_from_dirent.

* subversion/tests/libsvn_wc/pristine-store-test.c
  (create_repos_and_wc): Use svn_uri_get_file_url_from_dirent().

* subversion/tests/svn_test_fs.c
  (svn_test__current_directory_url): Remove function.

* subversion/tests/svn_test_fs.h
  (svn_test__current_directory_url): Remove function.

Modified:
    subversion/trunk/subversion/include/svn_dirent_uri.h
    subversion/trunk/subversion/libsvn_subr/dirent_uri.c
    subversion/trunk/subversion/tests/libsvn_client/client-test.c
    subversion/trunk/subversion/tests/libsvn_ra_local/ra-local-test.c
    subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c
    subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c
    subversion/trunk/subversion/tests/svn_test_fs.c
    subversion/trunk/subversion/tests/svn_test_fs.h

Modified: subversion/trunk/subversion/include/svn_dirent_uri.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_dirent_uri.h?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_dirent_uri.h (original)
+++ subversion/trunk/subversion/include/svn_dirent_uri.h Tue Jun 29 08:28:29 2010
@@ -779,7 +779,7 @@ svn_dirent_is_under_root(char **full_pat
                          const char *path,
                          apr_pool_t *pool);
 
-/* Set @a *dirent to the path corresponding to the file:// URL @a url, using
+/** Set @a *dirent to the path corresponding to the file:// URL @a url, using
  * the platform-specific file:// rules.
  *
  * @since New in 1.7.
@@ -789,6 +789,16 @@ svn_uri_get_dirent_from_file_url(const c
                                  const char *url,
                                  apr_pool_t *pool);
 
+/** Set @a *url to a file:// URL, corresponding to @a dirent using the
+ * platform specific dirent and file:// rules.
+ *
+ * @since New in 1.7.
+ */
+svn_error_t *
+svn_uri_get_file_url_from_dirent(const char **url,
+                                 const char *dirent,
+                                 apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: subversion/trunk/subversion/libsvn_subr/dirent_uri.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/dirent_uri.c?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/dirent_uri.c (original)
+++ subversion/trunk/subversion/libsvn_subr/dirent_uri.c Tue Jun 29 08:28:29 2010
@@ -2386,3 +2386,31 @@ svn_uri_get_dirent_from_file_url(const c
 #endif /* SVN_USE_DOS_PATHS */
   return SVN_NO_ERROR;
 }
+
+svn_error_t *
+svn_uri_get_file_url_from_dirent(const char **url,
+                                 const char *dirent,
+                                 apr_pool_t *pool)
+{
+  assert(svn_dirent_is_canonical(dirent, pool));
+
+  SVN_ERR(svn_dirent_get_absolute(&dirent, dirent, pool));
+
+  dirent = svn_path_uri_encode(dirent, pool);
+
+#ifndef SVN_USE_DOS_PATHS
+  *url = apr_pstrcat(pool, "file://", dirent, NULL);
+#else
+  if (dirent[0] == '/')
+    {
+      /* Handle UNC paths */
+      assert(dirent[1] != '/'); /* Not absolute! */
+
+      *url = apr_pstrcat(pool, "file://", dirent+1, NULL);
+    }
+  else
+    *url = apr_pstrcat(pool, "file:///", dirent, NULL);
+#endif
+
+  return SVN_NO_ERROR;
+}

Modified: subversion/trunk/subversion/tests/libsvn_client/client-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_client/client-test.c?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_client/client-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_client/client-test.c Tue Jun 29 08:28:29 2010
@@ -342,16 +342,8 @@ test_patch(const svn_test_opts_t *opts,
 
   /* Check out the HEAD revision */
   SVN_ERR(svn_dirent_get_absolute(&cwd, "", pool));
-
-  if (cwd[0] == '/')
-    repos_url = apr_pstrcat(pool, "file://", cwd,
-                            "/test-patch-repos", NULL);
-  else
-    /* On Windows CWD is always in "X:/..." style */
-    repos_url = apr_pstrcat(pool, "file:///", cwd,
-                            "/test-patch-repos", NULL);
-
-  repos_url = svn_uri_canonicalize(repos_url, pool);
+  SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, "test-patch-repos",
+                                           pool));
 
   /* Put wc inside an unversioned directory.  Checking out a 1.7 wc
      directly inside a 1.6 wc doesn't work reliably, an intervening

Modified: subversion/trunk/subversion/tests/libsvn_ra_local/ra-local-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_ra_local/ra-local-test.c?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_ra_local/ra-local-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_ra_local/ra-local-test.c Tue Jun 29 08:28:29 2010
@@ -55,7 +55,7 @@ make_and_open_local_repos(svn_ra_session
   SVN_ERR(svn_test__create_repos(&repos, repos_name, opts, pool));
   SVN_ERR(svn_ra_initialize(pool));
 
-  SVN_ERR(svn_test__current_directory_url(&url, repos_name, pool));
+  SVN_ERR(svn_uri_get_file_url_from_dirent(&url, repos_name, pool));
 
   SVN_ERR(svn_ra_open3(session,
                        url,
@@ -223,7 +223,7 @@ check_split_url(const char *repos_path,
   /* Create a filesystem and repository */
   SVN_ERR(svn_test__create_repos(&repos, repos_path, opts, pool));
 
-  SVN_ERR(svn_test__current_directory_url(&root_url, repos_path, pool));
+  SVN_ERR(svn_uri_get_file_url_from_dirent(&root_url, repos_path, pool));
   if (in_repos_path)
     url = apr_pstrcat(pool, root_url, in_repos_path, NULL);
   else

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=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c Tue Jun 29 08:28:29 2010
@@ -2709,8 +2709,8 @@ test_dirent_from_file_url(apr_pool_t *po
 
       if (strcmp(result, tests[i].result))
         return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
-                                 "svn_relpath_internal_style(\"%s\") returned "
-                                 "\"%s\" expected \"%s\"",
+                                 "svn_uri_get_dirent_from_file_url(\"%s\") "
+                                 "returned \"%s\" expected \"%s\"",
                                  tests[i].url, result, tests[i].result);
     }
 
@@ -2740,14 +2740,56 @@ test_dirent_from_file_url_errors(apr_poo
 
       if (err == NULL)
         return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
-                                 "svn_relpath_internal_style(\"%s\") did "
-                                 "not return an error",
+                                 "svn_uri_get_dirent_from_file_url(\"%s\") "
+                                 "returned \"%s\" expected \"%s\"",
                                  bad_file_urls[i]);
       svn_error_clear(err);
     }
 
   return SVN_NO_ERROR;
 }
+
+static svn_error_t *
+test_file_url_from_dirent(apr_pool_t *pool)
+{
+  struct {
+    const char *dirent;
+    const char *result;
+  } tests[] = {
+#ifdef SVN_USE_DOS_PATHS
+    { "C:/file",                   "file:///C:/file" },
+    { "C:/",                       "file:///C:/" },
+    { "C:/File#$",                 "file:///C:/File%23$" },
+    /* We can't check these as svn_dirent_get_absolute() won't work
+       on shares that don't exist */
+    /*{ "//server/share",            "file://server/share" },
+    { "//server/share/file",       "file://server/share/file" },*/
+#else
+    { "/a/b",                      "file:///a/b" }
+    { "/a",                        "file:///a" }
+    { "/",                         "file:///" },
+    { "/File#$",                   "file:///File%23$" },
+#endif
+  };
+  int i;
+
+  for (i = 0; i < COUNT_OF(tests); i++)
+    {
+      const char *result;
+      
+      SVN_ERR(svn_uri_get_file_url_from_dirent(&result, tests[i].dirent,
+                                               pool));
+
+      if (strcmp(result, tests[i].result))
+        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+                                 "svn_uri_get_file_url_from_dirent(\"%s\") "
+                                 "returned \"%s\" expected \"%s\"",
+                                 tests[i].dirent, result, tests[i].result);
+    }
+
+  return SVN_NO_ERROR;
+}
+
 
 /* The test table.  */
 
@@ -2844,5 +2886,7 @@ struct svn_test_descriptor_t test_funcs[
                    "test svn_uri_get_dirent_from_file_url"),
     SVN_TEST_PASS2(test_dirent_from_file_url_errors,
                    "test svn_uri_get_dirent_from_file_url errors"),
+    SVN_TEST_PASS2(test_file_url_from_dirent,
+                   "test svn_uri_get_file_url_from_dirent"),
     SVN_TEST_NULL
   };

Modified: subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Tue Jun 29 08:28:29 2010
@@ -86,7 +86,7 @@ create_repos_and_wc(const char **repos_u
     svn_repos_t *repos;
 
     SVN_ERR(svn_test__create_repos(&repos, repos_path, opts, pool));
-    SVN_ERR(svn_test__current_directory_url(repos_url, repos_path, pool));
+    SVN_ERR(svn_uri_get_file_url_from_dirent(repos_url, repos_path, pool));
   }
 
   /* Create a WC */

Modified: subversion/trunk/subversion/tests/svn_test_fs.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test_fs.c?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/svn_test_fs.c (original)
+++ subversion/trunk/subversion/tests/svn_test_fs.c Tue Jun 29 08:28:29 2010
@@ -231,33 +231,6 @@ svn_test__create_repos(svn_repos_t **rep
   return SVN_NO_ERROR;
 }
 
-
-/* Helper function.  Set URL to a "file://" url for the current directory,
-   suffixed by the forward-slash-style relative path SUFFIX, performing all
-   allocation in POOL. */
-svn_error_t *
-svn_test__current_directory_url(const char **url,
-                                const char *suffix,
-                                apr_pool_t *pool)
-{
-  /* 8KB is a lot, but it almost guarantees that any path will fit. */
-  const char* curdir;
-  const char *unencoded_url;
-
-  SVN_ERR(svn_dirent_get_absolute(&curdir, "", pool));
-
-  unencoded_url = apr_psprintf(pool, "file://%s%s%s%s",
-                               (curdir[0] != '/') ? "/" : "",
-                               curdir,
-                               (suffix[0] && suffix[0] != '/') ? "/" : "",
-                               suffix);
-
-  *url = svn_path_uri_encode(unencoded_url, pool);
-
-  return SVN_NO_ERROR;
-}
-
-
 svn_error_t *
 svn_test__stream_to_string(svn_stringbuf_t **string,
                            svn_stream_t *stream,

Modified: subversion/trunk/subversion/tests/svn_test_fs.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test_fs.h?rev=958872&r1=958871&r2=958872&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/svn_test_fs.h (original)
+++ subversion/trunk/subversion/tests/svn_test_fs.h Tue Jun 29 08:28:29 2010
@@ -73,14 +73,6 @@ svn_test__create_repos(svn_repos_t **rep
                        const svn_test_opts_t *opts,
                        apr_pool_t *pool);
 
-/* Set URL to a "file://" url for the current directory, suffixed by the
-   forward-slash-style relative path SUFFIX, performing all allocation
-   in POOL. */
-svn_error_t *
-svn_test__current_directory_url(const char **url,
-                                const char *suffix,
-                                apr_pool_t *pool);
-
 /* Read all data from a generic read STREAM, and return it in STRING.
    Allocate the svn_stringbuf_t in POOL.  (All data in STRING will be
    dup'ed from STREAM using POOL too.) */