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

[PATCH][merge-tracking] generalized SQLITE_ERR macro

From: Kamesh Jayachandran <kamesh_at_collab.net>
Date: 2006-09-06 13:58:11 CEST

Hi All,

Find the attached patch and log.
This patch makes SQLITE_ERR to check for any expected value instead of
only 'SQLITE_OK'.

With regards
Kamesh Jayachandran

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

SQLITE_ERR has been made to check for expected value instead of
SQLITE_OK.

* subversion/libsvn_fs_fs/fs.h
  (SQLITE_ERR): accepts 'expected_val' and checks against the first argument.

* subversion/libsvn_fs_fs/tree.c
  (parse_mergeinfo_from_db): Adjust for above SQLITE_ERR change.
  (get_merge_info_for_path): Adjust for above SQLITE_ERR change.
  (fs_get_merge_info): Adjust for above SQLITE_ERR change.

* subversion/libsvn_fs_fs/fs_fs.c
  (index_path_merge_info): Adjust for above SQLITE_ERR change.
  (update_merge_info_index): Adjust for above SQLITE_ERR change.
  (svn_fs_fs__create): Adjust for above SQLITE_ERR change.
]]]

Index: subversion/libsvn_fs_fs/tree.c
===================================================================
--- subversion/libsvn_fs_fs/tree.c (revision 21362)
+++ subversion/libsvn_fs_fs/tree.c (working copy)
@@ -1107,26 +1107,23 @@
 
   SQLITE_ERR(sqlite3_prepare(db, "SELECT MAX(revision) from mergeinfo_changed"
                              " where path = ? and revision <= ?;",
- -1, &stmt, NULL), db);
- SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT), db);
- SQLITE_ERR(sqlite3_bind_int64(stmt, 2, rev), db);
- sqlite_result = sqlite3_step(stmt);
- if (sqlite_result != SQLITE_ROW)
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(db));
-
+ -1, &stmt, NULL), SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT), SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_bind_int64(stmt, 2, rev), SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_step(stmt), SQLITE_ROW, db);
   lastchanged_rev = sqlite3_column_int64(stmt, 0);
 
- SQLITE_ERR(sqlite3_finalize(stmt), db);
+ SQLITE_ERR(sqlite3_finalize(stmt), SQLITE_OK, db);
 
   SQLITE_ERR(sqlite3_prepare(db,
                              "SELECT mergedfrom, mergedrevstart,"
                              "mergedrevend from mergeinfo "
                              "where mergedto = ? and revision = ? "
                              "order by mergedfrom;",
- -1, &stmt, NULL), db);
- SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT), db);
- SQLITE_ERR(sqlite3_bind_int64(stmt, 2, lastchanged_rev), db);
+ -1, &stmt, NULL), SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT),
+ SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_bind_int64(stmt, 2, lastchanged_rev), SQLITE_OK, db);
   sqlite_result = sqlite3_step(stmt);
 
   /* It is possible the mergeinfo changed because of a delete, and
@@ -1171,17 +1168,13 @@
         }
       apr_hash_set(*result, mergedfrom, APR_HASH_KEY_STRING, pathranges);
 
- if (sqlite_result != SQLITE_DONE)
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(db));
+ SQLITE_ERR(sqlite_result, SQLITE_DONE, db);
     }
   else
- {
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(db));
- }
- SQLITE_ERR(sqlite3_finalize(stmt), db);
+ SQLITE_ERR(sqlite_result, !sqlite_result, db);
 
+ SQLITE_ERR(sqlite3_finalize(stmt), SQLITE_OK, db);
+
   return SVN_NO_ERROR;
 }
 
@@ -1243,17 +1236,15 @@
      then it can't have mergeinfo. */
   SQLITE_ERR(sqlite3_prepare(db, "SELECT COUNT(*) from mergeinfo_changed"
                              " where path = ? and revision <= ?;",
- -1, &stmt, NULL), db);
+ -1, &stmt, NULL), SQLITE_OK, db);
 
- SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT), db);
- SQLITE_ERR(sqlite3_bind_int64(stmt, 2, rev), db);
- sqlite_result = sqlite3_step(stmt);
- if (sqlite_result != SQLITE_ROW)
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(db));
+ SQLITE_ERR(sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT),
+ SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_bind_int64(stmt, 2, rev), SQLITE_OK, db);
+ SQLITE_ERR(sqlite3_step(stmt), SQLITE_ROW, db);
 
   count = sqlite3_column_int64(stmt, 0);
- SQLITE_ERR(sqlite3_finalize(stmt), db);
+ SQLITE_ERR(sqlite3_finalize(stmt), SQLITE_OK, db);
 
   /* If we've got mergeinfo data, transform it from the db into a
      mergeinfo hash */
@@ -1344,7 +1335,7 @@
   rev = svn_fs_revision_root_revision(root);
 
   SQLITE_ERR(sqlite3_open(svn_path_join(root->fs->path, "mergeinfo.db", pool),
- &db), db);
+ &db), SQLITE_OK, db);
 #ifdef SQLITE3_DEBUG
   sqlite3_trace (db, sqlite_tracer, db);
 #endif
@@ -1373,7 +1364,7 @@
           apr_hash_set(*mergeinfo, path, APR_HASH_KEY_STRING, mergestring->data);
         }
     }
- SQLITE_ERR(sqlite3_close(db), db);
+ SQLITE_ERR(sqlite3_close(db), SQLITE_OK, db);
   return SVN_NO_ERROR;
 }
 
Index: subversion/libsvn_fs_fs/fs_fs.c
===================================================================
--- subversion/libsvn_fs_fs/fs_fs.c (revision 21362)
+++ subversion/libsvn_fs_fs/fs_fs.c (working copy)
@@ -4024,44 +4024,39 @@
           int i;
           SQLITE_ERR(sqlite3_prepare(ftd->mtd,
                                      "INSERT INTO mergeinfo (revision, mergedto, mergedfrom, mergedrevstart, mergedrevend) VALUES (?, ?, ?, ?, ?);",
- -1, &stmt, NULL), ftd->mtd);
- SQLITE_ERR(sqlite3_bind_int64(stmt, 1, new_rev), ftd->mtd);
+ -1, &stmt, NULL), SQLITE_OK, ftd->mtd);
+ SQLITE_ERR(sqlite3_bind_int64(stmt, 1, new_rev), SQLITE_OK, ftd->mtd);
           SQLITE_ERR(sqlite3_bind_text(stmt, 2, path, -1, SQLITE_TRANSIENT),
- ftd->mtd);
+ SQLITE_OK, ftd->mtd);
           SQLITE_ERR(sqlite3_bind_text(stmt, 3, from, -1, SQLITE_TRANSIENT),
- ftd->mtd);
+ SQLITE_OK, ftd->mtd);
           for (i = 0; i < revlist->nelts; i++)
             {
               svn_merge_range_t *range;
               
               range = APR_ARRAY_IDX(revlist, i, svn_merge_range_t *);
               SQLITE_ERR(sqlite3_bind_int64(stmt, 4, range->start),
- ftd->mtd);
+ SQLITE_OK, ftd->mtd);
               SQLITE_ERR(sqlite3_bind_int64(stmt, 5, range->end),
- ftd->mtd);
- if (sqlite3_step(stmt) != SQLITE_DONE)
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(ftd->mtd));
-
- SQLITE_ERR(sqlite3_reset(stmt), ftd->mtd);
+ SQLITE_OK, ftd->mtd);
+ SQLITE_ERR(sqlite3_step(stmt), SQLITE_DONE, ftd->mtd);
+ SQLITE_ERR(sqlite3_reset(stmt), SQLITE_OK, ftd->mtd);
             }
- SQLITE_ERR(sqlite3_finalize(stmt), ftd->mtd);
+ SQLITE_ERR(sqlite3_finalize(stmt), SQLITE_OK, ftd->mtd);
         }
     }
   SQLITE_ERR (sqlite3_prepare(ftd->mtd,
                               "INSERT INTO mergeinfo_changed (revision, path) VALUES (?, ?);",
                               -1, &stmt, NULL),
- ftd->mtd);
- SQLITE_ERR(sqlite3_bind_int64(stmt, 1, new_rev), ftd->mtd);
+ SQLITE_OK, ftd->mtd);
+ SQLITE_ERR(sqlite3_bind_int64(stmt, 1, new_rev), SQLITE_OK, ftd->mtd);
   
   SQLITE_ERR(sqlite3_bind_text(stmt, 2, path, -1, SQLITE_TRANSIENT),
- ftd->mtd);
+ SQLITE_OK, ftd->mtd);
   
- if (sqlite3_step(stmt) != SQLITE_DONE)
- return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL,
- sqlite3_errmsg(ftd->mtd));
+ SQLITE_ERR(sqlite3_step(stmt), SQLITE_DONE, ftd->mtd);
   
- SQLITE_ERR(sqlite3_finalize(stmt), ftd->mtd);
+ SQLITE_ERR(sqlite3_finalize(stmt), SQLITE_OK, ftd->mtd);
   
   return SVN_NO_ERROR;
 }
@@ -4117,7 +4112,7 @@
   fs_txn_data_t *ftd = cb->txn->fsap_data;
       
   SQLITE_ERR(sqlite3_open(path_mergeinfo_db(cb->fs, pool),
- &ftd->mtd), ftd->mtd);
+ &ftd->mtd), SQLITE_OK, ftd->mtd);
 #ifdef SQLITE3_DEBUG
   sqlite3_trace (ftd->mtd, sqlite_tracer, ftd->mtd);
 #endif
@@ -4144,7 +4139,7 @@
      the current file, we just end up with inaccessible data in the
      database, not a real problem. */
   SVN_ERR(fs_sqlite_exec(ftd->mtd, "commit transaction;", NULL, NULL));
- SQLITE_ERR(sqlite3_close(ftd->mtd), ftd->mtd);
+ SQLITE_ERR(sqlite3_close(ftd->mtd), SQLITE_OK, ftd->mtd);
 
   return SVN_NO_ERROR;
 }
@@ -4390,7 +4385,7 @@
   fs->path = apr_pstrdup(pool, path);
 
   SQLITE_ERR(sqlite3_open(path_mergeinfo_db(fs, pool), &ffd->mtd),
- ffd->mtd);
+ SQLITE_OK, ffd->mtd);
 #ifdef SQLITE3_DEBUG
   sqlite3_trace (ffd->mtd, sqlite_tracer, ffd->mtd);
 #endif
@@ -4422,7 +4417,7 @@
           (path_format(fs, pool), format, pool));
   ((fs_fs_data_t *) fs->fsap_data)->format = format;
   
- SQLITE_ERR(sqlite3_close(ffd->mtd), ffd->mtd);
+ SQLITE_ERR(sqlite3_close(ffd->mtd), SQLITE_OK, ffd->mtd);
 
   ffd->mtd = NULL;
 
Index: subversion/libsvn_fs_fs/fs.h
===================================================================
--- subversion/libsvn_fs_fs/fs.h (revision 21362)
+++ subversion/libsvn_fs_fs/fs.h (working copy)
@@ -214,11 +214,11 @@
                             sqlite3_callback cb, void *data);
 
 /* SQLITE->SVN quick error wrap, much like SVN_ERR.
- XXX: This macro probably belongs elsehwere, like svn_sqlite.h or
+ XXX: This macro probably belongs elsewhere, like svn_sqlite.h or
    something. Later. */
-#define SQLITE_ERR(x, db) do \
+#define SQLITE_ERR(x, expected_val, db) do \
 { \
- if ((x) != SQLITE_OK) \
+ if ((x) != expected_val) \
     return svn_error_create(SVN_ERR_FS_SQLITE_ERROR, NULL, \
                             sqlite3_errmsg((db))); \
  } while (0)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Sep 6 13:58:47 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.