subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r932335 - in /subversion/trunk/subversion: include/svn_repos.h libsvn_repos/deprecated.c libsvn_repos/dump.c
Date Fri, 09 Apr 2010 10:17:58 GMT
Author: rhuijben
Date: Fri Apr  9 10:17:58 2010
New Revision: 932335

URL: http://svn.apache.org/viewvc?rev=932335&view=rev
Log:
Make it easier to use some of the common repository management functions
from a GUI by providing per revision progress via a callback instead
of a stream. This allows applications to provide better progress than
just showing a text window on these lengthy operations.

* subversion/include/svn_repos.h
  (svn_repos_progress_func_t): New typedef.
  (svn_repos_verify_fs2): New function.
  (svn_repos_verify_fs): Deprecate function.
  (svn_repos_dump_fs3): New function.
  (svn_repos_dump_fs2): Deprecate function.

* subversion/libsvn_repos/deprecated.c
  (progress_baton): New struct.
  (repos_progress_handler): New function.
  (svn_repos_dump_fs2): New function.
  (svn_repos_verify_fs): New function.

* subversion/libsvn_repos/dump.c
  (edit_baton): Store function and baton instead of stream.
  (dump_node): Call progress handler instead of writing to stream.
  (get_dump_editor): Accept progress handler instead of stream.
  (svn_repos_dump_fs2): Rename to ...
  (svn_repos_dump_fs3): ... this and accept progress function instead
    of a stream. Call handler instead of writing localized output.
  (svn_repos_verify_fs): Rename to ...
  (svn_repos_verify_fs2): ... this and accept progress function instead of
    of a stream. Call handler instead of writing localized output.

Modified:
    subversion/trunk/subversion/include/svn_repos.h
    subversion/trunk/subversion/libsvn_repos/deprecated.c
    subversion/trunk/subversion/libsvn_repos/dump.c

Modified: subversion/trunk/subversion/include/svn_repos.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_repos.h?rev=932335&r1=932334&r2=932335&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_repos.h (original)
+++ subversion/trunk/subversion/include/svn_repos.h Fri Apr  9 10:17:58 2010
@@ -2115,6 +2115,15 @@ enum svn_repos_load_uuid
   svn_repos_load_uuid_force
 };
 
+/** Callback for providing per revision progress while dumping or verifying
+ *  the repository.
+ *
+ * @since New in 1.7. */
+typedef svn_error_t *(*svn_repos_progress_func_t)(void *baton,
+                                                  svn_revnum_t rev,
+                                                  const char *warning_text,
+                                                  apr_pool_t *scratch_pool);
+
 
 /**
  * Verify the contents of the file system in @a repos.
@@ -2126,12 +2135,31 @@ enum svn_repos_load_uuid
  * revision 0.  If @a end_rev is #SVN_INVALID_REVNUM, then verify
  * through the @c HEAD revision.
  *
+ * For every verified revision call @a progress_func with @a rev set to
+ * the verified revision and @a warning_text @c NULL. For warnings call @a
+ * progress_func with @a warning_text set.
+ *
  * If @a cancel_func is not @c NULL, call it periodically with @a
  * cancel_baton as argument to see if the caller wishes to cancel the
  * verification.
+ */
+svn_error_t *
+svn_repos_verify_fs2(svn_repos_t *repos,
+                     svn_revnum_t start_rev,
+                     svn_revnum_t end_rev,
+                     svn_repos_progress_func_t progress,
+                     void *progress_baton,
+                     svn_cancel_func_t cancel,
+                     void *cancel_baton,
+                     apr_pool_t *scratch_pool);
+
+/**
+ * Similar to svn_repos_verify_fs2(), but with a feedback_stream instead of
+ * handling feedback via the progress_func handler
  *
  * @since New in 1.5.
  */
+SVN_DEPRECATED
 svn_error_t *
 svn_repos_verify_fs(svn_repos_t *repos,
                     svn_stream_t *feedback_stream,
@@ -2141,7 +2169,6 @@ svn_repos_verify_fs(svn_repos_t *repos,
                     void *cancel_baton,
                     apr_pool_t *pool);
 
-
 /**
  * Dump the contents of the filesystem within already-open @a repos into
  * writable @a dumpstream.  Begin at revision @a start_rev, and dump every
@@ -2165,12 +2192,37 @@ svn_repos_verify_fs(svn_repos_t *repos,
  * be done with full plain text.  A dump with @a use_deltas set cannot
  * be loaded by Subversion 1.0.x.
  *
+ * For every dumped revision call @a progress_func with @a rev set to the
+ * dumped revision and @a warning_text @c NULL. For warnings call @a
+ * progress_func with @a warning_text.
+ *
  * If @a cancel_func is not @c NULL, it is called periodically with
  * @a cancel_baton as argument to see if the client wishes to cancel
  * the dump.
  *
+ * @since New in 1.7.
+ */
+svn_error_t *
+svn_repos_dump_fs3(svn_repos_t *repos,
+                   svn_stream_t *dumpstream,
+                   svn_revnum_t start_rev,
+                   svn_revnum_t end_rev,
+                   svn_boolean_t incremental,
+                   svn_boolean_t use_deltas,
+                   svn_repos_progress_func_t progress_func,
+                   void *progress_baton,
+                   svn_cancel_func_t cancel_func,
+                   void *cancel_baton,
+                   apr_pool_t *scratch_pool);
+
+/**
+ * Similar to svn_repos_dump_fs3(), but with a feedback_stream instead of
+ * handling feedback via the progress_func handler
+ *
  * @since New in 1.1.
+ * @deprecated Provided for backward compatibility with the 1.6 API.
  */
+SVN_DEPRECATED
 svn_error_t *
 svn_repos_dump_fs2(svn_repos_t *repos,
                    svn_stream_t *dumpstream,
@@ -2183,7 +2235,6 @@ svn_repos_dump_fs2(svn_repos_t *repos,
                    void *cancel_baton,
                    apr_pool_t *pool);
 
-
 /**
  * Similar to svn_repos_dump_fs2(), but with the @a use_deltas
  * parameter always set to @c FALSE.

Modified: subversion/trunk/subversion/libsvn_repos/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/deprecated.c?rev=932335&r1=932334&r2=932335&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_repos/deprecated.c Fri Apr  9 10:17:58 2010
@@ -428,6 +428,95 @@ svn_repos_dump_fs(svn_repos_t *repos,
                             cancel_baton, pool);
 }
 
+/* Baton for repos_progress_handler */
+struct progress_baton
+{
+  svn_boolean_t dumping;
+  svn_stream_t *feedback_stream;
+};
+
+/* Implementation of svn_repos_progress_func_t to wrap the output to a
+   response stream for svn_repos_dump_fs2() and svn_repos_verify_fs() */
+static svn_error_t *
+repos_progress_handler(void * baton,
+                       svn_revnum_t revision,
+                       const char *warning_text,
+                       apr_pool_t *scratch_pool)
+{
+  struct progress_baton *pb = baton;
+
+  if (warning_text != NULL)
+    {
+      apr_size_t len = strlen(warning_text);
+      SVN_ERR(svn_stream_write(pb->feedback_stream, warning_text, &len));
+    }
+  else
+    SVN_ERR(svn_stream_printf(pb->feedback_stream, scratch_pool,
+                              pb->dumping
+                              ? _("* Dumped revision %ld.\n")
+                              : _("* Verified revision %ld.\n"),
+                              revision));
+
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_repos_dump_fs2(svn_repos_t *repos,
+                   svn_stream_t *stream,
+                   svn_stream_t *feedback_stream,
+                   svn_revnum_t start_rev,
+                   svn_revnum_t end_rev,
+                   svn_boolean_t incremental,
+                   svn_boolean_t use_deltas,
+                   svn_cancel_func_t cancel_func,
+                   void *cancel_baton,
+                   apr_pool_t *pool)
+{
+  struct progress_baton pb;
+  pb.dumping = (stream != NULL); /* Show verify messages if stream is NULL */
+  pb.feedback_stream = feedback_stream;
+
+  return svn_error_return(svn_repos_dump_fs3(repos,
+                                             stream,
+                                             start_rev,
+                                             end_rev,
+                                             incremental,
+                                             use_deltas,
+                                             feedback_stream
+                                               ? repos_progress_handler
+                                               : NULL,
+                                             &pb,
+                                             cancel_func,
+                                             cancel_baton,
+                                             pool));
+}
+
+svn_error_t *
+svn_repos_verify_fs(svn_repos_t *repos,
+                    svn_stream_t *feedback_stream,
+                    svn_revnum_t start_rev,
+                    svn_revnum_t end_rev,
+                    svn_cancel_func_t cancel_func,
+                    void *cancel_baton,
+                    apr_pool_t *pool)
+{
+  struct progress_baton pb;
+  pb.dumping = FALSE;
+  pb.feedback_stream = feedback_stream;
+
+  return svn_error_return(svn_repos_verify_fs2(repos,
+                                               start_rev,
+                                               end_rev,
+                                               feedback_stream
+                                                 ? repos_progress_handler
+                                                 : NULL,
+                                               &pb,
+                                               cancel_func,
+                                               cancel_baton,
+                                               pool));
+}
+
 /*** From load.c ***/
 static svn_repos_parser_fns_t *
 fns_from_fns2(const svn_repos_parse_fns2_t *fns2,

Modified: subversion/trunk/subversion/libsvn_repos/dump.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/dump.c?rev=932335&r1=932334&r2=932335&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/dump.c (original)
+++ subversion/trunk/subversion/libsvn_repos/dump.c Fri Apr  9 10:17:58 2010
@@ -180,7 +180,8 @@ struct edit_baton
   svn_stream_t *stream;
 
   /* Send feedback here, if non-NULL */
-  svn_stream_t *feedback_stream;
+  svn_repos_progress_func_t progress_func;
+  void *progress_baton;
 
   /* The fs revision root, so we can read the contents of paths. */
   svn_fs_root_t *fs_root;
@@ -416,15 +417,21 @@ dump_node(struct edit_baton *eb,
         }
       else
         {
-          if (!eb->verify && cmp_rev < eb->oldest_dumped_rev)
-            SVN_ERR(svn_stream_printf
-                    (eb->feedback_stream, pool,
+          if (!eb->verify && cmp_rev < eb->oldest_dumped_rev
+              && eb->progress_func)
+            {
+              const char *warning = apr_psprintf(
+                     pool,
                      _("WARNING: Referencing data in revision %ld,"
                        " which is older than the oldest\n"
                        "WARNING: dumped revision (%ld).  Loading this dump"
                        " into an empty repository\n"
                        "WARNING: will fail.\n"),
-                     cmp_rev, eb->oldest_dumped_rev));
+                     cmp_rev, eb->oldest_dumped_rev);
+
+              SVN_ERR(eb->progress_func(eb->progress_baton,
+                                        eb->oldest_dumped_rev, warning, pool));
+            }
 
           SVN_ERR(svn_stream_printf(eb->stream, pool,
                                     SVN_REPOS_DUMPFILE_NODE_COPYFROM_REV
@@ -845,7 +852,8 @@ get_dump_editor(const svn_delta_editor_t
                 svn_revnum_t to_rev,
                 const char *root_path,
                 svn_stream_t *stream,
-                svn_stream_t *feedback_stream,
+                svn_repos_progress_func_t progress_func,
+                void *progress_baton,
                 svn_revnum_t oldest_dumped_rev,
                 svn_boolean_t use_deltas,
                 svn_boolean_t verify,
@@ -859,7 +867,8 @@ get_dump_editor(const svn_delta_editor_t
 
   /* Set up the edit baton. */
   eb->stream = stream;
-  eb->feedback_stream = feedback_stream;
+  eb->progress_func = progress_func;
+  eb->progress_baton = progress_baton;
   eb->oldest_dumped_rev = oldest_dumped_rev;
   eb->bufsize = sizeof(eb->buffer);
   eb->path = apr_pstrdup(pool, root_path);
@@ -953,13 +962,14 @@ write_revision_record(svn_stream_t *stre
 
 /* The main dumper. */
 svn_error_t *
-svn_repos_dump_fs2(svn_repos_t *repos,
+svn_repos_dump_fs3(svn_repos_t *repos,
                    svn_stream_t *stream,
-                   svn_stream_t *feedback_stream,
                    svn_revnum_t start_rev,
                    svn_revnum_t end_rev,
                    svn_boolean_t incremental,
                    svn_boolean_t use_deltas,
+                   svn_repos_progress_func_t progress_func,
+                   void *progress_baton,
                    svn_cancel_func_t cancel_func,
                    void *cancel_baton,
                    apr_pool_t *pool)
@@ -972,7 +982,6 @@ svn_repos_dump_fs2(svn_repos_t *repos,
   svn_revnum_t youngest;
   const char *uuid;
   int version;
-  svn_boolean_t dumping = (stream != NULL);
 
   /* Determine the current youngest revision of the filesystem. */
   SVN_ERR(svn_fs_youngest_rev(&youngest, fs, pool));
@@ -984,8 +993,6 @@ svn_repos_dump_fs2(svn_repos_t *repos,
     end_rev = youngest;
   if (! stream)
     stream = svn_stream_empty(pool);
-  if (! feedback_stream)
-    feedback_stream = svn_stream_empty(pool);
 
   /* Validate the revisions. */
   if (start_rev > end_rev)
@@ -1068,8 +1075,8 @@ svn_repos_dump_fs2(svn_repos_t *repos,
          non-incremental dump. */
       use_deltas_for_rev = use_deltas && (incremental || i != start_rev);
       SVN_ERR(get_dump_editor(&dump_editor, &dump_edit_baton, fs, to_rev,
-                              "/", stream, feedback_stream, start_rev,
-                              use_deltas_for_rev, FALSE, subpool));
+                              "/", stream, progress_func, progress_baton,
+                              start_rev, use_deltas_for_rev, FALSE, subpool));
 
       /* Drive the editor in one way or another. */
       SVN_ERR(svn_fs_revision_root(&to_root, fs, to_rev, subpool));
@@ -1100,11 +1107,8 @@ svn_repos_dump_fs2(svn_repos_t *repos,
         }
 
     loop_end:
-      SVN_ERR(svn_stream_printf(feedback_stream, pool,
-                                dumping
-                                ? _("* Dumped revision %ld.\n")
-                                : _("* Verified revision %ld.\n"),
-                                to_rev));
+      if (progress_func)
+        SVN_ERR(progress_func(progress_baton, to_rev, NULL, subpool));
     }
 
   svn_pool_destroy(subpool);
@@ -1176,13 +1180,14 @@ verify_close_directory(void *dir_baton,
 }
 
 svn_error_t *
-svn_repos_verify_fs(svn_repos_t *repos,
-                    svn_stream_t *feedback_stream,
-                    svn_revnum_t start_rev,
-                    svn_revnum_t end_rev,
-                    svn_cancel_func_t cancel_func,
-                    void *cancel_baton,
-                    apr_pool_t *pool)
+svn_repos_verify_fs2(svn_repos_t *repos,
+                     svn_revnum_t start_rev,
+                     svn_revnum_t end_rev,
+                     svn_repos_progress_func_t progress_func,
+                     void *progress_baton,
+                     svn_cancel_func_t cancel_func,
+                     void *cancel_baton,
+                     apr_pool_t *pool)
 {
   svn_fs_t *fs = svn_repos_fs(repos);
   svn_revnum_t youngest;
@@ -1197,8 +1202,6 @@ svn_repos_verify_fs(svn_repos_t *repos,
     start_rev = 0;
   if (! SVN_IS_VALID_REVNUM(end_rev))
     end_rev = youngest;
-  if (! feedback_stream)
-    feedback_stream = svn_stream_empty(pool);
 
   /* Validate the revisions. */
   if (start_rev > end_rev)
@@ -1226,7 +1229,8 @@ svn_repos_verify_fs(svn_repos_t *repos,
       /* Get cancellable dump editor, but with our close_directory handler. */
       SVN_ERR(get_dump_editor((const svn_delta_editor_t **)&dump_editor,
                               &dump_edit_baton, fs, rev, "",
-                              svn_stream_empty(pool), feedback_stream,
+                              svn_stream_empty(pool), 
+                              progress_func, progress_baton,
                               start_rev,
                               FALSE, TRUE, /* use_deltas, verify */
                               iterpool));
@@ -1242,9 +1246,9 @@ svn_repos_verify_fs(svn_repos_t *repos,
                                 cancel_editor, cancel_edit_baton,
                                 NULL, NULL, iterpool));
       SVN_ERR(svn_fs_revision_proplist(&props, fs, rev, iterpool));
-      SVN_ERR(svn_stream_printf(feedback_stream, iterpool,
-                                _("* Verified revision %ld.\n"),
-                                rev));
+
+      if (progress_func)
+        SVN_ERR(progress_func(progress_baton, rev, NULL, iterpool));
     }
 
   svn_pool_destroy(iterpool);



Mime
View raw message