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

[PATCH][merge-tracking]Create mergeinfo.db with proper schema in case it does not exist.

From: Kamesh Jayachandran <kamesh_at_collab.net>
Date: 2006-12-14 13:47:15 CET

Hi All,
Find the attached patch and log.

With regards
Kamesh Jayachandran

[[[

Create mergeinfo.db with the necessary schema if the db does not exist with
one.

* subversion/libsvn_fs_util/merge-info-sqlite-index.c
  (CREATE_MERGEINFO_INDEX): New macro.
  (svn_fs_merge_info__update_index):
   Create the default merge-tracking sqlite schema on first failure of sqlite
   operation.
  (svn_fs_merge_info__get_merge_info):
   Create the default merge-tracking sqlite schema on first failure of sqlite
   operation.

Patch by: Kamesh Jayachandran <kamesh@collab.net>
]]]

Index: subversion/libsvn_fs_util/merge-info-sqlite-index.c
===================================================================
--- subversion/libsvn_fs_util/merge-info-sqlite-index.c (revision 22704)
+++ subversion/libsvn_fs_util/merge-info-sqlite-index.c (working copy)
@@ -96,6 +96,20 @@
   "create index mi_c_revision_idx on mergeinfo_changed (revision);"
   APR_EOL_STR;
 
+/* Create the mergeinfo database with the schema for upgraded repositories.
+ Sqlite was not friendlier enough to explicitly say that Table does not
+ exist. If it says SQLITE_ERROR then we can assume the sqlite database
+ do not have merge-tracking schema.
+ SQLITE_ERROR === "SQL error or missing database" as per sqlite docs. */
+
+#define CREATE_MERGEINFO_INDEX(x, db) do \
+{ \
+ if ((x) == SQLITE_ERROR) \
+ SVN_ERR(util_sqlite_exec(db, SVN_MTD_CREATE_SQL, NULL, NULL)); \
+ else \
+ SQLITE_ERR((x), db); \
+} while (0)
+
 /* Create an sqlite DB for our merge info index under PATH. Use POOL
    for temporary allocations. */
 svn_error_t *
@@ -228,6 +242,7 @@
                                 apr_pool_t *pool)
 {
   const char *deletestring;
+ char *err_msg;
 
   sqlite3 *db;
 
@@ -242,7 +257,8 @@
   deletestring = apr_psprintf(pool,
                               "delete from mergeinfo_changed where revision = %ld;",
                               new_rev);
- SVN_ERR(util_sqlite_exec(db, deletestring, NULL, NULL));
+ CREATE_MERGEINFO_INDEX(sqlite3_exec(db, deletestring, NULL, NULL, &err_msg),
+ db);
   deletestring = apr_psprintf(pool,
                               "delete from mergeinfo where revision = %ld;",
                               new_rev);
@@ -490,6 +506,7 @@
   sqlite3 *db;
   int i;
   svn_revnum_t rev;
+ char *err_msg;
 
   /* We require a revision root. */
   if (root->is_txn_root)
@@ -502,6 +519,9 @@
   sqlite3_trace (db, sqlite_tracer, db);
 #endif
 
+ CREATE_MERGEINFO_INDEX(sqlite3_exec(db, "select 1 from mergeinfo",
+ NULL, NULL, &err_msg),
+ db);
   *mergeinfo = apr_hash_make (pool);
   for (i = 0; i < paths->nelts; i++)
     {

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Dec 14 13:47:20 2006

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