Author: stefan2
Date: Mon Aug 24 13:22:05 2015
New Revision: 1697387

URL: http://svn.apache.org/r1697387
Log:
Actually implement what 'svnfsfs load-index' promises: That the input data
does not need to be pre-sorted by offset.

* subversion/libsvn_fs_fs/load-index.c
  (compare_p2l_entry_revision): Define ordering criterion.
  (svn_fs_fs__load_index): Sort the input before processing it.

Modified:
    subversion/trunk/subversion/libsvn_fs_fs/load-index.c

Modified: subversion/trunk/subversion/libsvn_fs_fs/load-index.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/load-index.c?rev=1697387&r1=1697386&r2=1697387&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/load-index.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/load-index.c Mon Aug 24 13:22:05 
2015
@@ -23,11 +23,29 @@
 #include "svn_pools.h"
 
 #include "private/svn_fs_fs_private.h"
+#include "private/svn_sorts_private.h"
 
 #include "index.h"
 #include "util.h"
 #include "transaction.h"
 
+/* A svn_sort__array compatible comparator function, sorting the
+ * svn_fs_fs__p2l_entry_t** given in LHS, RHS by offset. */
+static int
+compare_p2l_entry_revision(const void *lhs,
+                           const void *rhs)
+{
+  const svn_fs_fs__p2l_entry_t *lhs_entry
+    =*(const svn_fs_fs__p2l_entry_t **)lhs;
+  const svn_fs_fs__p2l_entry_t *rhs_entry
+    =*(const svn_fs_fs__p2l_entry_t **)rhs;
+
+  if (lhs_entry->offset < rhs_entry->offset)
+    return -1;
+
+  return lhs_entry->offset == rhs_entry->offset ? 0 : 1;
+}
+
 svn_error_t *
 svn_fs_fs__load_index(svn_fs_t *fs,
                       svn_revnum_t revision,
@@ -40,6 +58,10 @@ svn_fs_fs__load_index(svn_fs_t *fs,
   if (! svn_fs_fs__use_log_addressing(fs))
     return svn_error_create(SVN_ERR_FS_UNSUPPORTED_FORMAT, NULL, NULL);
 
+  /* P2L index must be written in offset order.
+   * Sort ENTRIES accordingly. */
+  svn_sort__array(entries, compare_p2l_entry_revision);
+
   /* Treat an empty array as a no-op instead error. */
   if (entries->nelts != 0)
     {


Reply via email to