Author: stefan2
Date: Sat Oct 18 22:33:27 2014
New Revision: 1632855

URL: http://svn.apache.org/r1632855
Log:
Prepare the 'svnfsfs dump-index' code for being split up into UI,
FSFS internal logic and a private interface in between.

This patch introduces the interface structure but does not move
any code around.  We add a per index record callback function
that the UI can implement to show the contents while the actual
query would be run in FSFS.

* subversion/svnfsfs/dump-index-cmd.c
  (svn_fs_fs__dump_index_func_t): The new callback type.
  (dump_index_entry): The former record display part of dump_index.
  (svn_fs_fs__dump_index): The suggested FSFS private API function.
                           It contains the logic of the previous
                           dump_index but expects the FS to be passed
                           in instead of being opened locally.  Invoke
                           the callback instead of displaying data.
                           Finally, add cancellation support.
  (dump_index): Stripped down to opening the FS, writing the header
                line and then invoking the new function to drive
                the index processing.

Modified:
    subversion/trunk/subversion/svnfsfs/dump-index-cmd.c

Modified: subversion/trunk/subversion/svnfsfs/dump-index-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnfsfs/dump-index-cmd.c?rev=1632855&r1=1632854&r2=1632855&view=diff
==============================================================================
--- subversion/trunk/subversion/svnfsfs/dump-index-cmd.c (original)
+++ subversion/trunk/subversion/svnfsfs/dump-index-cmd.c Sat Oct 18 22:33:27 
2014
@@ -31,6 +31,15 @@
 
 #include "svnfsfs.h"
 
+/* Callback function type receiving a single P2L index ENTRY, a user
+ * provided BATON and a SCRATCH_POOL for temporary allocations.
+ * ENTRY's lifetime may end when the callback returns.
+ */
+typedef svn_error_t *
+(*svn_fs_fs__dump_index_func_t)(const svn_fs_fs__p2l_entry_t *entry,
+                                void *baton,
+                                apr_pool_t *scratch_pool);
+
 /* Return the 8 digit hex string for FNVV1, allocated in POOL.
  */
 static const char *
@@ -50,38 +59,58 @@ fnv1_to_string(apr_uint32_t fnv1,
 static const char *item_type_str[]
   = {"none ", "frep ", "drep ", "fprop", "dprop", "node ", "chgs ", "rep  "};
 
-/* Read the repository at PATH beginning with revision START_REVISION and
- * return the result in *FS.  Allocate caches with MEMSIZE bytes total
- * capacity.  Use POOL for non-cache allocations.
+/* Implements svn_fs_fs__dump_index_func_t as printing one table row
+ * containing the fields of ENTRY to the console.
  */
 static svn_error_t *
-dump_index(const char *path,
-           svn_revnum_t revision,
-           apr_pool_t *pool)
+dump_index_entry(const svn_fs_fs__p2l_entry_t *entry,
+                 void *baton,
+                 apr_pool_t *scratch_pool)
+{
+  const char *type_str
+    = entry->type < (sizeof(item_type_str) / sizeof(item_type_str[0]))
+    ? item_type_str[entry->type]
+    : "???";
+
+  printf("%12" APR_UINT64_T_HEX_FMT " %12" APR_UINT64_T_HEX_FMT
+         " %s %9ld %8" APR_UINT64_T_FMT " %s\n",
+         (apr_uint64_t)entry->offset, (apr_uint64_t)entry->size,
+         type_str, entry->item.revision, entry->item.number,
+         fnv1_to_string(entry->fnv1_checksum, scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+/* Read the P2L index for the rev / pack file containing REVISION in FS.
+ * For each index entry, invoke CALLBACK_FUNC with CALLBACK_BATON.
+ * If not NULL, call CANCEL_FUNC with CANCEL_BATON from time to time.
+ * Use SCRATCH_POOL for temporary allocations.
+ */
+static svn_error_t *
+svn_fs_fs__dump_index(svn_fs_t *fs,
+                      svn_revnum_t revision,
+                      svn_fs_fs__dump_index_func_t callback_func,
+                      void *callback_baton,
+                      svn_cancel_func_t cancel_func,
+                      void *cancel_baton,
+                      apr_pool_t *scratch_pool)
 {
   svn_fs_fs__revision_file_t *rev_file;
-  svn_fs_t *fs;
   int i;
   apr_off_t offset, max_offset;
-  apr_pool_t *iterpool = svn_pool_create(pool);
-
-  /* Check repository type and open it. */
-  SVN_ERR(open_fs(&fs, path, pool));
+  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
 
   /* Check the FS format. */
   if (! svn_fs_fs__use_log_addressing(fs, revision))
     return svn_error_create(SVN_ERR_FS_UNSUPPORTED_FORMAT, NULL, NULL);
 
   /* Revision & index file access object. */
-  SVN_ERR(svn_fs_fs__open_pack_or_rev_file(&rev_file, fs, revision, pool,
-                                           iterpool));
+  SVN_ERR(svn_fs_fs__open_pack_or_rev_file(&rev_file, fs, revision,
+                                           scratch_pool, iterpool));
 
   /* Offset range to cover. */
   SVN_ERR(svn_fs_fs__p2l_get_max_offset(&max_offset, fs, rev_file, revision,
-                                        pool));
-
-  /* Write header line. */
-  printf("       Start       Length Type   Revision     Item Checksum\n");
+                                        scratch_pool));
 
   /* Walk through all P2L index entries in offset order. */
   for (offset = 0; offset < max_offset; )
@@ -100,18 +129,14 @@ dump_index(const char *path,
         {
           const svn_fs_fs__p2l_entry_t *entry
             = &APR_ARRAY_IDX(entries, i, const svn_fs_fs__p2l_entry_t);
-          const char *type_str
-            = entry->type < (sizeof(item_type_str) / sizeof(item_type_str[0]))
-            ? item_type_str[entry->type]
-            : "???";
-
           offset = entry->offset + entry->size;
 
-          printf("%12" APR_UINT64_T_HEX_FMT " %12" APR_UINT64_T_HEX_FMT
-                 " %s %9ld %8" APR_UINT64_T_FMT " %s\n",
-                 (apr_uint64_t)entry->offset, (apr_uint64_t)entry->size,
-                 type_str, entry->item.revision, entry->item.number,
-                 fnv1_to_string(entry->fnv1_checksum, iterpool));
+          /* Cancellation support */
+          if (cancel_func)
+            SVN_ERR(cancel_func(cancel_baton));
+
+          /* Invoke processing callback. */
+          SVN_ERR(callback_func(entry, callback_baton, iterpool));
         }
     }
 
@@ -120,6 +145,31 @@ dump_index(const char *path,
   return SVN_NO_ERROR;
 }
 
+
+/* Read the repository at PATH beginning with revision START_REVISION and
+ * return the result in *FS.  Allocate caches with MEMSIZE bytes total
+ * capacity.  Use POOL for non-cache allocations.
+ */
+static svn_error_t *
+dump_index(const char *path,
+           svn_revnum_t revision,
+           apr_pool_t *pool)
+{
+  svn_fs_t *fs;
+
+  /* Check repository type and open it. */
+  SVN_ERR(open_fs(&fs, path, pool));
+
+  /* Write header line. */
+  printf("       Start       Length Type   Revision     Item Checksum\n");
+
+  /* Dump the whole index contents */
+  SVN_ERR(svn_fs_fs__dump_index(fs, revision, dump_index_entry, NULL,
+                                check_cancel, NULL, pool));
+
+  return SVN_NO_ERROR;
+}
+
 /* This implements `svn_opt_subcommand_t'. */
 svn_error_t *
 subcommand__dump_index(apr_getopt_t *os, void *baton, apr_pool_t *pool)


Reply via email to