[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] svn_fs_youngest_revision

From: Yoshiki Hayashi <yoshiki_at_xemacs.org>
Date: 2001-02-26 10:36:59 CET

* rev-table.c (txn_body_youngest_rev): New function.
* rev-table.c (svn_fs_youngest_rev): New function.

* subversion/tests/libsvn_fs/fs-test.c (open_berkeley_filesystem):
  Test youngest rev equals 0.

Index: subversion/libsvn_fs/rev-table.c
===================================================================
RCS file: /cvs/subversion/subversion/libsvn_fs/rev-table.c,v
retrieving revision 1.3
diff -u -r1.3 rev-table.c
--- subversion/libsvn_fs/rev-table.c 2001/02/20 22:43:31 1.3
+++ subversion/libsvn_fs/rev-table.c 2001/02/26 08:58:31
@@ -161,6 +161,89 @@
 }
 
 
+
+
+/* Getting the youngest revision. */
+
+
+struct youngest_rev_args {
+ svn_revnum_t *youngest_p;
+ svn_fs_t *fs;
+};
+
+static svn_error_t *
+txn_body_youngest_rev (void *baton,
+ trail_t *trail)
+{
+ struct youngest_rev_args *args = baton;
+
+ int db_err;
+ DBC *cursor = 0;
+ DBT key, value;
+
+ svn_fs_t *fs = args->fs;
+
+ /* Create a database cursor. */
+ SVN_ERR (DB_WRAP (fs, "getting youngest revision (creating cursor)",
+ fs->revisions->cursor (fs->revisions, trail->db_txn, &cursor, 0)));
+
+ /* Find the last entry in the `revisions' table. */
+ db_err = cursor->c_get (cursor,
+ svn_fs__result_dbt (&key),
+ svn_fs__nodata_dbt (&value),
+ DB_LAST);
+
+ if (db_err)
+ {
+ /* Free the cursor. Ignore any error value --- the error above
+ is more interesting. */
+ cursor->c_close (cursor);
+
+ if (db_err == DB_NOTFOUND)
+ /* The revision 0 should always be present, at least. */
+ return
+ svn_error_createf
+ (SVN_ERR_FS_CORRUPT, 0, 0, fs->pool,
+ "revision 0 missing from `revisions' table, in filesystem `%s'",
+ fs->env_path);
+
+ SVN_ERR (DB_WRAP (fs, "getting youngest revision (finding last entry)",
+ db_err));
+ }
+ svn_fs__track_dbt (&key, trail->pool);
+
+ /* Turn the record number into a Subversion revision number.
+ Revisions are numbered starting with zero; Berkeley DB record
+ numbers begin with one. */
+ {
+ db_recno_t recno;
+ recno = *(db_recno_t *) key.data;
+ *args->youngest_p = recno - 1;
+ }
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_fs_youngest_rev (svn_revnum_t *youngest_p,
+ svn_fs_t *fs)
+{
+ svn_error_t *svn_err = 0;
+ apr_pool_t *pool = svn_pool_create (fs->pool);
+
+ svn_revnum_t youngest;
+ struct youngest_rev_args args;
+ args.youngest_p = &youngest;
+ args.fs = fs;
+
+ svn_err = svn_fs__retry_txn (fs, txn_body_youngest_rev, &args, pool);
+ /* Fall through. We must destroy pool. */
+ *youngest_p = youngest;
+
+ apr_pool_destroy (pool);
+ return svn_err;
+}
+
+
 
 /*
  * local variables:
Index: subversion/tests/libsvn_fs/fs-test.c
===================================================================
RCS file: /cvs/subversion/subversion/tests/libsvn_fs/fs-test.c,v
retrieving revision 1.10
diff -u -r1.10 fs-test.c
--- subversion/tests/libsvn_fs/fs-test.c 2001/02/05 20:12:56 1.10
+++ subversion/tests/libsvn_fs/fs-test.c 2001/02/26 08:58:33
@@ -113,6 +113,16 @@
                                          fs, fs->pool))
     return fail();
 
+ {
+ svn_revnum_t rev;
+
+ if (SVN_NO_ERROR != svn_fs_youngest_rev (&rev, fs))
+ return fail();
+
+ if (rev != 0)
+ return fail();
+ }
+
   if (SVN_NO_ERROR != svn_fs_close_fs (fs))
     return fail();
 

-- 
Yoshiki Hayashi
Received on Sat Oct 21 14:36:23 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.