Author: hwright
Date: Thu May 5 19:50:39 2011
New Revision: 1099941
URL: http://svn.apache.org/viewvc?rev=1099941&view=rev
Log:
Fold a couple of small wc_db utility files into each other.
* subversion/libsvn_wc/wc_db_txn.c:
Remove, moving content to...
* subversion/libsvn_wc/wc_db_util.c:
...here.
Removed:
subversion/trunk/subversion/libsvn_wc/wc_db_txn.c
Modified:
subversion/trunk/subversion/libsvn_wc/wc_db_util.c
Modified: subversion/trunk/subversion/libsvn_wc/wc_db_util.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db_util.c?rev=1099941&r1=1099940&r2=1099941&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db_util.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db_util.c Thu May 5 19:50:39 2011
@@ -91,3 +91,59 @@ svn_wc__db_util_open_db(svn_sqlite__db_t
0, NULL,
result_pool, scratch_pool));
}
+
+
+/* Some helpful transaction helpers.
+
+ Instead of directly using SQLite transactions, these wrappers take care of
+ simple cases by allowing consumers to worry about wrapping the wcroot and
+ local_relpath, which are almost always used within the transaction.
+
+ This also means if we later want to implement some wc_db-specific txn
+ handling, we have a convenient place to do it.
+ */
+
+/* A callback which supplies WCROOTs and LOCAL_RELPATHs. */
+typedef svn_error_t *(*db_txn_callback_t)(void *baton,
+ svn_wc__db_wcroot_t *wcroot,
+ const char *local_relpath,
+ apr_pool_t *scratch_pool);
+
+/* Baton for use with run_txn() and with_db_txn(). */
+struct txn_baton_t
+{
+ svn_wc__db_wcroot_t *wcroot;
+ const char *local_relpath;
+
+ db_txn_callback_t cb_func;
+ void *cb_baton;
+};
+
+
+/* Unwrap the sqlite transaction into a wc_db txn.
+ Implements svn_sqlite__transaction_callback_t. */
+static svn_error_t *
+run_txn(void *baton, svn_sqlite__db_t *db, apr_pool_t *scratch_pool)
+{
+ struct txn_baton_t *tb = baton;
+
+ return svn_error_return(
+ tb->cb_func(tb->cb_baton, tb->wcroot, tb->local_relpath, scratch_pool));
+}
+
+
+/* Run CB_FUNC in a SQLite transaction with CB_BATON, using WCROOT and
+ LOCAL_RELPATH. If callbacks require additional information, they may
+ provide it using CB_BATON. */
+svn_error_t *
+svn_wc__db_with_txn(svn_wc__db_wcroot_t *wcroot,
+ const char *local_relpath,
+ svn_wc__db_txn_callback_t cb_func,
+ void *cb_baton,
+ apr_pool_t *scratch_pool)
+{
+ struct txn_baton_t tb = { wcroot, local_relpath, cb_func, cb_baton };
+
+ return svn_error_return(
+ svn_sqlite__with_lock(wcroot->sdb, run_txn, &tb, scratch_pool));
+}