Author: hwright
Date: Wed Dec  5 02:14:40 2012
New Revision: 1417270

URL: http://svn.apache.org/viewvc?rev=1417270&view=rev
Log:
Move the file export functionality to a helper function.

* subversion/libsvn_client/export.c
  (export_file): New.
  (svn_client_export5): Call the new helper.

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

Modified: subversion/trunk/subversion/libsvn_client/export.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/export.c?rev=1417270&r1=1417269&r2=1417270&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/export.c (original)
+++ subversion/trunk/subversion/libsvn_client/export.c Wed Dec  5 02:14:40 2012
@@ -1147,6 +1147,89 @@ get_editor_ev2(const svn_delta_editor_t 
 }
 
 static svn_error_t *
+export_file(const char *from_path_or_url,
+            const char *to_path,
+            struct edit_baton *eb,
+            svn_client__pathrev_t *loc,
+            svn_ra_session_t *ra_session,
+            svn_boolean_t overwrite,
+            apr_pool_t *scratch_pool)
+{
+  apr_hash_t *props;
+  apr_hash_index_t *hi;
+  struct file_baton *fb = apr_pcalloc(scratch_pool, sizeof(*fb));
+  svn_node_kind_t to_kind;
+  svn_boolean_t from_is_url = svn_path_is_url(from_path_or_url);
+
+  if (svn_path_is_empty(to_path))
+    {
+      if (from_is_url)
+        to_path = svn_uri_basename(from_path_or_url, scratch_pool);
+      else
+        to_path = svn_dirent_basename(from_path_or_url, NULL);
+      eb->root_path = to_path;
+    }
+  else
+    {
+      SVN_ERR(append_basename_if_dir(&to_path, from_path_or_url,
+                                     from_is_url, scratch_pool));
+      eb->root_path = to_path;
+    }
+
+  SVN_ERR(svn_io_check_path(to_path, &to_kind, scratch_pool));
+
+  if ((to_kind == svn_node_file || to_kind == svn_node_unknown) &&
+      ! overwrite)
+    return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
+                             _("Destination file '%s' exists, and "
+                               "will not be overwritten unless forced"),
+                             svn_dirent_local_style(to_path, scratch_pool));
+  else if (to_kind == svn_node_dir)
+    return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
+                             _("Destination '%s' exists. Cannot "
+                               "overwrite directory with non-directory"),
+                             svn_dirent_local_style(to_path, scratch_pool));
+
+  /* Since you cannot actually root an editor at a file, we
+   * manually drive a few functions of our editor. */
+
+  /* This is the equivalent of a parentless add_file(). */
+  fb->edit_baton = eb;
+  fb->path = eb->root_path;
+  fb->url = eb->root_url;
+  fb->pool = scratch_pool;
+
+  /* Copied from apply_textdelta(). */
+  SVN_ERR(svn_stream_open_unique(&fb->tmp_stream, &fb->tmppath,
+                                 svn_dirent_dirname(fb->path, scratch_pool),
+                                 svn_io_file_del_none,
+                                 fb->pool, fb->pool));
+
+  /* Step outside the editor-likeness for a moment, to actually talk
+   * to the repository. */
+  /* ### note: the stream will not be closed */
+  SVN_ERR(svn_ra_get_file(ra_session, "", loc->rev,
+                          fb->tmp_stream,
+                          NULL, &props, scratch_pool));
+
+  /* Push the props into change_file_prop(), to update the file_baton
+   * with information. */
+  for (hi = apr_hash_first(scratch_pool, props); hi; hi = apr_hash_next(hi))
+    {
+      const char *propname = svn__apr_hash_index_key(hi);
+      const svn_string_t *propval = svn__apr_hash_index_val(hi);
+
+      SVN_ERR(change_file_prop(fb, propname, propval, scratch_pool));
+    }
+
+  /* And now just use close_file() to do all the keyword and EOL
+   * work, and put the file into place. */
+  SVN_ERR(close_file(fb, NULL, scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
 export_directory(const char *from_path_or_url,
                  const char *to_path,
                  struct edit_baton *eb,
@@ -1287,75 +1370,8 @@ svn_client_export5(svn_revnum_t *result_
 
       if (kind == svn_node_file)
         {
-          apr_hash_t *props;
-          apr_hash_index_t *hi;
-          struct file_baton *fb = apr_pcalloc(pool, sizeof(*fb));
-          svn_node_kind_t to_kind;
-
-          if (svn_path_is_empty(to_path))
-            {
-              if (from_is_url)
-                to_path = svn_uri_basename(from_path_or_url, pool);
-              else
-                to_path = svn_dirent_basename(from_path_or_url, NULL);
-              eb->root_path = to_path;
-            }
-          else
-            {
-              SVN_ERR(append_basename_if_dir(&to_path, from_path_or_url,
-                                             from_is_url, pool));
-              eb->root_path = to_path;
-            }
-
-          SVN_ERR(svn_io_check_path(to_path, &to_kind, pool));
-
-          if ((to_kind == svn_node_file || to_kind == svn_node_unknown) &&
-              ! overwrite)
-            return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
-                                     _("Destination file '%s' exists, and "
-                                       "will not be overwritten unless 
forced"),
-                                     svn_dirent_local_style(to_path, pool));
-          else if (to_kind == svn_node_dir)
-            return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
-                                     _("Destination '%s' exists. Cannot "
-                                       "overwrite directory with 
non-directory"),
-                                     svn_dirent_local_style(to_path, pool));
-
-          /* Since you cannot actually root an editor at a file, we
-           * manually drive a few functions of our editor. */
-
-          /* This is the equivalent of a parentless add_file(). */
-          fb->edit_baton = eb;
-          fb->path = eb->root_path;
-          fb->url = eb->root_url;
-          fb->pool = pool;
-
-          /* Copied from apply_textdelta(). */
-          SVN_ERR(svn_stream_open_unique(&fb->tmp_stream, &fb->tmppath,
-                                         svn_dirent_dirname(fb->path, pool),
-                                         svn_io_file_del_none,
-                                         fb->pool, fb->pool));
-
-          /* Step outside the editor-likeness for a moment, to actually talk
-           * to the repository. */
-          /* ### note: the stream will not be closed */
-          SVN_ERR(svn_ra_get_file(ra_session, "", loc->rev,
-                                  fb->tmp_stream,
-                                  NULL, &props, pool));
-
-          /* Push the props into change_file_prop(), to update the file_baton
-           * with information. */
-          for (hi = apr_hash_first(pool, props); hi; hi = apr_hash_next(hi))
-            {
-              const char *propname = svn__apr_hash_index_key(hi);
-              const svn_string_t *propval = svn__apr_hash_index_val(hi);
-
-              SVN_ERR(change_file_prop(fb, propname, propval, pool));
-            }
-
-          /* And now just use close_file() to do all the keyword and EOL
-           * work, and put the file into place. */
-          SVN_ERR(close_file(fb, NULL, pool));
+          SVN_ERR(export_file(from_path_or_url, to_path, eb, loc, ra_session,
+                              overwrite, pool));
         }
       else if (kind == svn_node_dir)
         {


Reply via email to