FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/recovery.c
/* Part of the recovery procedure.  Return the largest revision *REV in
   filesystem FS.  Use POOL for temporary allocation. */
Part of the recovery procedure.  Return the largest revision *REV in
filesystem FS.  Use POOL for temporary allocation.
Part of the recovery procedure . Return the largest revision * REV in filesystem FS . Use POOL for temporary allocation .
static svn_error_t *
recover_get_largest_revision(svn_fs_t *fs, svn_revnum_t *rev, apr_pool_t *pool)
{
  apr_pool_t *iterpool;
  svn_revnum_t left, right = 1;
  iterpool = svn_pool_create(pool);
  while (1)
    {
      svn_error_t *err;
      svn_fs_fs__revision_file_t *file;
      svn_pool_clear(iterpool);
      err = svn_fs_fs__open_pack_or_rev_file(&file, fs, right, iterpool,
                                             iterpool);
      if (err && err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
        {
          svn_error_clear(err);
          break;
        }
      else
        SVN_ERR(err);
      right <<= 1;
    }
  left = right >> 1;
  while (left + 1 < right)
    {
      svn_revnum_t probe = left + ((right - left) / 2);
      svn_error_t *err;
      svn_fs_fs__revision_file_t *file;
      svn_pool_clear(iterpool);
      err = svn_fs_fs__open_pack_or_rev_file(&file, fs, probe, iterpool,
                                             iterpool);
      if (err && err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
        {
          svn_error_clear(err);
          right = probe;
        }
      else
        {
          SVN_ERR(err);
          left = probe;
        }
    }
  svn_pool_destroy(iterpool);
  *rev = left;
  return SVN_NO_ERROR;
}
static svn_error_t * recover_get_largest_revision ( svn_fs_t * fs , svn_revnum_t * rev , apr_pool_t * pool ) { apr_pool_t * iterpool ; svn_revnum_t left , right = 1 ; iterpool = svn_pool_create ( pool ) ; while ( 1 ) { svn_error_t * err ; svn_fs_fs__revision_file_t * file ; svn_pool_clear ( iterpool ) ; err = svn_fs_fs__open_pack_or_rev_file ( & file , fs , right , iterpool , iterpool ) ; if ( err && err -> apr_err == SVN_ERR_FS_NO_SUCH_REVISION ) { svn_error_clear ( err ) ; break ; } else SVN_ERR ( err ) ; right <<= 1 ; } left = right >> 1 ; while ( left + 1 < right ) { svn_revnum_t probe = left + ( ( right - left ) / 2 ) ; svn_error_t * err ; svn_fs_fs__revision_file_t * file ; svn_pool_clear ( iterpool ) ; err = svn_fs_fs__open_pack_or_rev_file ( & file , fs , probe , iterpool , iterpool ) ; if ( err && err -> apr_err == SVN_ERR_FS_NO_SUCH_REVISION ) { svn_error_clear ( err ) ; right = probe ; } else { SVN_ERR ( err ) ; left = probe ; } } svn_pool_destroy ( iterpool ) ; * rev = left ; return SVN_NO_ERROR ; }
Part of the recovery procedure.
Part of the recovery procedure .
/* Discovering the largest revision in the filesystem would be an
     expensive operation if we did a readdir() or searched linearly,
     so we'll do a form of binary search.  left is a revision that we
     know exists, right a revision that we know does not exist. */ /* Keep doubling right, until we find a revision that doesn't exist. */ /* We know that left exists and right doesn't.  Do a normal bsearch to find
     the last revision. */ /* left is now the largest revision that exists. */