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 2010/06/01 15:19:58 UTC

svn commit: r950068 - in /subversion/trunk/subversion: include/svn_repos.h libsvn_repos/deprecated.c libsvn_repos/dump.c libsvn_repos/notify.c svnadmin/main.c

Author: hwright
Date: Tue Jun  1 13:19:57 2010
New Revision: 950068

URL: http://svn.apache.org/viewvc?rev=950068&view=rev
Log:
Take the current progress notification system in libsvn_repos, and make it
a more generic notification system, with the goal of further extending it
to stuff like 'load' and 'pack'.

This is intended for callers of the repos APIs directly, such as svnadmin.
Callers which retrieve information (such as logs and other data) intended for
the client should continue to use existing callbacks.

* subversion/svnadmin/main.c
  (progress_baton, repos_progress_handler): Remove.
  (repos_notify_handler): New.
  (subcommand_dump, subcommand_verify): Use the new notification callback,
    and get rid of the baton struct, since we only need one baton item.
 
* subversion/include/svn_repos.h
  (svn_repos_notify_action_t, svn_repos_notify_t): New.
  (svn_repos_notify_func_t): Return void, and only accept a notify parameter.
  (svn_repos_notify_create): New.

* subversion/libsvn_repos/deprecated.c
  (notify_baton, repos_progress_handler): Remove.
  (repos_notify_handler): New.
  (svn_repos_dump_fs2, svn_repos_verify_fs): Use the new callback, and
    just use the feedback stream as the baton.

* subversion/libsvn_repos/dump.c
  (dump_node): Use notification system to emit warnings.
  (svn_repos_dump_fs3, svn_repos_verify_fs2): Use the notification system to
    return information about the operation.

* subversion/libsvn_repos/notify.c:
  New.

Added:
    subversion/trunk/subversion/libsvn_repos/notify.c   (with props)
Modified:
    subversion/trunk/subversion/include/svn_repos.h
    subversion/trunk/subversion/libsvn_repos/deprecated.c
    subversion/trunk/subversion/libsvn_repos/dump.c
    subversion/trunk/subversion/svnadmin/main.c

Modified: subversion/trunk/subversion/include/svn_repos.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_repos.h?rev=950068&r1=950067&r2=950068&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_repos.h (original)
+++ subversion/trunk/subversion/include/svn_repos.h Tue Jun  1 13:19:57 2010
@@ -2115,14 +2115,69 @@ enum svn_repos_load_uuid
   svn_repos_load_uuid_force
 };
 
-/** Callback for providing per revision progress while dumping or verifying
- *  the repository.
+/** The type of action occuring.
+ *
+ * @since New in 1.7.
+ */
+typedef enum svn_repos_notify_action_t
+{
+  /** A warning message is waiting. */
+  svn_repos_notify_warning = 0,
+
+  /** A revision has finished being dumped. */
+  svn_repos_notify_dump_rev_end,
+
+  /** A revision has finished being verified. */
+  svn_repos_notify_verify_rev_end,
+} svn_repos_notify_action_t;
+
+/**
+ * Structure used by #svn_repos_notify_func_t.
+ *
+ * The only field guaranteed to be populated is @c action.  Other fields are
+ * dependent upon the @c action.  (See individual fields for more information.)
+ *
+ * @note Callers of notification functions should use
+ * svn_repos_notify_create() to create structures of this type to allow for
+ * future extensibility.
+ *
+ * @since New in 1.7.
+ */
+typedef struct svn_repos_notify_t
+{
+  /** Action that describes what happened in the repository. */
+  svn_repos_notify_action_t action;
+
+  /** For #svn_repos_notify_dump_rev_end and #svn_repos_notify_verify_rev_end,
+   * the revision which just completed. */
+  svn_revnum_t revision;
+
+  /** For #svn_repos_notify_warning, the warning text. */
+  const char *warning;
+
+  /* NOTE: Add new fields at the end to preserve binary compatibility.
+     Also, if you add fields here, you have to update
+     svn_repos_notify_create(). */
+} svn_repos_notify_t;
+
+/** Callback for providing notification from the repository.
+ * Returns @a void.  Justification: success of an operation is not dependent
+ * upon successful notification of that operation.
  *
  * @since New in 1.7. */
-typedef svn_error_t *(*svn_repos_notify_func_t)(void *baton,
-                                                svn_revnum_t rev,
-                                                const char *warning_text,
-                                                apr_pool_t *scratch_pool);
+typedef void (*svn_repos_notify_func_t)(void *baton,
+                                        const svn_repos_notify_t *notify,
+                                        apr_pool_t *scratch_pool);
+
+/**
+ * Allocate an #svn_repos_notify_t structure in @a result_pool, initialize
+ * and return it.
+ *
+ * @since New in 1.7.
+ */
+svn_repos_notify_t *
+svn_repos_notify_create(svn_repos_notify_action_t action,
+                        apr_pool_t *result_pool);
 
 
 /**

Modified: subversion/trunk/subversion/libsvn_repos/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/deprecated.c?rev=950068&r1=950067&r2=950068&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_repos/deprecated.c Tue Jun  1 13:19:57 2010
@@ -428,36 +428,40 @@ svn_repos_dump_fs(svn_repos_t *repos,
                             cancel_baton, pool);
 }
 
-/* Baton for repos_progress_handler */
-struct notify_baton
-{
-  svn_boolean_t dumping;
-  svn_stream_t *feedback_stream;
-};
-
 /* Implementation of svn_repos_notify_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 notify_baton *nb = baton;
-
-  if (warning_text != NULL)
-    {
-      apr_size_t len = strlen(warning_text);
-      SVN_ERR(svn_stream_write(nb->feedback_stream, warning_text, &len));
-    }
-  else
-    SVN_ERR(svn_stream_printf(nb->feedback_stream, scratch_pool,
-                              nb->dumping
-                              ? _("* Dumped revision %ld.\n")
-                              : _("* Verified revision %ld.\n"),
-                              revision));
-
-  return SVN_NO_ERROR;
+static void
+repos_notify_handler(void *baton,
+                     const svn_repos_notify_t *notify,
+                     apr_pool_t *scratch_pool)
+{
+  svn_stream_t *feedback_stream = baton;
+
+  switch (notify->action)
+  {
+    case svn_repos_notify_warning:
+      {
+        apr_size_t len = strlen(notify->warning);
+        svn_error_clear(svn_stream_write(feedback_stream, notify->warning,
+                                         &len));
+        return;
+      }
+
+    case svn_repos_notify_dump_rev_end:
+      svn_error_clear(svn_stream_printf(feedback_stream, scratch_pool,
+                                        _("* Dumped revision %ld.\n"),
+                                        notify->revision));
+      return;
+
+    case svn_repos_notify_verify_rev_end:
+      svn_error_clear(svn_stream_printf(feedback_stream, scratch_pool,
+                                        _("* Verified revision %ld.\n"),
+                                        notify->revision));
+      return;
+
+    default:
+      return;
+  }
 }
 
 
@@ -473,10 +477,6 @@ svn_repos_dump_fs2(svn_repos_t *repos,
                    void *cancel_baton,
                    apr_pool_t *pool)
 {
-  struct notify_baton nb;
-  nb.dumping = (stream != NULL); /* Show verify messages if stream is NULL */
-  nb.feedback_stream = feedback_stream;
-
   return svn_error_return(svn_repos_dump_fs3(repos,
                                              stream,
                                              start_rev,
@@ -484,9 +484,9 @@ svn_repos_dump_fs2(svn_repos_t *repos,
                                              incremental,
                                              use_deltas,
                                              feedback_stream
-                                               ? repos_progress_handler
+                                               ? repos_notify_handler
                                                : NULL,
-                                             &nb,
+                                             feedback_stream,
                                              cancel_func,
                                              cancel_baton,
                                              pool));
@@ -501,17 +501,13 @@ svn_repos_verify_fs(svn_repos_t *repos,
                     void *cancel_baton,
                     apr_pool_t *pool)
 {
-  struct notify_baton nb;
-  nb.dumping = FALSE;
-  nb.feedback_stream = feedback_stream;
-
   return svn_error_return(svn_repos_verify_fs2(repos,
                                                start_rev,
                                                end_rev,
                                                feedback_stream
-                                                 ? repos_progress_handler
+                                                 ? repos_notify_handler
                                                  : NULL,
-                                               &nb,
+                                               feedback_stream,
                                                cancel_func,
                                                cancel_baton,
                                                pool));

Modified: subversion/trunk/subversion/libsvn_repos/dump.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/dump.c?rev=950068&r1=950067&r2=950068&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/dump.c (original)
+++ subversion/trunk/subversion/libsvn_repos/dump.c Tue Jun  1 13:19:57 2010
@@ -429,7 +429,10 @@ dump_node(struct edit_baton *eb,
           if (!eb->verify && cmp_rev < eb->oldest_dumped_rev
               && eb->notify_func)
             {
-              const char *warning = apr_psprintf(
+              svn_repos_notify_t *notify =
+                    svn_repos_notify_create(svn_repos_notify_warning, pool);
+
+              notify->warning = apr_psprintf(
                      pool,
                      _("WARNING: Referencing data in revision %ld,"
                        " which is older than the oldest\n"
@@ -438,8 +441,7 @@ dump_node(struct edit_baton *eb,
                        "WARNING: will fail.\n"),
                      cmp_rev, eb->oldest_dumped_rev);
               eb->found_old_reference = TRUE;
-              SVN_ERR(eb->notify_func(eb->notify_baton,
-                                        eb->oldest_dumped_rev, warning, pool));
+              eb->notify_func(eb->notify_baton, notify, pool);
             }
 
           SVN_ERR(svn_stream_printf(eb->stream, pool,
@@ -530,7 +532,10 @@ dump_node(struct edit_baton *eb,
                 TRUE, pool, pool));
               if (apr_hash_count(old_mergeinfo))
                 {
-                  const char *warning = apr_psprintf(
+                  svn_repos_notify_t *notify =
+                    svn_repos_notify_create(svn_repos_notify_warning, pool);
+
+                  notify->warning = apr_psprintf(
                     pool,
                     _("WARNING: Mergeinfo referencing revision(s) prior "
                       "to the oldest dumped revision (%ld).\n"
@@ -539,9 +544,7 @@ dump_node(struct edit_baton *eb,
                     eb->oldest_dumped_rev);
 
                   eb->found_old_mergeinfo = TRUE;
-                  SVN_ERR(eb->notify_func(eb->notify_baton,
-                                            SVN_INVALID_REVNUM,
-                                            warning, pool));
+                  eb->notify_func(eb->notify_baton, notify, pool);
                 }
             }
         }
@@ -1030,6 +1033,7 @@ svn_repos_dump_fs3(svn_repos_t *repos,
   int version;
   svn_boolean_t found_old_reference = FALSE;
   svn_boolean_t found_old_mergeinfo = FALSE;
+  svn_repos_notify_t *notify;
 
   /* Determine the current youngest revision of the filesystem. */
   SVN_ERR(svn_fs_youngest_rev(&youngest, fs, pool));
@@ -1075,6 +1079,11 @@ svn_repos_dump_fs3(svn_repos_t *repos,
   SVN_ERR(svn_stream_printf(stream, pool, SVN_REPOS_DUMPFILE_UUID
                             ": %s\n\n", uuid));
 
+  /* Create a notify object that we can reuse in the loop. */
+  if (notify_func)
+    notify = svn_repos_notify_create(svn_repos_notify_dump_rev_end,
+                                     pool);
+
   /* Main loop:  we're going to dump revision i.  */
   for (i = start_rev; i <= end_rev; i++)
     {
@@ -1156,7 +1165,10 @@ svn_repos_dump_fs3(svn_repos_t *repos,
 
     loop_end:
       if (notify_func)
-        SVN_ERR(notify_func(notify_baton, to_rev, NULL, subpool));
+        {
+          notify->revision = to_rev;
+          notify_func(notify_baton, notify, subpool);
+        }
 
       if (dump_edit_baton) /* We never get an edit baton for r0. */
         {
@@ -1173,23 +1185,28 @@ svn_repos_dump_fs3(svn_repos_t *repos,
          the oldest dumped revision?  If so, then issue a final generic
          warning, since the inline warnings already issued might easily be
          missed. */
+
+      notify = svn_repos_notify_create(svn_repos_notify_warning, subpool);
+
       if (found_old_reference)
-        SVN_ERR(notify_func(notify_baton, SVN_INVALID_REVNUM,
-                              _("WARNING: The range of revisions dumped "
-                                "contained references to\n"
-                                "WARNING: copy sources outside that "
-                                "range.\n"),
-                              subpool));
+        {
+          notify->warning = _("WARNING: The range of revisions dumped "
+                              "contained references to\n"
+                              "WARNING: copy sources outside that "
+                              "range.\n");
+          notify_func(notify_baton, notify, subpool);
+        }
 
       /* Ditto if we issued any warnings about old revisions referenced
          in dumped mergeinfo. */
       if (found_old_mergeinfo)
-        SVN_ERR(notify_func(notify_baton, SVN_INVALID_REVNUM,
-                              _("WARNING: The range of revisions dumped "
-                                "contained mergeinfo\n"
-                                "WARNING: which reference revisions outside "
-                                "that range.\n"),
-                              subpool));
+        {
+          notify->warning = _("WARNING: The range of revisions dumped "
+                              "contained mergeinfo\n"
+                              "WARNING: which reference revisions outside "
+                              "that range.\n");
+          notify_func(notify_baton, notify, subpool);
+        }
     }
 
   svn_pool_destroy(subpool);
@@ -1274,6 +1291,7 @@ svn_repos_verify_fs2(svn_repos_t *repos,
   svn_revnum_t youngest;
   svn_revnum_t rev;
   apr_pool_t *iterpool = svn_pool_create(pool);
+  svn_repos_notify_t *notify;
 
   /* Determine the current youngest revision of the filesystem. */
   SVN_ERR(svn_fs_youngest_rev(&youngest, fs, pool));
@@ -1296,6 +1314,11 @@ svn_repos_verify_fs2(svn_repos_t *repos,
                                "(youngest revision is %ld)"),
                              end_rev, youngest);
 
+  /* Create a notify object that we can reuse within the loop. */
+  if (notify_func)
+    notify = svn_repos_notify_create(svn_repos_notify_verify_rev_end,
+                                     pool);
+
   for (rev = start_rev; rev <= end_rev; rev++)
     {
       svn_delta_editor_t *dump_editor;
@@ -1329,7 +1352,10 @@ svn_repos_verify_fs2(svn_repos_t *repos,
       SVN_ERR(svn_fs_revision_proplist(&props, fs, rev, iterpool));
 
       if (notify_func)
-        SVN_ERR(notify_func(notify_baton, rev, NULL, iterpool));
+        {
+          notify->revision = rev;
+          notify_func(notify_baton, notify, iterpool);
+        }
     }
 
   svn_pool_destroy(iterpool);

Added: subversion/trunk/subversion/libsvn_repos/notify.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/notify.c?rev=950068&view=auto
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/notify.c (added)
+++ subversion/trunk/subversion/libsvn_repos/notify.c Tue Jun  1 13:19:57 2010
@@ -0,0 +1,44 @@
+/* notify.c --- notifcation system
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "svn_pools.h"
+#include "svn_repos.h"
+#include "repos.h"
+#include "svn_private_config.h"
+#include "private/svn_utf_private.h"
+
+
+
+svn_repos_notify_t *
+svn_repos_notify_create(svn_repos_notify_action_t action,
+                        apr_pool_t *result_pool)
+{
+  svn_repos_notify_t *notify = apr_pcalloc(result_pool, sizeof(*notify));
+
+  notify->action = action;
+
+  return notify;
+}

Propchange: subversion/trunk/subversion/libsvn_repos/notify.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/trunk/subversion/svnadmin/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnadmin/main.c?rev=950068&r1=950067&r2=950068&view=diff
==============================================================================
--- subversion/trunk/subversion/svnadmin/main.c (original)
+++ subversion/trunk/subversion/svnadmin/main.c Tue Jun  1 13:19:57 2010
@@ -650,35 +650,40 @@ subcommand_deltify(apr_getopt_t *os, voi
 }
 
 
-/* Baton for repos_progress_handler */
-struct progress_baton
-{
-  svn_boolean_t dumping;
-  svn_stream_t *progress_stream;
-};
-
-/* Implementation of svn_repos_progress_func_t to wrap the output to a
+/* Implementation of svn_repos_notify_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);
-      return svn_error_return(svn_stream_write(pb->progress_stream,
-                                               warning_text, &len));
-    }
-
-  return svn_error_return(svn_stream_printf(pb->progress_stream, scratch_pool,
-                              pb->dumping
-                              ? _("* Dumped revision %ld.\n")
-                              : _("* Verified revision %ld.\n"),
-                              revision));
+static void
+repos_notify_handler(void *baton,
+                     const svn_repos_notify_t *notify,
+                     apr_pool_t *scratch_pool)
+{
+  svn_stream_t *feedback_stream = baton;
+
+  switch (notify->action)
+  {
+    case svn_repos_notify_warning:
+      {
+        apr_size_t len = strlen(notify->warning);
+        svn_error_clear(svn_stream_write(feedback_stream, notify->warning,
+                                         &len));
+        return;
+      }
+
+    case svn_repos_notify_dump_rev_end:
+      svn_error_clear(svn_stream_printf(feedback_stream, scratch_pool,
+                                        _("* Dumped revision %ld.\n"),
+                                        notify->revision));
+      return;
+
+    case svn_repos_notify_verify_rev_end:
+      svn_error_clear(svn_stream_printf(feedback_stream, scratch_pool,
+                                        _("* Verified revision %ld.\n"),
+                                        notify->revision));
+      return;
+
+    default:
+      return;
+  }
 }
 
 
@@ -732,7 +737,7 @@ subcommand_dump(apr_getopt_t *os, void *
   svn_stream_t *stdout_stream;
   svn_revnum_t lower = SVN_INVALID_REVNUM, upper = SVN_INVALID_REVNUM;
   svn_revnum_t youngest;
-  struct progress_baton pb = { 0 };
+  svn_stream_t *progress_stream = NULL;
 
   SVN_ERR(open_repos(&repos, opt_state->repository_path, pool));
   fs = svn_repos_fs(repos);
@@ -764,14 +769,12 @@ subcommand_dump(apr_getopt_t *os, void *
 
   /* Progress feedback goes to STDERR, unless they asked to suppress it. */
   if (! opt_state->quiet)
-    pb.progress_stream = recode_stream_create(stderr, pool);
+    progress_stream = recode_stream_create(stderr, pool);
 
-  pb.dumping = TRUE;
   SVN_ERR(svn_repos_dump_fs3(repos, stdout_stream, lower, upper,
                              opt_state->incremental, opt_state->use_deltas,
-                             !opt_state->quiet ? repos_progress_handler : NULL,
-                             !opt_state->quiet ? &pb : NULL,
-                             check_cancel, NULL, pool));
+                             !opt_state->quiet ? repos_notify_handler : NULL,
+                             progress_stream, check_cancel, NULL, pool));
 
   return SVN_NO_ERROR;
 }
@@ -1223,7 +1226,7 @@ subcommand_verify(apr_getopt_t *os, void
   svn_repos_t *repos;
   svn_fs_t *fs;
   svn_revnum_t youngest, lower, upper;
-  struct progress_baton pb = { 0 };
+  svn_stream_t *progress_stream;
 
   SVN_ERR(open_repos(&repos, opt_state->repository_path, pool));
   fs = svn_repos_fs(repos);
@@ -1241,13 +1244,12 @@ subcommand_verify(apr_getopt_t *os, void
     }
 
   if (! opt_state->quiet)
-    pb.progress_stream = recode_stream_create(stderr, pool);
+    progress_stream = recode_stream_create(stderr, pool);
 
   return svn_repos_verify_fs2(repos, lower, upper,
                               !opt_state->quiet
-                                ? repos_progress_handler : NULL,
-                              !opt_state->quiet ? &pb : NULL,
-                              check_cancel, NULL, pool);
+                                ? repos_notify_handler : NULL,
+                              progress_stream, check_cancel, NULL, pool);
 }