Author: julianfoad
Date: Wed Oct 12 15:34:31 2011
New Revision: 1182435

URL: http://svn.apache.org/viewvc?rev=1182435&view=rev
Log:
Hoist out two rather similar chunks of compatibility code in two different
places. This is a move towards combining them.

* subversion/libsvn_client/info.c
  (ra_stat_compatible): New function, factored out of ...
  (svn_client_info3): ... here.

* subversion/libsvn_client/list.c
  (ra_stat_compatible): New function, factored out of ...
  (svn_client_list2): ... here.

Modified:
    subversion/trunk/subversion/libsvn_client/info.c
    subversion/trunk/subversion/libsvn_client/list.c

Modified: subversion/trunk/subversion/libsvn_client/info.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/info.c?rev=1182435&r1=1182434&r2=1182435&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/info.c (original)
+++ subversion/trunk/subversion/libsvn_client/info.c Wed Oct 12 15:34:31 2011
@@ -256,6 +256,75 @@ wc_info_receiver(void *baton,
                                  abspath_or_url, &client_info, scratch_pool);
 }
 
+/* Like svn_ra_stat() but with a compatibility hack for pre-1.2 svnserve. */
+static svn_error_t *
+ra_stat_compatible(svn_ra_session_t *ra_session,
+                   svn_revnum_t rev,
+                   svn_dirent_t **dirent_p,
+                   apr_uint32_t dirent_fields,
+                   svn_client_ctx_t *ctx,
+                   apr_pool_t *pool)
+{
+  const char *repos_root_URL, *url;
+  svn_error_t *err;
+  svn_dirent_t *the_ent;
+
+  SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_root_URL, pool));
+  SVN_ERR(svn_ra_get_session_url(ra_session, &url, pool));
+
+  err = svn_ra_stat(ra_session, "", rev, &the_ent, pool);
+
+  /* svn_ra_stat() will work against old versions of mod_dav_svn, but
+     not old versions of svnserve.  In the case of a pre-1.2 svnserve,
+     catch the specific error it throws:*/
+  if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED)
+    {
+      /* Fall back to pre-1.2 strategy for fetching dirent's URL. */
+      svn_node_kind_t url_kind;
+      svn_ra_session_t *parent_ra_session;
+      apr_hash_t *parent_ents;
+      const char *parent_url, *base_name;
+
+      if (strcmp(url, repos_root_URL) == 0)
+        {
+          /* In this universe, there's simply no way to fetch
+             information about the repository's root directory! */
+          return err;
+        }
+
+      svn_error_clear(err);
+
+      SVN_ERR(svn_ra_check_path(ra_session, "", rev, &url_kind, pool));
+      if (url_kind == svn_node_none)
+        return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
+                                 _("URL '%s' non-existent in revision %ld"),
+                                 url, rev);
+
+      /* Open a new RA session to the item's parent. */
+      svn_uri_split(&parent_url, &base_name, url, pool);
+      SVN_ERR(svn_client__open_ra_session_internal(&parent_ra_session, NULL,
+                                                   parent_url, NULL,
+                                                   NULL, FALSE, TRUE,
+                                                   ctx, pool));
+
+      /* Get all parent's entries, and find the item's dirent in the hash. */
+      SVN_ERR(svn_ra_get_dir2(parent_ra_session, &parent_ents, NULL, NULL,
+                              "", rev, dirent_fields, pool));
+      the_ent = apr_hash_get(parent_ents, base_name, APR_HASH_KEY_STRING);
+      if (the_ent == NULL)
+        return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
+                                 _("URL '%s' non-existent in revision %ld"),
+                                 url, rev);
+    }
+  else if (err)
+    {
+      return svn_error_trace(err);
+    }
+
+  *dirent_p = the_ent;
+  return SVN_NO_ERROR;
+}
+
 svn_error_t *
 svn_client_info3(const char *abspath_or_url,
                  const svn_opt_revision_t *peg_revision,
@@ -275,7 +344,7 @@ svn_client_info3(const char *abspath_or_
   const char *repos_root_URL, *repos_UUID;
   svn_lock_t *lock;
   svn_boolean_t related;
-  const char *parent_url, *base_name;
+  const char *base_name;
   svn_dirent_t *the_ent;
   svn_client_info2_t *info;
   svn_error_t *err;
@@ -310,60 +379,26 @@ svn_client_info3(const char *abspath_or_
   SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_root_URL, pool));
   SVN_ERR(svn_ra_get_uuid2(ra_session, &repos_UUID, pool));
 
-  svn_uri_split(&parent_url, &base_name, url, pool);
+  svn_uri_split(NULL, &base_name, url, pool);
 
   /* Get the dirent for the URL itself. */
-  err = svn_ra_stat(ra_session, "", rev, &the_ent, pool);
-
-  /* svn_ra_stat() will work against old versions of mod_dav_svn, but
-     not old versions of svnserve.  In the case of a pre-1.2 svnserve,
-     catch the specific error it throws:*/
+  err = ra_stat_compatible(ra_session, rev, &the_ent, DIRENT_FIELDS,
+                           ctx, pool);
   if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED)
     {
-      /* Fall back to pre-1.2 strategy for fetching dirent's URL. */
-      svn_node_kind_t url_kind;
-      svn_ra_session_t *parent_ra_session;
-      apr_hash_t *parent_ents;
-
       svn_error_clear(err);
 
-      if (strcmp(url, repos_root_URL) == 0)
-        {
-          /* In this universe, there's simply no way to fetch
-             information about the repository's root directory!
-             If we're recursing, degrade gracefully: rather than
-             throw an error, return no information about the
-             repos root. */
-          if (depth > svn_depth_empty)
-            goto pre_1_2_recurse;
-
-          /* Otherwise, we really are stuck.  Better tell the user
-             what's going on. */
-          return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
-                                   _("Server does not support retrieving "
-                                     "information about the repository root"));
-        }
-
-      SVN_ERR(svn_ra_check_path(ra_session, "", rev, &url_kind, pool));
-      if (url_kind == svn_node_none)
-        return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
-                                 _("URL '%s' non-existent in revision %ld"),
-                                 url, rev);
-
-      /* Open a new RA session to the item's parent. */
-      SVN_ERR(svn_client__open_ra_session_internal(&parent_ra_session, NULL,
-                                                   parent_url, NULL,
-                                                   NULL, FALSE, TRUE,
-                                                   ctx, pool));
-
-      /* Get all parent's entries, and find the item's dirent in the hash. */
-      SVN_ERR(svn_ra_get_dir2(parent_ra_session, &parent_ents, NULL, NULL,
-                              "", rev, DIRENT_FIELDS, pool));
-      the_ent = apr_hash_get(parent_ents, base_name, APR_HASH_KEY_STRING);
-      if (the_ent == NULL)
-        return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
-                                 _("URL '%s' non-existent in revision %ld"),
-                                 url, rev);
+      /* If we're recursing, degrade gracefully: rather than
+         throw an error, return no information about the
+         repos root. */
+      if (depth > svn_depth_empty)
+        goto pre_1_2_recurse;
+
+      /* Otherwise, we really are stuck.  Better tell the user
+         what's going on. */
+      return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+                               _("Server does not support retrieving "
+                                 "information about the repository root"));
     }
   else if (err)
     {

Modified: subversion/trunk/subversion/libsvn_client/list.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/list.c?rev=1182435&r1=1182434&r2=1182435&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/list.c (original)
+++ subversion/trunk/subversion/libsvn_client/list.c Wed Oct 12 15:34:31 2011
@@ -121,42 +121,21 @@ get_dir_contents(apr_uint32_t dirent_fie
   return SVN_NO_ERROR;
 }
 
-svn_error_t *
-svn_client_list2(const char *path_or_url,
-                 const svn_opt_revision_t *peg_revision,
-                 const svn_opt_revision_t *revision,
-                 svn_depth_t depth,
-                 apr_uint32_t dirent_fields,
-                 svn_boolean_t fetch_locks,
-                 svn_client_list_func_t list_func,
-                 void *baton,
-                 svn_client_ctx_t *ctx,
-                 apr_pool_t *pool)
+/* Like svn_ra_stat() but with a compatibility hack for pre-1.2 svnserve. */
+static svn_error_t *
+ra_stat_compatible(svn_ra_session_t *ra_session,
+                   svn_revnum_t rev,
+                   svn_dirent_t **dirent_p,
+                   apr_uint32_t dirent_fields,
+                   svn_client_ctx_t *ctx,
+                   apr_pool_t *pool)
 {
-  svn_ra_session_t *ra_session;
-  svn_revnum_t rev;
-  svn_dirent_t *dirent;
-  const char *url;
-  const char *repos_root;
-  const char *fs_path;
+  const char *repos_root, *url;
   svn_error_t *err;
-  apr_hash_t *locks;
-
-  /* We use the kind field to determine if we should recurse, so we
-     always need it. */
-  dirent_fields |= SVN_DIRENT_KIND;
-
-  /* Get an RA plugin for this filesystem object. */
-  SVN_ERR(svn_client__ra_session_from_path(&ra_session, &rev,
-                                           &url, path_or_url, NULL,
-                                           peg_revision,
-                                           revision, ctx, pool));
+  svn_dirent_t *dirent;
 
   SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_root, pool));
-
-  SVN_ERR(svn_client__path_relative_to_root(&fs_path, ctx->wc_ctx, url,
-                                            repos_root, TRUE, ra_session,
-                                            pool, pool));
+  SVN_ERR(svn_ra_get_session_url(ra_session, &url, pool));
 
   err = svn_ra_stat(ra_session, "", rev, &dirent, pool);
 
@@ -240,6 +219,49 @@ svn_client_list2(const char *path_or_url
   else if (err)
     return svn_error_trace(err);
 
+  *dirent_p = dirent;
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_client_list2(const char *path_or_url,
+                 const svn_opt_revision_t *peg_revision,
+                 const svn_opt_revision_t *revision,
+                 svn_depth_t depth,
+                 apr_uint32_t dirent_fields,
+                 svn_boolean_t fetch_locks,
+                 svn_client_list_func_t list_func,
+                 void *baton,
+                 svn_client_ctx_t *ctx,
+                 apr_pool_t *pool)
+{
+  svn_ra_session_t *ra_session;
+  svn_revnum_t rev;
+  svn_dirent_t *dirent;
+  const char *url;
+  const char *repos_root;
+  const char *fs_path;
+  svn_error_t *err;
+  apr_hash_t *locks;
+
+  /* We use the kind field to determine if we should recurse, so we
+     always need it. */
+  dirent_fields |= SVN_DIRENT_KIND;
+
+  /* Get an RA plugin for this filesystem object. */
+  SVN_ERR(svn_client__ra_session_from_path(&ra_session, &rev,
+                                           &url, path_or_url, NULL,
+                                           peg_revision,
+                                           revision, ctx, pool));
+
+  SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_root, pool));
+
+  SVN_ERR(svn_client__path_relative_to_root(&fs_path, ctx->wc_ctx, url,
+                                            repos_root, TRUE, ra_session,
+                                            pool, pool));
+
+  SVN_ERR(ra_stat_compatible(ra_session, rev, &dirent, dirent_fields,
+                             ctx, pool));
   if (! dirent)
     return svn_error_createf(SVN_ERR_FS_NOT_FOUND, NULL,
                              _("URL '%s' non-existent in revision %ld"),


Reply via email to