summaryrefslogtreecommitdiff
path: root/subversion/libsvn_fs_fs/rep-cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/libsvn_fs_fs/rep-cache.c')
-rw-r--r--subversion/libsvn_fs_fs/rep-cache.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/subversion/libsvn_fs_fs/rep-cache.c b/subversion/libsvn_fs_fs/rep-cache.c
index 437d60381ddb7..b0b81fad9ac38 100644
--- a/subversion/libsvn_fs_fs/rep-cache.c
+++ b/subversion/libsvn_fs_fs/rep-cache.c
@@ -24,6 +24,7 @@
#include "svn_private_config.h"
+#include "cached_data.h"
#include "fs_fs.h"
#include "fs.h"
#include "rep-cache.h"
@@ -35,9 +36,6 @@
#include "rep-cache-db.h"
-/* A few magic values */
-#define REP_CACHE_SCHEMA_FORMAT 1
-
REP_CACHE_DB_SQL_DECLARE_STATEMENTS(statements);
@@ -50,13 +48,6 @@ path_rep_cache_db(const char *fs_path,
return svn_dirent_join(fs_path, REP_CACHE_DB_NAME, result_pool);
}
-#define SVN_ERR_CLOSE(x, db) do \
-{ \
- svn_error_t *svn__err = (x); \
- if (svn__err) \
- return svn_error_compose_create(svn__err, svn_sqlite__close(db)); \
-} while (0)
-
/** Library-private API's. **/
@@ -106,12 +97,19 @@ open_rep_cache(void *baton,
0, NULL, 0,
fs->pool, pool));
- SVN_ERR_CLOSE(svn_sqlite__read_schema_version(&version, sdb, pool), sdb);
- if (version < REP_CACHE_SCHEMA_FORMAT)
+ SVN_SQLITE__ERR_CLOSE(svn_sqlite__read_schema_version(&version, sdb, pool),
+ sdb);
+ /* If we have an uninitialized database, go ahead and create the schema. */
+ if (version <= 0)
{
- /* Must be 0 -- an uninitialized (no schema) database. Create
- the schema. Results in schema version of 1. */
- SVN_ERR_CLOSE(svn_sqlite__exec_statements(sdb, STMT_CREATE_SCHEMA), sdb);
+ int stmt;
+
+ if (ffd->format >= SVN_FS_FS__MIN_REP_CACHE_SCHEMA_V2_FORMAT)
+ stmt = STMT_CREATE_SCHEMA_V2;
+ else
+ stmt = STMT_CREATE_SCHEMA_V1;
+
+ SVN_SQLITE__ERR_CLOSE(svn_sqlite__exec_statements(sdb, stmt), sdb);
}
/* This is used as a flag that the database is available so don't
@@ -263,7 +261,7 @@ svn_fs_fs__walk_rep_reference(svn_fs_t *fs,
If you extend this function, check the callsite to see if you have
to make it not-ignore additional error codes. */
svn_error_t *
-svn_fs_fs__get_rep_reference(representation_t **rep,
+svn_fs_fs__get_rep_reference(representation_t **rep_p,
svn_fs_t *fs,
svn_checksum_t *checksum,
apr_pool_t *pool)
@@ -271,6 +269,7 @@ svn_fs_fs__get_rep_reference(representation_t **rep,
fs_fs_data_t *ffd = fs->fsap_data;
svn_sqlite__stmt_t *stmt;
svn_boolean_t have_row;
+ representation_t *rep;
SVN_ERR_ASSERT(ffd->rep_sharing_allowed);
if (! ffd->rep_cache_db)
@@ -289,26 +288,28 @@ svn_fs_fs__get_rep_reference(representation_t **rep,
SVN_ERR(svn_sqlite__step(&have_row, stmt));
if (have_row)
{
- *rep = apr_pcalloc(pool, sizeof(**rep));
- svn_fs_fs__id_txn_reset(&(*rep)->txn_id);
- memcpy((*rep)->sha1_digest, checksum->digest,
- sizeof((*rep)->sha1_digest));
- (*rep)->has_sha1 = TRUE;
- (*rep)->revision = svn_sqlite__column_revnum(stmt, 0);
- (*rep)->item_index = svn_sqlite__column_int64(stmt, 1);
- (*rep)->size = svn_sqlite__column_int64(stmt, 2);
- (*rep)->expanded_size = svn_sqlite__column_int64(stmt, 3);
+ rep = apr_pcalloc(pool, sizeof(*rep));
+ svn_fs_fs__id_txn_reset(&(rep->txn_id));
+ memcpy(rep->sha1_digest, checksum->digest, sizeof(rep->sha1_digest));
+ rep->has_sha1 = TRUE;
+ rep->revision = svn_sqlite__column_revnum(stmt, 0);
+ rep->item_index = svn_sqlite__column_int64(stmt, 1);
+ rep->size = svn_sqlite__column_int64(stmt, 2);
+ rep->expanded_size = svn_sqlite__column_int64(stmt, 3);
}
else
- *rep = NULL;
+ rep = NULL;
SVN_ERR(svn_sqlite__reset(stmt));
- if (*rep)
+ if (rep)
{
+ svn_error_t *err;
+
+ SVN_ERR(svn_fs_fs__fixup_expanded_size(fs, rep, pool));
+
/* Check that REP refers to a revision that exists in FS. */
- svn_error_t *err = svn_fs_fs__ensure_revision_exists((*rep)->revision,
- fs, pool);
+ err = svn_fs_fs__ensure_revision_exists(rep->revision, fs, pool);
if (err)
return svn_error_createf(SVN_ERR_FS_CORRUPT, err,
"Checksum '%s' in rep-cache is beyond HEAD",
@@ -316,6 +317,7 @@ svn_fs_fs__get_rep_reference(representation_t **rep,
pool));
}
+ *rep_p = rep;
return SVN_NO_ERROR;
}