You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2012/03/02 21:36:01 UTC

svn commit: r1296439 - /subversion/trunk/subversion/libsvn_client/util.c

Author: hwright
Date: Fri Mar  2 20:36:00 2012
New Revision: 1296439

URL: http://svn.apache.org/viewvc?rev=1296439&view=rev
Log:
Refactor out some common code.

* subversion/libsvn_client/util.c
  (rationalize_shim_path): New.
  (fetch_props_func, fetch_kind_func, fetch_base_func): Use the new helper.

Modified:
    subversion/trunk/subversion/libsvn_client/util.c

Modified: subversion/trunk/subversion/libsvn_client/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/util.c?rev=1296439&r1=1296438&r2=1296439&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/util.c (original)
+++ subversion/trunk/subversion/libsvn_client/util.c Fri Mar  2 20:36:00 2012
@@ -248,6 +248,34 @@ struct shim_callbacks_baton
 };
 
 static svn_error_t *
+rationalize_shim_path(const char **local_abspath,
+                      struct shim_callbacks_baton *scb,
+                      const char *path,
+                      apr_pool_t *result_pool,
+                      apr_pool_t *scratch_pool)
+{
+  if (svn_path_is_url(path))
+    {
+      /* This is a copyfrom URL */
+      const char *wcroot_abspath;
+      const char *wcroot_url;
+      const char *relpath;
+
+      SVN_ERR(svn_wc__get_wc_root(&wcroot_abspath, scb->wc_ctx,
+                                  scb->anchor_abspath,
+                                  scratch_pool, scratch_pool));
+      SVN_ERR(svn_wc__node_get_url(&wcroot_url, scb->wc_ctx, wcroot_abspath,
+                                   scratch_pool, scratch_pool));
+      relpath = svn_uri_skip_ancestor(wcroot_url, path, scratch_pool);
+      *local_abspath = svn_dirent_join(wcroot_abspath, relpath, result_pool);
+    }
+  else
+    *local_abspath = svn_dirent_join(scb->anchor_abspath, path, result_pool);
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
 fetch_props_func(apr_hash_t **props,
                  void *baton,
                  const char *path,
@@ -266,23 +294,8 @@ fetch_props_func(apr_hash_t **props,
       return SVN_NO_ERROR;
     }
 
-  if (svn_path_is_url(path))
-    {
-      /* This is a copyfrom URL */
-      const char *wcroot_abspath;
-      const char *wcroot_url;
-      const char *relpath;
-
-      SVN_ERR(svn_wc__get_wc_root(&wcroot_abspath, scb->wc_ctx,
-                                  scb->anchor_abspath,
-                                  scratch_pool, scratch_pool));
-      SVN_ERR(svn_wc__node_get_url(&wcroot_url, scb->wc_ctx, wcroot_abspath,
-                                   scratch_pool, scratch_pool));
-      relpath = svn_uri_skip_ancestor(wcroot_url, path, scratch_pool);
-      local_abspath = svn_dirent_join(wcroot_abspath, relpath, scratch_pool);
-    }
-  else
-    local_abspath = svn_dirent_join(scb->anchor_abspath, path, scratch_pool);
+  SVN_ERR(rationalize_shim_path(&local_abspath, scb, path, scratch_pool,
+                                scratch_pool));
 
   SVN_ERR(svn_wc_get_pristine_props(props, scb->wc_ctx, local_abspath,
                                     result_pool, scratch_pool));
@@ -312,23 +325,8 @@ fetch_kind_func(svn_kind_t *kind,
       return SVN_NO_ERROR;
     }
 
-  if (svn_path_is_url(path))
-    {
-      /* This is a copyfrom URL */
-      const char *wcroot_abspath;
-      const char *wcroot_url;
-      const char *relpath;
-
-      SVN_ERR(svn_wc__get_wc_root(&wcroot_abspath, scb->wc_ctx,
-                                  scb->anchor_abspath,
-                                  scratch_pool, scratch_pool));
-      SVN_ERR(svn_wc__node_get_url(&wcroot_url, scb->wc_ctx, wcroot_abspath,
-                                   scratch_pool, scratch_pool));
-      relpath = svn_uri_skip_ancestor(wcroot_url, path, scratch_pool);
-      local_abspath = svn_dirent_join(wcroot_abspath, relpath, scratch_pool);
-    }
-  else
-    local_abspath = svn_dirent_join(scb->anchor_abspath, path, scratch_pool);
+  SVN_ERR(rationalize_shim_path(&local_abspath, scb, path, scratch_pool,
+                                scratch_pool));
 
   SVN_ERR(svn_wc_read_kind(&node_kind, scb->wc_ctx, local_abspath, FALSE,
                            scratch_pool));
@@ -359,23 +357,8 @@ fetch_base_func(const char **filename,
       return SVN_NO_ERROR;
     }
 
-  if (svn_path_is_url(path))
-    {
-      /* This is a copyfrom URL */
-      const char *wcroot_abspath;
-      const char *wcroot_url;
-      const char *relpath;
-
-      SVN_ERR(svn_wc__get_wc_root(&wcroot_abspath, scb->wc_ctx,
-                                  scb->anchor_abspath,
-                                  scratch_pool, scratch_pool));
-      SVN_ERR(svn_wc__node_get_url(&wcroot_url, scb->wc_ctx, wcroot_abspath,
-                                   scratch_pool, scratch_pool));
-      relpath = svn_uri_skip_ancestor(wcroot_url, path, scratch_pool);
-      local_abspath = svn_dirent_join(wcroot_abspath, relpath, scratch_pool);
-    }
-  else
-    local_abspath = svn_dirent_join(scb->anchor_abspath, path, scratch_pool);
+  SVN_ERR(rationalize_shim_path(&local_abspath, scb, path, scratch_pool,
+                                scratch_pool));
 
   err = svn_wc_get_pristine_contents2(&pristine_stream, scb->wc_ctx,
                                       local_abspath, scratch_pool,