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

Re: [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-21 13:57:36 CET

Hi All,
Reposting this patch after incorporating the comments raised by Dan on IRC.

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_SCHEMA): 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: kameshj
Suggested by: malcom
]]]

Index: subversion/libsvn_fs_util/merge-info-sqlite-index.c
===================================================================
--- subversion/libsvn_fs_util/merge-info-sqlite-index.c (revision 22777)
+++ subversion/libsvn_fs_util/merge-info-sqlite-index.c (working copy)
@@ -96,6 +96,21 @@
   "create index mi_c_revision_idx on mergeinfo_changed (revision);"
   APR_EOL_STR;
 
+/* Create the mergeinfo database with the proper schema if one already does
+ not exist. Sqlite was not friendlier enough to explicitly say that Table
+ does not exist.
+ As per sqlite docs SQLITE_ERROR === "SQL error or missing database".
+ Our queries will never cause SQL error, so we can assume SQLITE_ERROR to be
+ missing schema. Most likely caused by the newly upgraded repository created
+ originally by merge-tracking unaware svnadmin. */
+#define CREATE_MERGEINFO_SCHEMA(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 *
@@ -242,7 +257,7 @@
   deletestring = apr_psprintf(pool,
                               "delete from mergeinfo_changed where revision = %ld;",
                               new_rev);
- SVN_ERR(util_sqlite_exec(db, deletestring, NULL, NULL));
+ CREATE_MERGEINFO_SCHEMA(sqlite3_exec(db, deletestring, NULL, NULL, NULL), db);
   deletestring = apr_psprintf(pool,
                               "delete from mergeinfo where revision = %ld;",
                               new_rev);
@@ -502,6 +517,9 @@
   sqlite3_trace (db, sqlite_tracer, db);
 #endif
 
+ CREATE_MERGEINFO_SCHEMA(sqlite3_exec(db, "select 1 from mergeinfo",
+ NULL, NULL, NULL),
+ 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 21 13:57:40 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.