You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2011/03/14 20:32:04 UTC
svn commit: r1081528 [2/2] - in /subversion/trunk/subversion/libsvn_wc:
wc_db.c wc_db_pristine.c wc_db_private.h wc_db_txn.c
Copied: subversion/trunk/subversion/libsvn_wc/wc_db_txn.c (from r1081515, subversion/trunk/subversion/libsvn_wc/wc_db.c)
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db_txn.c?p2=subversion/trunk/subversion/libsvn_wc/wc_db_txn.c&p1=subversion/trunk/subversion/libsvn_wc/wc_db.c&r1=1081515&r2=1081528&rev=1081528&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db_txn.c Mon Mar 14 19:32:04 2011
@@ -30,285 +30,14 @@
#include "svn_types.h"
#include "svn_error.h"
#include "svn_dirent_uri.h"
-#include "svn_path.h"
-#include "svn_hash.h"
-#include "svn_wc.h"
-#include "svn_checksum.h"
-#include "svn_pools.h"
-#include "wc.h"
#include "wc_db.h"
-#include "adm_files.h"
-#include "wc-queries.h"
-#include "entries.h"
-#include "lock.h"
-#include "tree_conflicts.h"
#include "wc_db_private.h"
-#include "workqueue.h"
#include "svn_private_config.h"
#include "private/svn_sqlite.h"
-#include "private/svn_skel.h"
-#include "private/svn_wc_private.h"
-#include "private/svn_token.h"
-#define NOT_IMPLEMENTED() SVN__NOT_IMPLEMENTED()
-
-
-/*
- * Some filename constants.
- */
-#define SDB_FILE "wc.db"
-#define SDB_FILE_UPGRADE "wc.db.upgrade"
-
-#define WCROOT_TEMPDIR_RELPATH "tmp"
-
-
-/*
- * PARAMETER ASSERTIONS
- *
- * Every (semi-)public entrypoint in this file has a set of assertions on
- * the parameters passed into the function. Since this is a brand new API,
- * we want to make sure that everybody calls it properly. The original WC
- * code had years to catch stray bugs, but we do not have that luxury in
- * the wc-nb rewrite. Any extra assurances that we can find will be
- * welcome. The asserts will ensure we have no doubt about the values
- * passed into the function.
- *
- * Some parameters are *not* specifically asserted. Typically, these are
- * params that will be used immediately, so something like a NULL value
- * will be obvious.
- *
- * ### near 1.7 release, it would be a Good Thing to review the assertions
- * ### and decide if any can be removed or switched to assert() in order
- * ### to remove their runtime cost in the production release.
- *
- *
- * DATABASE OPERATIONS
- *
- * Each function should leave the database in a consistent state. If it
- * does *not*, then the implication is some other function needs to be
- * called to restore consistency. Subtle requirements like that are hard
- * to maintain over a long period of time, so this API will not allow it.
- *
- *
- * STANDARD VARIABLE NAMES
- *
- * db working copy database (this module)
- * sdb SQLite database (not to be confused with 'db')
- * wc_id a WCROOT id associated with a node
- */
-
-#define INVALID_REPOS_ID ((apr_int64_t) -1)
-#define UNKNOWN_WC_ID ((apr_int64_t) -1)
-#define FORMAT_FROM_SDB (-1)
-
-/* This is a character used to escape itself and the globbing character in
- globbing sql expressions below. See escape_sqlite_like().
-
- NOTE: this should match the character used within wc-metadata.sql */
-#define LIKE_ESCAPE_CHAR "#"
-
-/* Calculates the depth of the relpath below "" */
-APR_INLINE static int relpath_depth(const char *relpath)
-{
- int n = 1;
- if (*relpath == '\0')
- return 0;
-
- do
- {
- if (*relpath == '/')
- n++;
- }
- while (*(++relpath));
-
- return n;
-}
-
-
-int svn_wc__db_op_depth_for_upgrade(const char *local_relpath)
-{
- return relpath_depth(local_relpath);
-}
-
-
-typedef struct insert_base_baton_t {
- /* common to all insertions into BASE */
- svn_wc__db_status_t status;
- svn_wc__db_kind_t kind;
- apr_int64_t repos_id;
- const char *repos_relpath;
- svn_revnum_t revision;
-
- /* common to all "normal" presence insertions */
- const apr_hash_t *props;
- svn_revnum_t changed_rev;
- apr_time_t changed_date;
- const char *changed_author;
- apr_hash_t *dav_cache;
-
- /* for inserting directories */
- const apr_array_header_t *children;
- svn_depth_t depth;
-
- /* for inserting files */
- const svn_checksum_t *checksum;
- svn_filesize_t translated_size;
-
- /* for inserting symlinks */
- const char *target;
-
- /* may need to insert/update ACTUAL to record a conflict */
- const svn_skel_t *conflict;
-
- /* may have work items to queue in this transaction */
- const svn_skel_t *work_items;
-
-} insert_base_baton_t;
-
-
-typedef struct insert_working_baton_t {
- /* common to all insertions into WORKING (including NODE_DATA) */
- svn_wc__db_status_t presence;
- svn_wc__db_kind_t kind;
- apr_int64_t op_depth;
-
- /* common to all "normal" presence insertions */
- const apr_hash_t *props;
- svn_revnum_t changed_rev;
- apr_time_t changed_date;
- const char *changed_author;
- apr_int64_t original_repos_id;
- const char *original_repos_relpath;
- svn_revnum_t original_revnum;
- svn_boolean_t moved_here;
-
- /* for inserting directories */
- const apr_array_header_t *children;
- svn_depth_t depth;
-
- /* for inserting (copied/moved-here) files */
- const svn_checksum_t *checksum;
-
- /* for inserting symlinks */
- const char *target;
-
- /* may have work items to queue in this transaction */
- const svn_skel_t *work_items;
-
-} insert_working_baton_t;
-
-
-static const svn_token_map_t kind_map[] = {
- { "file", svn_wc__db_kind_file },
- { "dir", svn_wc__db_kind_dir },
- { "symlink", svn_wc__db_kind_symlink },
- { "unknown", svn_wc__db_kind_unknown },
- { NULL }
-};
-
-/* Note: we only decode presence values from the database. These are a subset
- of all the status values. */
-static const svn_token_map_t presence_map[] = {
- { "normal", svn_wc__db_status_normal },
- { "absent", svn_wc__db_status_absent },
- { "excluded", svn_wc__db_status_excluded },
- { "not-present", svn_wc__db_status_not_present },
- { "incomplete", svn_wc__db_status_incomplete },
- { "base-deleted", svn_wc__db_status_base_deleted },
- { NULL }
-};
-
-
-/* Forward declarations */
-static svn_error_t *
-add_work_items(svn_sqlite__db_t *sdb,
- const svn_skel_t *skel,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-insert_incomplete_children(svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *local_relpath,
- apr_int64_t repos_id,
- const char *repos_relpath,
- svn_revnum_t revision,
- const apr_array_header_t *children,
- apr_int64_t op_depth,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-db_read_pristine_props(apr_hash_t **props,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-read_info(svn_wc__db_status_t *status,
- svn_wc__db_kind_t *kind,
- svn_revnum_t *revision,
- const char **repos_relpath,
- apr_int64_t *repos_id,
- svn_revnum_t *changed_rev,
- apr_time_t *changed_date,
- const char **changed_author,
- apr_time_t *last_mod_time,
- svn_depth_t *depth,
- const svn_checksum_t **checksum,
- svn_filesize_t *translated_size,
- const char **target,
- const char **changelist,
- const char **original_repos_relpath,
- apr_int64_t *original_repos_id,
- svn_revnum_t *original_revision,
- svn_boolean_t *props_mod,
- svn_boolean_t *have_base,
- svn_boolean_t *have_work,
- svn_boolean_t *conflicted,
- svn_wc__db_lock_t **lock,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-scan_addition(svn_wc__db_status_t *status,
- const char **op_root_relpath,
- const char **repos_relpath,
- apr_int64_t *repos_id,
- const char **original_repos_relpath,
- apr_int64_t *original_repos_id,
- svn_revnum_t *original_revision,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-scan_deletion(const char **base_del_relpath,
- const char **moved_to_relpath,
- const char **work_del_relpath,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
-
-static svn_error_t *
-convert_to_working_status(svn_wc__db_status_t *working_status,
- svn_wc__db_status_t status);
-
-static svn_error_t *
-wclock_owns_lock(svn_boolean_t *own_lock,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- svn_boolean_t exact,
- apr_pool_t *scratch_pool);
-
-
-
/* Some helpful transaction helpers.
Instead of directly using SQLite transactions, these wrappers take care of
@@ -351,9303 +80,15 @@ run_txn(void *baton, svn_sqlite__db_t *d
/* 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. */
-static svn_error_t *
-with_db_txn(svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- db_txn_callback_t cb_func,
- void *cb_baton,
- apr_pool_t *scratch_pool)
+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));
}
-
-
-
-/* Return the absolute path, in local path style, of LOCAL_RELPATH
- in WCROOT. */
-static const char *
-path_for_error_message(const svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool)
-{
- const char *local_abspath
- = svn_dirent_join(wcroot->abspath, local_relpath, result_pool);
-
- return svn_dirent_local_style(local_abspath, result_pool);
-}
-
-
-/* Return a file size from column SLOT of the SQLITE statement STMT, or
- SVN_INVALID_FILESIZE if the column value is NULL. */
-static svn_filesize_t
-get_translated_size(svn_sqlite__stmt_t *stmt, int slot)
-{
- if (svn_sqlite__column_is_null(stmt, slot))
- return SVN_INVALID_FILESIZE;
- return svn_sqlite__column_int64(stmt, slot);
-}
-
-
-/* Return a lock info structure constructed from the given columns of the
- SQLITE statement STMT, or return NULL if the token column value is null. */
-static svn_wc__db_lock_t *
-lock_from_columns(svn_sqlite__stmt_t *stmt,
- int col_token,
- int col_owner,
- int col_comment,
- int col_date,
- apr_pool_t *result_pool)
-{
- svn_wc__db_lock_t *lock;
-
- if (svn_sqlite__column_is_null(stmt, col_token))
- {
- lock = NULL;
- }
- else
- {
- lock = apr_pcalloc(result_pool, sizeof(svn_wc__db_lock_t));
- lock->token = svn_sqlite__column_text(stmt, col_token, result_pool);
- lock->owner = svn_sqlite__column_text(stmt, col_owner, result_pool);
- lock->comment = svn_sqlite__column_text(stmt, col_comment, result_pool);
- lock->date = svn_sqlite__column_int64(stmt, col_date);
- }
- return lock;
-}
-
-
-/* */
-static const char *
-escape_sqlite_like(const char * const str, apr_pool_t *result_pool)
-{
- char *result;
- const char *old_ptr;
- char *new_ptr;
- int len = 0;
-
- /* Count the number of extra characters we'll need in the escaped string.
- We could just use the worst case (double) value, but we'd still need to
- iterate over the string to get it's length. So why not do something
- useful why iterating over it, and save some memory at the same time? */
- for (old_ptr = str; *old_ptr; ++old_ptr)
- {
- len++;
- if (*old_ptr == '%'
- || *old_ptr == '_'
- || *old_ptr == LIKE_ESCAPE_CHAR[0])
- len++;
- }
-
- result = apr_palloc(result_pool, len + 1);
-
- /* Now do the escaping. */
- for (old_ptr = str, new_ptr = result; *old_ptr; ++old_ptr, ++new_ptr)
- {
- if (*old_ptr == '%'
- || *old_ptr == '_'
- || *old_ptr == LIKE_ESCAPE_CHAR[0])
- *(new_ptr++) = LIKE_ESCAPE_CHAR[0];
- *new_ptr = *old_ptr;
- }
- *new_ptr = '\0';
-
- return result;
-}
-
-
-/* Return a string that can be used as the argument to a SQLite 'LIKE'
- operator, in order to match any path that is a child of LOCAL_RELPATH
- (at any depth below LOCAL_RELPATH), *excluding* LOCAL_RELPATH itself.
- LOCAL_RELPATH may be the empty string, in which case the result will
- match any path except the empty path.
-
- Allocate the result either statically or in RESULT_POOL. */
-static const char *construct_like_arg(const char *local_relpath,
- apr_pool_t *result_pool)
-{
- if (local_relpath[0] == '\0')
- return "_%";
-
- return apr_pstrcat(result_pool,
- escape_sqlite_like(local_relpath, result_pool),
- "/%", (char *)NULL);
-}
-
-
-/* Look up REPOS_ID in SDB and set *REPOS_ROOT_URL and/or *REPOS_UUID to
- its root URL and UUID respectively. If REPOS_ID is INVALID_REPOS_ID,
- use NULL for both URL and UUID. Either or both output parameters may be
- NULL if not wanted. */
-static svn_error_t *
-fetch_repos_info(const char **repos_root_url,
- const char **repos_uuid,
- svn_sqlite__db_t *sdb,
- apr_int64_t repos_id,
- apr_pool_t *result_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- if (!repos_root_url && !repos_uuid)
- return SVN_NO_ERROR;
-
- if (repos_id == INVALID_REPOS_ID)
- {
- if (repos_root_url)
- *repos_root_url = NULL;
- if (repos_uuid)
- *repos_uuid = NULL;
- return SVN_NO_ERROR;
- }
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
- STMT_SELECT_REPOSITORY_BY_ID));
- SVN_ERR(svn_sqlite__bindf(stmt, "i", repos_id));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (!have_row)
- return svn_error_createf(SVN_ERR_WC_CORRUPT, svn_sqlite__reset(stmt),
- _("No REPOSITORY table entry for id '%ld'"),
- (long int)repos_id);
-
- if (repos_root_url)
- *repos_root_url = svn_sqlite__column_text(stmt, 0, result_pool);
- if (repos_uuid)
- *repos_uuid = svn_sqlite__column_text(stmt, 1, result_pool);
-
- return svn_error_return(svn_sqlite__reset(stmt));
-}
-
-
-/* Set *REPOS_ID, *REVISION and *REPOS_RELPATH from the
- given columns of the SQLITE statement STMT, or to NULL if the respective
- column value is null. Any of the output parameters may be NULL if not
- required. */
-static svn_error_t *
-repos_location_from_columns(apr_int64_t *repos_id,
- svn_revnum_t *revision,
- const char **repos_relpath,
- svn_sqlite__stmt_t *stmt,
- int col_repos_id,
- int col_revision,
- int col_repos_relpath,
- apr_pool_t *result_pool)
-{
- svn_error_t *err = SVN_NO_ERROR;
-
- if (repos_id)
- {
- /* Fetch repository information via REPOS_ID. */
- if (svn_sqlite__column_is_null(stmt, col_repos_id))
- *repos_id = INVALID_REPOS_ID;
- else
- *repos_id = svn_sqlite__column_int64(stmt, col_repos_id);
- }
- if (revision)
- {
- *revision = svn_sqlite__column_revnum(stmt, col_revision);
- }
- if (repos_relpath)
- {
- *repos_relpath = svn_sqlite__column_text(stmt, col_repos_relpath,
- result_pool);
- }
-
- return err;
-}
-
-
-/* Set *REPOS_ID and *REPOS_RELPATH to the BASE node of LOCAL_RELPATH.
- Either of REPOS_ID and REPOS_RELPATH may be NULL if not wanted. */
-static svn_error_t *
-scan_upwards_for_repos(apr_int64_t *repos_id,
- const char **repos_relpath,
- const svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- SVN_ERR_ASSERT(wcroot->sdb != NULL && wcroot->wc_id != UNKNOWN_WC_ID);
- SVN_ERR_ASSERT(repos_id != NULL || repos_relpath != NULL);
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, STMT_SELECT_BASE_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
-
- if (!have_row)
- {
- svn_error_t *err = svn_error_createf(
- SVN_ERR_WC_PATH_NOT_FOUND, NULL,
- _("The node '%s' was not found."),
- path_for_error_message(wcroot, local_relpath, scratch_pool));
-
- return svn_error_compose_create(err, svn_sqlite__reset(stmt));
- }
-
- SVN_ERR_ASSERT(!svn_sqlite__column_is_null(stmt, 0));
- SVN_ERR_ASSERT(!svn_sqlite__column_is_null(stmt, 1));
-
- if (repos_id)
- *repos_id = svn_sqlite__column_int64(stmt, 0);
- if (repos_relpath)
- *repos_relpath = svn_sqlite__column_text(stmt, 1, result_pool);
- return svn_sqlite__reset(stmt);
-}
-
-
-/* Get the statement given by STMT_IDX, and bind the appropriate wc_id and
- local_relpath based upon LOCAL_ABSPATH. Store it in *STMT, and use
- SCRATCH_POOL for temporary allocations.
-
- Note: WC_ID and LOCAL_RELPATH must be arguments 1 and 2 in the statement. */
-static svn_error_t *
-get_statement_for_path(svn_sqlite__stmt_t **stmt,
- svn_wc__db_t *db,
- const char *local_abspath,
- int stmt_idx,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(svn_sqlite__get_statement(stmt, wcroot->sdb, stmt_idx));
- SVN_ERR(svn_sqlite__bindf(*stmt, "is", wcroot->wc_id, local_relpath));
-
- return SVN_NO_ERROR;
-}
-
-
-/* For a given REPOS_ROOT_URL/REPOS_UUID pair, return the existing REPOS_ID
- value. If one does not exist, then create a new one. */
-static svn_error_t *
-create_repos_id(apr_int64_t *repos_id,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_sqlite__db_t *sdb,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *get_stmt;
- svn_sqlite__stmt_t *insert_stmt;
- svn_boolean_t have_row;
-
- SVN_ERR(svn_sqlite__get_statement(&get_stmt, sdb, STMT_SELECT_REPOSITORY));
- SVN_ERR(svn_sqlite__bindf(get_stmt, "s", repos_root_url));
- SVN_ERR(svn_sqlite__step(&have_row, get_stmt));
-
- if (have_row)
- {
- *repos_id = svn_sqlite__column_int64(get_stmt, 0);
- return svn_error_return(svn_sqlite__reset(get_stmt));
- }
- SVN_ERR(svn_sqlite__reset(get_stmt));
-
- /* NOTE: strictly speaking, there is a race condition between the
- above query and the insertion below. We're simply going to ignore
- that, as it means two processes are *modifying* the working copy
- at the same time, *and* new repositores are becoming visible.
- This is rare enough, let alone the miniscule chance of hitting
- this race condition. Further, simply failing out will leave the
- database in a consistent state, and the user can just re-run the
- failed operation. */
-
- SVN_ERR(svn_sqlite__get_statement(&insert_stmt, sdb,
- STMT_INSERT_REPOSITORY));
- SVN_ERR(svn_sqlite__bindf(insert_stmt, "ss", repos_root_url, repos_uuid));
- return svn_error_return(svn_sqlite__insert(repos_id, insert_stmt));
-}
-
-
-/* Initialize the baton with appropriate "blank" values. This allows the
- insertion function to leave certain columns null. */
-static void
-blank_ibb(insert_base_baton_t *pibb)
-{
- memset(pibb, 0, sizeof(*pibb));
- pibb->revision = SVN_INVALID_REVNUM;
- pibb->changed_rev = SVN_INVALID_REVNUM;
- pibb->depth = svn_depth_infinity;
- pibb->translated_size = SVN_INVALID_FILESIZE;
-}
-
-
-/* Extend any delete of the parent of LOCAL_RELPATH to LOCAL_RELPATH.
-
- Given a wc:
-
- 0 1 2 3 4
- normal
- A normal
- A/B normal normal
- A/B/C not-pres normal
- A/B/C/D normal
-
- That is checkout, delete A/B, copy a replacement A/B, delete copied
- child A/B/C, add replacement A/B/C, add A/B/C/D.
-
- Now an update that adds base nodes for A/B/C, A/B/C/D and A/B/C/D/E
- must extend the A/B deletion:
-
- 0 1 2 3 4
- normal
- A normal
- A/B normal normal
- A/B/C normal not-pres normal
- A/B/C/D normal base-del normal
- A/B/C/D/E normal base-del
-
- When adding a base node if the parent has a working node then the
- parent base is deleted and this must be extended to cover new base
- node.
-
- In the example above A/B/C/D and A/B/C/D/E are the nodes that get
- the extended delete, A/B/C is already deleted.
- */
-static svn_error_t *
-extend_parent_delete(svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *local_relpath,
- apr_pool_t *scratch_pool)
-{
- svn_boolean_t have_row;
- svn_sqlite__stmt_t *stmt;
- apr_int64_t parent_op_depth;
- const char *parent_relpath = svn_relpath_dirname(local_relpath, scratch_pool);
-
- SVN_ERR_ASSERT(local_relpath[0]);
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
- STMT_SELECT_LOWEST_WORKING_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, parent_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (have_row)
- parent_op_depth = svn_sqlite__column_int64(stmt, 0);
- SVN_ERR(svn_sqlite__reset(stmt));
- if (have_row)
- {
- apr_int64_t op_depth;
-
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (have_row)
- op_depth = svn_sqlite__column_int64(stmt, 0);
- SVN_ERR(svn_sqlite__reset(stmt));
- if (!have_row || parent_op_depth < op_depth)
- {
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
- STMT_INSERT_WORKING_NODE_FROM_BASE));
- SVN_ERR(svn_sqlite__bindf(stmt, "isit", wc_id,
- local_relpath, parent_op_depth,
- presence_map,
- svn_wc__db_status_base_deleted));
- SVN_ERR(svn_sqlite__update(NULL, stmt));
- }
- }
-
- return SVN_NO_ERROR;
-}
-
-
-/* This is the reverse of extend_parent_delete.
-
- When removing a base node if the parent has a working node then the
- parent base and this node are both deleted and so the delete of
- this node must be removed.
- */
-static svn_error_t *
-retract_parent_delete(svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *local_relpath,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
- STMT_DELETE_LOWEST_WORKING_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step_done(stmt));
-
- return SVN_NO_ERROR;
-}
-
-
-
-/* */
-static svn_error_t *
-insert_base_node(void *baton,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *scratch_pool)
-{
- const insert_base_baton_t *pibb = baton;
- svn_sqlite__stmt_t *stmt;
- /* The directory at the WCROOT has a NULL parent_relpath. Otherwise,
- bind the appropriate parent_relpath. */
- const char *parent_relpath =
- (*local_relpath == '\0') ? NULL
- : svn_relpath_dirname(local_relpath, scratch_pool);
-
- SVN_ERR_ASSERT(pibb->repos_id != INVALID_REPOS_ID);
- SVN_ERR_ASSERT(pibb->repos_relpath != NULL);
-
- /* ### we can't handle this right now */
- SVN_ERR_ASSERT(pibb->conflict == NULL);
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, STMT_INSERT_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "isisisr"
- "tstr" /* 8 - 11 */
- "isnnnnns", /* 12 - 19 */
- wcroot->wc_id, /* 1 */
- local_relpath, /* 2 */
- (apr_int64_t)0, /* op_depth is 0 for base */
- parent_relpath, /* 4 */
- pibb->repos_id,
- pibb->repos_relpath,
- pibb->revision,
- presence_map, pibb->status, /* 8 */
- (pibb->kind == svn_wc__db_kind_dir) ? /* 9 */
- svn_depth_to_word(pibb->depth) : NULL,
- kind_map, pibb->kind, /* 10 */
- pibb->changed_rev, /* 11 */
- pibb->changed_date, /* 12 */
- pibb->changed_author, /* 13 */
- (pibb->kind == svn_wc__db_kind_symlink) ?
- pibb->target : NULL)); /* 19 */
-
- if (pibb->kind == svn_wc__db_kind_file)
- {
- SVN_ERR(svn_sqlite__bind_checksum(stmt, 14, pibb->checksum,
- scratch_pool));
- if (pibb->translated_size != SVN_INVALID_FILESIZE)
- SVN_ERR(svn_sqlite__bind_int64(stmt, 16, pibb->translated_size));
- }
-
- SVN_ERR(svn_sqlite__bind_properties(stmt, 15, pibb->props,
- scratch_pool));
- if (pibb->dav_cache)
- SVN_ERR(svn_sqlite__bind_properties(stmt, 18, pibb->dav_cache,
- scratch_pool));
-
- SVN_ERR(svn_sqlite__insert(NULL, stmt));
-
- if (pibb->kind == svn_wc__db_kind_dir && pibb->children)
- SVN_ERR(insert_incomplete_children(wcroot->sdb, wcroot->wc_id,
- local_relpath,
- pibb->repos_id,
- pibb->repos_relpath,
- pibb->revision,
- pibb->children,
- 0 /* BASE */,
- scratch_pool));
-
- if (parent_relpath)
- SVN_ERR(extend_parent_delete(wcroot->sdb, wcroot->wc_id, local_relpath,
- scratch_pool));
-
- SVN_ERR(add_work_items(wcroot->sdb, pibb->work_items, scratch_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-static void
-blank_iwb(insert_working_baton_t *piwb)
-{
- memset(piwb, 0, sizeof(*piwb));
- piwb->changed_rev = SVN_INVALID_REVNUM;
- piwb->depth = svn_depth_infinity;
-
- /* ORIGINAL_REPOS_ID and ORIGINAL_REVNUM could use some kind of "nil"
- value, but... meh. We'll avoid them if ORIGINAL_REPOS_RELPATH==NULL. */
-}
-
-
-/* Insert a row in NODES for each (const char *) child name in CHILDREN,
- whose parent directory is LOCAL_RELPATH, at op_depth=OP_DEPTH. Set each
- child's presence to 'incomplete', kind to 'unknown', repos_id to REPOS_ID,
- repos_path by appending the child name to REPOS_PATH, and revision to
- REVISION (which should match the parent's revision).
-
- If REPOS_ID is INVALID_REPOS_ID, set each child's repos_id to null. */
-static svn_error_t *
-insert_incomplete_children(svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *local_relpath,
- apr_int64_t repos_id,
- const char *repos_path,
- svn_revnum_t revision,
- const apr_array_header_t *children,
- apr_int64_t op_depth,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- int i;
-
- SVN_ERR_ASSERT(repos_path != NULL || op_depth > 0);
- SVN_ERR_ASSERT((repos_id != INVALID_REPOS_ID)
- == (repos_path != NULL));
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_INSERT_NODE));
-
- for (i = children->nelts; i--; )
- {
- const char *name = APR_ARRAY_IDX(children, i, const char *);
-
- SVN_ERR(svn_sqlite__bindf(stmt, "isisnnrsns",
- wc_id,
- svn_relpath_join(local_relpath, name,
- scratch_pool),
- op_depth,
- local_relpath,
- revision,
- "incomplete", /* 8, presence */
- "unknown")); /* 10, kind */
-
- if (repos_id != INVALID_REPOS_ID)
- {
- SVN_ERR(svn_sqlite__bind_int64(stmt, 5, repos_id));
- SVN_ERR(svn_sqlite__bind_text(stmt, 6,
- svn_relpath_join(repos_path, name,
- scratch_pool)));
- }
-
- SVN_ERR(svn_sqlite__insert(NULL, stmt));
- }
-
- return SVN_NO_ERROR;
-}
-
-
-/* */
-static svn_error_t *
-insert_working_node(void *baton,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *scratch_pool)
-{
- const insert_working_baton_t *piwb = baton;
- const char *parent_relpath;
- svn_sqlite__stmt_t *stmt;
-
- SVN_ERR_ASSERT(piwb->op_depth > 0);
-
- /* We cannot insert a WORKING_NODE row at the wcroot. */
- SVN_ERR_ASSERT(*local_relpath != '\0');
- parent_relpath = svn_relpath_dirname(local_relpath, scratch_pool);
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, STMT_INSERT_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "isisnnntstrisn"
- "nnnn" /* properties translated_size last_mod_time dav_cache */
- "s",
- wcroot->wc_id, local_relpath,
- piwb->op_depth,
- parent_relpath,
- presence_map, piwb->presence,
- (piwb->kind == svn_wc__db_kind_dir)
- ? svn_depth_to_word(piwb->depth) : NULL,
- kind_map, piwb->kind,
- piwb->changed_rev,
- piwb->changed_date,
- piwb->changed_author,
- (piwb->kind == svn_wc__db_kind_symlink)
- ? piwb->target : NULL));
-
-
- if (piwb->kind == svn_wc__db_kind_file)
- {
- SVN_ERR(svn_sqlite__bind_checksum(stmt, 14, piwb->checksum,
- scratch_pool));
- }
- else if (piwb->kind == svn_wc__db_kind_symlink)
- {
- /* Note: incomplete nodes may have a NULL target. */
- if (piwb->target)
- SVN_ERR(svn_sqlite__bind_text(stmt, 19, piwb->target));
- }
-
- if (piwb->original_repos_relpath != NULL)
- {
- SVN_ERR(svn_sqlite__bind_int64(stmt, 5, piwb->original_repos_id));
- SVN_ERR(svn_sqlite__bind_text(stmt, 6, piwb->original_repos_relpath));
- SVN_ERR(svn_sqlite__bind_int64(stmt, 7, piwb->original_revnum));
- }
-
-
- SVN_ERR(svn_sqlite__bind_properties(stmt, 15, piwb->props, scratch_pool));
-
- SVN_ERR(svn_sqlite__insert(NULL, stmt));
-
- /* Insert incomplete children, if specified.
- The children are part of the same op and so have the same op_depth.
- (The only time we'd want a different depth is during a recursive
- simple add, but we never insert children here during a simple add.) */
- if (piwb->kind == svn_wc__db_kind_dir && piwb->children)
- SVN_ERR(insert_incomplete_children(wcroot->sdb, wcroot->wc_id,
- local_relpath,
- INVALID_REPOS_ID /* inherit repos_id */,
- NULL /* inherit repos_path */,
- piwb->original_revnum,
- piwb->children,
- piwb->op_depth,
- scratch_pool));
-
- SVN_ERR(add_work_items(wcroot->sdb, piwb->work_items, scratch_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-/* Each name is allocated in RESULT_POOL and stored into CHILDREN as a key
- pointed to the same name. */
-static svn_error_t *
-add_children_to_hash(apr_hash_t *children,
- int stmt_idx,
- svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *parent_relpath,
- apr_pool_t *result_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, stmt_idx));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, parent_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- while (have_row)
- {
- const char *child_relpath = svn_sqlite__column_text(stmt, 0, NULL);
- const char *name = svn_relpath_basename(child_relpath, result_pool);
-
- apr_hash_set(children, name, APR_HASH_KEY_STRING, name);
-
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- }
-
- return svn_sqlite__reset(stmt);
-}
-
-
-/* Set *CHILDREN to a new array of the (const char *) basenames of the
- immediate children, whatever their status, of the working node at
- LOCAL_RELPATH. */
-static svn_error_t *
-gather_children2(const apr_array_header_t **children,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- apr_hash_t *names_hash = apr_hash_make(scratch_pool);
- apr_array_header_t *names_array;
-
- /* All of the names get allocated in RESULT_POOL. It
- appears to be faster to use the hash to remove duplicates than to
- use DISTINCT in the SQL query. */
- SVN_ERR(add_children_to_hash(names_hash, STMT_SELECT_WORKING_CHILDREN,
- wcroot->sdb, wcroot->wc_id,
- local_relpath, result_pool));
-
- SVN_ERR(svn_hash_keys(&names_array, names_hash, result_pool));
- *children = names_array;
- return SVN_NO_ERROR;
-}
-
-/* Return in *CHILDREN all of the children of the directory LOCAL_RELPATH,
- of any status, in all op-depths in the NODES table. */
-static svn_error_t *
-gather_children(const apr_array_header_t **children,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- apr_hash_t *names_hash = apr_hash_make(scratch_pool);
- apr_array_header_t *names_array;
-
- /* All of the names get allocated in RESULT_POOL. It
- appears to be faster to use the hash to remove duplicates than to
- use DISTINCT in the SQL query. */
- SVN_ERR(add_children_to_hash(names_hash, STMT_SELECT_NODE_CHILDREN,
- wcroot->sdb, wcroot->wc_id,
- local_relpath, result_pool));
-
- SVN_ERR(svn_hash_keys(&names_array, names_hash, result_pool));
- *children = names_array;
- return SVN_NO_ERROR;
-}
-
-
-/* Set *CHILDREN to a new array of (const char *) names of the children of
- the repository directory corresponding to the (working) path
- WCROOT:LOCAL_RELPATH - that is, only the children that are at the same
- op-depth as their parent. */
-static svn_error_t *
-gather_repo_children(const apr_array_header_t **children,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_int64_t op_depth,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- apr_array_header_t *result
- = apr_array_make(result_pool, 0, sizeof(const char *));
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- STMT_SELECT_OP_DEPTH_CHILDREN));
- SVN_ERR(svn_sqlite__bindf(stmt, "isi", wcroot->wc_id, local_relpath,
- op_depth));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- while (have_row)
- {
- const char *child_relpath = svn_sqlite__column_text(stmt, 0, NULL);
-
- /* Allocate the name in RESULT_POOL so we won't have to copy it. */
- APR_ARRAY_PUSH(result, const char *)
- = svn_relpath_basename(child_relpath, result_pool);
-
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- }
- SVN_ERR(svn_sqlite__reset(stmt));
-
- *children = result;
- return SVN_NO_ERROR;
-}
-
-
-/* */
-static svn_error_t *
-flush_entries(svn_wc__db_t *db,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_abspath,
- apr_pool_t *scratch_pool)
-{
- svn_wc_adm_access_t *adm_access;
- const char *parent_abspath;
-
- adm_access = apr_hash_get(wcroot->access_cache, local_abspath,
- APR_HASH_KEY_STRING);
-
- if (adm_access)
- svn_wc__adm_access_set_entries(adm_access, NULL);
-
- /* We're going to be overly aggressive here and just flush the parent
- without doing much checking. This may hurt performance for
- legacy API consumers, but that's not our problem. :) */
- parent_abspath = svn_dirent_dirname(local_abspath, scratch_pool);
- adm_access = apr_hash_get(wcroot->access_cache, parent_abspath,
- APR_HASH_KEY_STRING);
-
- if (adm_access)
- svn_wc__adm_access_set_entries(adm_access, NULL);
-
- return SVN_NO_ERROR;
-}
-
-
-/* Add a single WORK_ITEM into the given SDB's WORK_QUEUE table. This does
- not perform its work within a transaction, assuming the caller will
- manage that. */
-static svn_error_t *
-add_single_work_item(svn_sqlite__db_t *sdb,
- const svn_skel_t *work_item,
- apr_pool_t *scratch_pool)
-{
- svn_stringbuf_t *serialized;
- svn_sqlite__stmt_t *stmt;
-
- serialized = svn_skel__unparse(work_item, scratch_pool);
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_INSERT_WORK_ITEM));
- SVN_ERR(svn_sqlite__bind_blob(stmt, 1, serialized->data, serialized->len));
- return svn_error_return(svn_sqlite__insert(NULL, stmt));
-}
-
-
-/* Add work item(s) to the given SDB. Also see add_one_work_item(). This
- SKEL is usually passed to the various wc_db operation functions. It may
- be NULL, indicating no additional work items are needed, it may be a
- single work item, or it may be a list of work items. */
-static svn_error_t *
-add_work_items(svn_sqlite__db_t *sdb,
- const svn_skel_t *skel,
- apr_pool_t *scratch_pool)
-{
- apr_pool_t *iterpool;
-
- /* Maybe there are no work items to insert. */
- if (skel == NULL)
- return SVN_NO_ERROR;
-
- /* Should have a list. */
- SVN_ERR_ASSERT(!skel->is_atom);
-
- /* Is the list a single work item? Or a list of work items? */
- if (SVN_WC__SINGLE_WORK_ITEM(skel))
- return svn_error_return(add_single_work_item(sdb, skel, scratch_pool));
-
- /* SKEL is a list-of-lists, aka list of work items. */
-
- iterpool = svn_pool_create(scratch_pool);
- for (skel = skel->children; skel; skel = skel->next)
- {
- svn_pool_clear(iterpool);
-
- SVN_ERR(add_single_work_item(sdb, skel, iterpool));
- }
- svn_pool_destroy(iterpool);
-
- return SVN_NO_ERROR;
-}
-
-
-/* Determine which trees' nodes exist for a given WC_ID and LOCAL_RELPATH
- in the specified SDB. */
-static svn_error_t *
-which_trees_exist(svn_boolean_t *base_exists,
- svn_boolean_t *working_exists,
- svn_sqlite__db_t *sdb,
- apr_int64_t wc_id,
- const char *local_relpath)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- *base_exists = FALSE;
- *working_exists = FALSE;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
- STMT_DETERMINE_TREE_FOR_RECORDING));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
-
- if (have_row)
- {
- int value = svn_sqlite__column_int(stmt, 0);
-
- if (value)
- *working_exists = TRUE; /* value == 1 */
- else
- *base_exists = TRUE; /* value == 0 */
-
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (have_row)
- {
- /* If both rows, then both tables. */
- *base_exists = TRUE;
- *working_exists = TRUE;
- }
- }
-
- return svn_error_return(svn_sqlite__reset(stmt));
-}
-
-
-/* */
-static svn_error_t *
-create_db(svn_sqlite__db_t **sdb,
- apr_int64_t *repos_id,
- apr_int64_t *wc_id,
- const char *dir_abspath,
- const char *repos_root_url,
- const char *repos_uuid,
- const char *sdb_fname,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
-
- SVN_ERR(svn_wc__db_util_open_db(sdb, dir_abspath, sdb_fname,
- svn_sqlite__mode_rwcreate, result_pool,
- scratch_pool));
-
- /* Create the database's schema. */
- SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_SCHEMA));
- SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_NODES));
- SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_NODES_TRIGGERS));
-
- /* Insert the repository. */
- SVN_ERR(create_repos_id(repos_id, repos_root_url, repos_uuid, *sdb,
- scratch_pool));
-
- /* Insert the wcroot. */
- /* ### Right now, this just assumes wc metadata is being stored locally. */
- SVN_ERR(svn_sqlite__get_statement(&stmt, *sdb, STMT_INSERT_WCROOT));
- SVN_ERR(svn_sqlite__insert(wc_id, stmt));
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_init(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t initial_rev,
- svn_depth_t depth,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__db_t *sdb;
- apr_int64_t repos_id;
- apr_int64_t wc_id;
- svn_wc__db_wcroot_t *wcroot;
- insert_base_baton_t ibb;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(repos_relpath != NULL);
- SVN_ERR_ASSERT(depth == svn_depth_empty
- || depth == svn_depth_files
- || depth == svn_depth_immediates
- || depth == svn_depth_infinity);
-
- /* ### REPOS_ROOT_URL and REPOS_UUID may be NULL. ... more doc: tbd */
-
- /* Create the SDB and insert the basic rows. */
- SVN_ERR(create_db(&sdb, &repos_id, &wc_id, local_abspath, repos_root_url,
- repos_uuid, SDB_FILE, db->state_pool, scratch_pool));
-
- /* Create the WCROOT for this directory. */
- SVN_ERR(svn_wc__db_pdh_create_wcroot(&wcroot,
- apr_pstrdup(db->state_pool, local_abspath),
- sdb, wc_id, FORMAT_FROM_SDB,
- FALSE /* auto-upgrade */,
- FALSE /* enforce_empty_wq */,
- db->state_pool, scratch_pool));
-
- /* The WCROOT is complete. Stash it into DB. */
- apr_hash_set(db->dir_data, wcroot->abspath, APR_HASH_KEY_STRING, wcroot);
-
- blank_ibb(&ibb);
-
- if (initial_rev > 0)
- ibb.status = svn_wc__db_status_incomplete;
- else
- ibb.status = svn_wc__db_status_normal;
- ibb.kind = svn_wc__db_kind_dir;
- ibb.repos_id = repos_id;
- ibb.repos_relpath = repos_relpath;
- ibb.revision = initial_rev;
-
- /* ### what about the children? */
- ibb.children = NULL;
- ibb.depth = depth;
-
- /* ### no children, conflicts, or work items to install in a txn... */
-
- return svn_error_return(insert_base_node(&ibb, wcroot, "", scratch_pool));
-}
-
-
-svn_error_t *
-svn_wc__db_to_relpath(const char **local_relpath,
- svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, local_relpath, db,
- local_abspath, svn_sqlite__mode_readonly,
- result_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_from_relpath(const char **local_abspath,
- svn_wc__db_t *db,
- const char *wri_abspath,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *unused_relpath;
-
-#if 0
- SVN_ERR_ASSERT(svn_relpath_is_canonical(local_abspath));
-#endif
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &unused_relpath, db,
- wri_abspath, svn_sqlite__mode_readonly,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- *local_abspath = svn_dirent_join(wcroot->abspath,
- local_relpath,
- result_pool);
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_get_wcroot(const char **wcroot_abspath,
- svn_wc__db_t *db,
- const char *wri_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *unused_relpath;
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &unused_relpath, db,
- wri_abspath, svn_sqlite__mode_readonly,
- scratch_pool, scratch_pool));
-
- /* Can't use VERIFY_USABLE_WCROOT, as this should be usable to detect
- where call upgrade */
-
- if (wcroot == NULL)
- return svn_error_createf(SVN_ERR_WC_NOT_WORKING_COPY, NULL,
- _("The node '%s' is not in a workingcopy."),
- svn_dirent_local_style(wri_abspath,
- scratch_pool));
-
- *wcroot_abspath = apr_pstrdup(result_pool, wcroot->abspath);
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_add_directory(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- const apr_hash_t *props,
- svn_revnum_t changed_rev,
- apr_time_t changed_date,
- const char *changed_author,
- const apr_array_header_t *children,
- svn_depth_t depth,
- apr_hash_t *dav_cache,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- apr_int64_t repos_id;
- insert_base_baton_t ibb;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(repos_relpath != NULL);
- SVN_ERR_ASSERT(svn_uri_is_canonical(repos_root_url, scratch_pool));
- SVN_ERR_ASSERT(repos_uuid != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(revision));
- SVN_ERR_ASSERT(props != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(changed_rev));
-#if 0
- SVN_ERR_ASSERT(children != NULL);
-#endif
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
- wcroot->sdb, scratch_pool));
-
- blank_ibb(&ibb);
-
- ibb.status = svn_wc__db_status_normal;
- ibb.kind = svn_wc__db_kind_dir;
- ibb.repos_id = repos_id;
- ibb.repos_relpath = repos_relpath;
- ibb.revision = revision;
-
- ibb.props = props;
- ibb.changed_rev = changed_rev;
- ibb.changed_date = changed_date;
- ibb.changed_author = changed_author;
-
- ibb.children = children;
- ibb.depth = depth;
-
- ibb.dav_cache = dav_cache;
- ibb.conflict = conflict;
- ibb.work_items = work_items;
-
- /* Insert the directory and all its children transactionally.
-
- Note: old children can stick around, even if they are no longer present
- in this directory's revision. */
- SVN_ERR(with_db_txn(wcroot, local_relpath, insert_base_node, &ibb,
- scratch_pool));
-
- /* ### worry about flushing child subdirs? */
- SVN_ERR(flush_entries(db, wcroot, local_abspath, scratch_pool));
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_add_file(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- const apr_hash_t *props,
- svn_revnum_t changed_rev,
- apr_time_t changed_date,
- const char *changed_author,
- const svn_checksum_t *checksum,
- svn_filesize_t translated_size,
- apr_hash_t *dav_cache,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- apr_int64_t repos_id;
- insert_base_baton_t ibb;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(repos_relpath != NULL);
- SVN_ERR_ASSERT(svn_uri_is_canonical(repos_root_url, scratch_pool));
- SVN_ERR_ASSERT(repos_uuid != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(revision));
- SVN_ERR_ASSERT(props != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(changed_rev));
- SVN_ERR_ASSERT(checksum != NULL);
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
- wcroot->sdb, scratch_pool));
-
- blank_ibb(&ibb);
-
- ibb.status = svn_wc__db_status_normal;
- ibb.kind = svn_wc__db_kind_file;
- ibb.repos_id = repos_id;
- ibb.repos_relpath = repos_relpath;
- ibb.revision = revision;
-
- ibb.props = props;
- ibb.changed_rev = changed_rev;
- ibb.changed_date = changed_date;
- ibb.changed_author = changed_author;
-
- ibb.checksum = checksum;
- ibb.translated_size = translated_size;
-
- ibb.dav_cache = dav_cache;
- ibb.conflict = conflict;
- ibb.work_items = work_items;
-
- /* ### hmm. if this used to be a directory, we should remove children.
- ### or maybe let caller deal with that, if there is a possibility
- ### of a node kind change (rather than eat an extra lookup here). */
-
- SVN_ERR(with_db_txn(wcroot, local_relpath, insert_base_node, &ibb,
- scratch_pool));
-
- SVN_ERR(flush_entries(db, wcroot, local_abspath, scratch_pool));
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_add_symlink(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- const apr_hash_t *props,
- svn_revnum_t changed_rev,
- apr_time_t changed_date,
- const char *changed_author,
- const char *target,
- apr_hash_t *dav_cache,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- apr_int64_t repos_id;
- insert_base_baton_t ibb;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(repos_relpath != NULL);
- SVN_ERR_ASSERT(svn_uri_is_canonical(repos_root_url, scratch_pool));
- SVN_ERR_ASSERT(repos_uuid != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(revision));
- SVN_ERR_ASSERT(props != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(changed_rev));
- SVN_ERR_ASSERT(target != NULL);
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
- wcroot->sdb, scratch_pool));
-
- blank_ibb(&ibb);
-
- ibb.status = svn_wc__db_status_normal;
- ibb.kind = svn_wc__db_kind_symlink;
- ibb.repos_id = repos_id;
- ibb.repos_relpath = repos_relpath;
- ibb.revision = revision;
-
- ibb.props = props;
- ibb.changed_rev = changed_rev;
- ibb.changed_date = changed_date;
- ibb.changed_author = changed_author;
-
- ibb.target = target;
-
- ibb.dav_cache = dav_cache;
- ibb.conflict = conflict;
- ibb.work_items = work_items;
-
- /* ### hmm. if this used to be a directory, we should remove children.
- ### or maybe let caller deal with that, if there is a possibility
- ### of a node kind change (rather than eat an extra lookup here). */
-
- SVN_ERR(with_db_txn(wcroot, local_relpath, insert_base_node, &ibb,
- scratch_pool));
-
- SVN_ERR(flush_entries(db, wcroot, local_abspath, scratch_pool));
- return SVN_NO_ERROR;
-}
-
-
-static svn_error_t *
-add_absent_excluded_not_present_node(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- svn_wc__db_kind_t kind,
- svn_wc__db_status_t status,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- apr_int64_t repos_id;
- insert_base_baton_t ibb;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(repos_relpath != NULL);
- SVN_ERR_ASSERT(svn_uri_is_canonical(repos_root_url, scratch_pool));
- SVN_ERR_ASSERT(repos_uuid != NULL);
- SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(revision));
- SVN_ERR_ASSERT(status == svn_wc__db_status_absent
- || status == svn_wc__db_status_excluded
- || status == svn_wc__db_status_not_present);
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
- wcroot->sdb, scratch_pool));
-
- blank_ibb(&ibb);
-
- ibb.status = status;
- ibb.kind = kind;
- ibb.repos_id = repos_id;
- ibb.repos_relpath = repos_relpath;
- ibb.revision = revision;
-
- /* Depending upon KIND, any of these might get used. */
- ibb.children = NULL;
- ibb.depth = svn_depth_unknown;
- ibb.checksum = NULL;
- ibb.translated_size = SVN_INVALID_FILESIZE;
- ibb.target = NULL;
-
- ibb.conflict = conflict;
- ibb.work_items = work_items;
-
- /* ### hmm. if this used to be a directory, we should remove children.
- ### or maybe let caller deal with that, if there is a possibility
- ### of a node kind change (rather than eat an extra lookup here). */
-
- SVN_ERR(with_db_txn(wcroot, local_relpath, insert_base_node, &ibb,
- scratch_pool));
-
- SVN_ERR(flush_entries(db, wcroot, local_abspath, scratch_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_add_absent_node(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- svn_wc__db_kind_t kind,
- svn_wc__db_status_t status,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- SVN_ERR_ASSERT(status == svn_wc__db_status_absent
- || status == svn_wc__db_status_excluded);
-
- return add_absent_excluded_not_present_node(
- db, local_abspath, repos_relpath, repos_root_url, repos_uuid, revision,
- kind, status, conflict, work_items, scratch_pool);
-}
-
-
-svn_error_t *
-svn_wc__db_base_add_not_present_node(svn_wc__db_t *db,
- const char *local_abspath,
- const char *repos_relpath,
- const char *repos_root_url,
- const char *repos_uuid,
- svn_revnum_t revision,
- svn_wc__db_kind_t kind,
- const svn_skel_t *conflict,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- return add_absent_excluded_not_present_node(
- db, local_abspath, repos_relpath, repos_root_url, repos_uuid, revision,
- kind, svn_wc__db_status_not_present, conflict, work_items, scratch_pool);
-}
-
-
-/* This implements db_txn_callback_t */
-static svn_error_t *
-db_base_remove(void *baton,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- STMT_DELETE_BASE_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step_done(stmt));
-
- SVN_ERR(retract_parent_delete(wcroot->sdb, wcroot->wc_id, local_relpath,
- scratch_pool));
-
- /* If there is no working node then any actual node must be deleted,
- unless it marks a conflict */
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- STMT_SELECT_WORKING_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- SVN_ERR(svn_sqlite__reset(stmt));
- if (!have_row)
- {
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- STMT_DELETE_ACTUAL_NODE_WITHOUT_CONFLICT));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step_done(stmt));
- }
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_remove(svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(with_db_txn(wcroot, local_relpath, db_base_remove, NULL,
- scratch_pool));
-
- SVN_ERR(flush_entries(db, wcroot, local_abspath, scratch_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-/* Like svn_wc__db_base_get_info(), but taking WCROOT+LOCAL_RELPATH instead of
- DB+LOCAL_ABSPATH and outputting REPOS_ID instead of URL+UUID. */
-static svn_error_t *
-base_get_info(svn_wc__db_status_t *status,
- svn_wc__db_kind_t *kind,
- svn_revnum_t *revision,
- const char **repos_relpath,
- apr_int64_t *repos_id,
- svn_revnum_t *changed_rev,
- apr_time_t *changed_date,
- const char **changed_author,
- apr_time_t *last_mod_time,
- svn_depth_t *depth,
- const svn_checksum_t **checksum,
- svn_filesize_t *translated_size,
- const char **target,
- svn_wc__db_lock_t **lock,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
- svn_error_t *err = SVN_NO_ERROR;
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- lock ? STMT_SELECT_BASE_NODE_WITH_LOCK
- : STMT_SELECT_BASE_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
-
- if (have_row)
- {
- svn_wc__db_kind_t node_kind = svn_sqlite__column_token(stmt, 3,
- kind_map);
-
- if (kind)
- {
- *kind = node_kind;
- }
- if (status)
- {
- *status = svn_sqlite__column_token(stmt, 2, presence_map);
- }
- err = repos_location_from_columns(repos_id, revision, repos_relpath,
- stmt, 0, 4, 1, result_pool);
- SVN_ERR_ASSERT(!repos_id || *repos_id != INVALID_REPOS_ID);
- SVN_ERR_ASSERT(!repos_relpath || *repos_relpath);
- if (lock)
- {
- *lock = lock_from_columns(stmt, 14, 15, 16, 17, result_pool);
- }
- if (changed_rev)
- {
- *changed_rev = svn_sqlite__column_revnum(stmt, 7);
- }
- if (changed_date)
- {
- *changed_date = svn_sqlite__column_int64(stmt, 8);
- }
- if (changed_author)
- {
- /* Result may be NULL. */
- *changed_author = svn_sqlite__column_text(stmt, 9, result_pool);
- }
- if (last_mod_time)
- {
- *last_mod_time = svn_sqlite__column_int64(stmt, 12);
- }
- if (depth)
- {
- if (node_kind != svn_wc__db_kind_dir)
- {
- *depth = svn_depth_unknown;
- }
- else
- {
- const char *depth_str = svn_sqlite__column_text(stmt, 10, NULL);
-
- if (depth_str == NULL)
- *depth = svn_depth_unknown;
- else
- *depth = svn_depth_from_word(depth_str);
- }
- }
- if (checksum)
- {
- if (node_kind != svn_wc__db_kind_file)
- {
- *checksum = NULL;
- }
- else
- {
- err = svn_sqlite__column_checksum(checksum, stmt, 5,
- result_pool);
- if (err != NULL)
- err = svn_error_createf(
- err->apr_err, err,
- _("The node '%s' has a corrupt checksum value."),
- path_for_error_message(wcroot, local_relpath,
- scratch_pool));
- }
- }
- if (translated_size)
- {
- *translated_size = get_translated_size(stmt, 6);
- }
- if (target)
- {
- if (node_kind != svn_wc__db_kind_symlink)
- *target = NULL;
- else
- *target = svn_sqlite__column_text(stmt, 11, result_pool);
- }
- }
- else
- {
- err = svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, NULL,
- _("The node '%s' was not found."),
- path_for_error_message(wcroot, local_relpath,
- scratch_pool));
- }
-
- /* Note: given the composition, no need to wrap for tracing. */
- return svn_error_compose_create(err, svn_sqlite__reset(stmt));
-}
-
-
-svn_error_t *
-svn_wc__db_base_get_info(svn_wc__db_status_t *status,
- svn_wc__db_kind_t *kind,
- svn_revnum_t *revision,
- const char **repos_relpath,
- const char **repos_root_url,
- const char **repos_uuid,
- svn_revnum_t *changed_rev,
- apr_time_t *changed_date,
- const char **changed_author,
- apr_time_t *last_mod_time,
- svn_depth_t *depth,
- const svn_checksum_t **checksum,
- svn_filesize_t *translated_size,
- const char **target,
- svn_wc__db_lock_t **lock,
- svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- apr_int64_t repos_id;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath, svn_sqlite__mode_readonly,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- SVN_ERR(base_get_info(status, kind, revision, repos_relpath, &repos_id,
- changed_rev, changed_date, changed_author,
- last_mod_time, depth, checksum, translated_size,
- target, lock,
- wcroot, local_relpath, result_pool, scratch_pool));
- SVN_ERR_ASSERT(repos_id != INVALID_REPOS_ID);
- SVN_ERR(fetch_repos_info(repos_root_url, repos_uuid,
- wcroot->sdb, repos_id, result_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_get_prop(const svn_string_t **propval,
- svn_wc__db_t *db,
- const char *local_abspath,
- const char *propname,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- apr_hash_t *props;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
- SVN_ERR_ASSERT(propname != NULL);
-
- /* Note: maybe one day, we'll have internal caches of this stuff, but
- for now, we just grab all the props and pick out the requested prop. */
-
- /* ### should: fetch into scratch_pool, then dup into result_pool. */
- SVN_ERR(svn_wc__db_base_get_props(&props, db, local_abspath,
- result_pool, scratch_pool));
-
- *propval = apr_hash_get(props, propname, APR_HASH_KEY_STRING);
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_get_props(apr_hash_t **props,
- svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
- svn_error_t *err;
-
- SVN_ERR(get_statement_for_path(&stmt, db, local_abspath,
- STMT_SELECT_BASE_PROPS, scratch_pool));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (!have_row)
- {
- err = svn_sqlite__reset(stmt);
- return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, err,
- _("The node '%s' was not found."),
- svn_dirent_local_style(local_abspath,
- scratch_pool));
- }
-
- err = svn_sqlite__column_properties(props, stmt, 0, result_pool,
- scratch_pool);
- if (err == NULL && *props == NULL)
- {
- /* ### is this a DB constraint violation? the column "probably" should
- ### never be null. */
- *props = apr_hash_make(result_pool);
- }
-
- return svn_error_compose_create(err, svn_sqlite__reset(stmt));
-}
-
-
-svn_error_t *
-svn_wc__db_base_get_children(const apr_array_header_t **children,
- svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
-
- SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
- local_abspath,
- svn_sqlite__mode_readonly,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- return gather_repo_children(children, wcroot, local_relpath, 0,
- result_pool, scratch_pool);
-}
-
-
-svn_error_t *
-svn_wc__db_base_set_dav_cache(svn_wc__db_t *db,
- const char *local_abspath,
- const apr_hash_t *props,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- int affected_rows;
-
- SVN_ERR(get_statement_for_path(&stmt, db, local_abspath,
- STMT_UPDATE_BASE_NODE_DAV_CACHE,
- scratch_pool));
- SVN_ERR(svn_sqlite__bind_properties(stmt, 3, props, scratch_pool));
-
- SVN_ERR(svn_sqlite__update(&affected_rows, stmt));
-
- if (affected_rows != 1)
- return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, NULL,
- _("The node '%s' was not found."),
- svn_dirent_local_style(local_abspath,
- scratch_pool));
-
- return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_base_get_dav_cache(apr_hash_t **props,
- svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
-
- SVN_ERR(get_statement_for_path(&stmt, db, local_abspath,
- STMT_SELECT_BASE_DAV_CACHE, scratch_pool));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (!have_row)
- return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND,
- svn_sqlite__reset(stmt),
- _("The node '%s' was not found."),
- svn_dirent_local_style(local_abspath,
- scratch_pool));
-
- SVN_ERR(svn_sqlite__column_properties(props, stmt, 0, result_pool,
- scratch_pool));
- return svn_error_return(svn_sqlite__reset(stmt));
-}
-
-
-svn_error_t *
-svn_wc__db_base_clear_dav_cache_recursive(svn_wc__db_t *db,
- const char *local_abspath,
- apr_pool_t *scratch_pool)
-{
- svn_wc__db_wcroot_t *wcroot;
- const char *local_relpath;
- const char *like_arg;
- svn_sqlite__stmt_t *stmt;
-
- SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath,
- db, local_abspath,
- svn_sqlite__mode_readwrite,
- scratch_pool, scratch_pool));
- VERIFY_USABLE_WCROOT(wcroot);
-
- like_arg = construct_like_arg(local_relpath, scratch_pool);
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
- STMT_CLEAR_BASE_NODE_RECURSIVE_DAV_CACHE));
- SVN_ERR(svn_sqlite__bindf(stmt, "iss", wcroot->wc_id, local_relpath,
- like_arg));
-
- SVN_ERR(svn_sqlite__step_done(stmt));
-
- return SVN_NO_ERROR;
-}
-
-
-/* Helper for svn_wc__db_op_copy to handle copying from one db to
- another */
-static svn_error_t *
-cross_db_copy(svn_wc__db_wcroot_t *src_wcroot,
- const char *src_relpath,
- svn_wc__db_wcroot_t *dst_wcroot,
- const char *dst_relpath,
- svn_wc__db_status_t dst_status,
- apr_int64_t dst_op_depth,
- svn_wc__db_kind_t kind,
- const apr_array_header_t *children,
- apr_int64_t copyfrom_id,
- const char *copyfrom_relpath,
- svn_revnum_t copyfrom_rev,
- apr_pool_t *scratch_pool)
-{
- insert_working_baton_t iwb;
- svn_revnum_t changed_rev;
- apr_time_t changed_date;
- const char *changed_author;
- const svn_checksum_t *checksum;
- apr_hash_t *props;
- svn_sqlite__stmt_t *stmt;
- svn_boolean_t have_row;
- svn_depth_t depth;
-
- SVN_ERR_ASSERT(kind == svn_wc__db_kind_file
- || kind == svn_wc__db_kind_dir
- );
-
- SVN_ERR(read_info(NULL /* status */,
- NULL /* kind */,
- NULL /* revision */,
- NULL /* repos_relpath */,
- NULL /* repos_id */,
- &changed_rev, &changed_date, &changed_author,
- NULL /* last_mod_time */,
- &depth,
- &checksum,
- NULL /* translated_size */,
- NULL /* target */,
- NULL /* changelist */,
- NULL /* original_repos_relpath */,
- NULL /* original_repos_id */,
- NULL /* original_revision */,
- NULL /* props_mod */,
- NULL /* have_base */,
- NULL /* have_work */,
- NULL /* conflicted */,
- NULL /* lock */,
- src_wcroot, src_relpath, scratch_pool, scratch_pool));
-
- SVN_ERR(db_read_pristine_props(&props, src_wcroot, src_relpath,
- scratch_pool, scratch_pool));
-
- blank_iwb(&iwb);
- iwb.presence = dst_status;
- iwb.kind = kind;
-
- iwb.props = props;
- iwb.changed_rev = changed_rev;
- iwb.changed_date = changed_date;
- iwb.changed_author = changed_author;
- iwb.original_repos_id = copyfrom_id;
- iwb.original_repos_relpath = copyfrom_relpath;
- iwb.original_revnum = copyfrom_rev;
- iwb.moved_here = FALSE;
-
- iwb.op_depth = dst_op_depth;
-
- iwb.checksum = checksum;
- iwb.children = children;
- iwb.depth = depth;
-
- SVN_ERR(insert_working_node(&iwb, dst_wcroot, dst_relpath, scratch_pool));
-
- SVN_ERR(svn_sqlite__get_statement(&stmt, src_wcroot->sdb,
- STMT_SELECT_ACTUAL_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "is", src_wcroot->wc_id, src_relpath));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- if (have_row)
- {
- /* const char *prop_reject = svn_sqlite__column_text(stmt, 0,
- scratch_pool);
-
- ### STMT_INSERT_ACTUAL_NODE doesn't cover every column, it's
- ### enough for some cases but will probably need to extended. */
- const char *changelist = svn_sqlite__column_text(stmt, 1, scratch_pool);
- const char *conflict_old = svn_sqlite__column_text(stmt, 2, scratch_pool);
- const char *conflict_new = svn_sqlite__column_text(stmt, 3, scratch_pool);
- const char *conflict_working = svn_sqlite__column_text(stmt, 4,
- scratch_pool);
- const char *tree_conflict_data = svn_sqlite__column_text(stmt, 5,
- scratch_pool);
- apr_size_t props_size;
-
- /* No need to parse the properties when simply copying. */
- const char *properties = svn_sqlite__column_blob(stmt, 6, &props_size,
- scratch_pool);
- SVN_ERR(svn_sqlite__reset(stmt));
- SVN_ERR(svn_sqlite__get_statement(&stmt, dst_wcroot->sdb,
- STMT_INSERT_ACTUAL_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "issbsssss",
- dst_wcroot->wc_id, dst_relpath,
- svn_relpath_dirname(dst_relpath, scratch_pool),
- properties, props_size,
- conflict_old, conflict_new, conflict_working,
- changelist, tree_conflict_data));
- SVN_ERR(svn_sqlite__step(&have_row, stmt));
- }
- SVN_ERR(svn_sqlite__reset(stmt));
-
- return SVN_NO_ERROR;
-}
-
-
-/* Set *COPYFROM_ID, *COPYFROM_RELPATH, *COPYFROM_REV to the values
- appropriate for the copy. Also return *STATUS, *KIND and *HAVE_WORK
- since they are available. This is a helper for
- svn_wc__db_op_copy. */
-static svn_error_t *
-get_info_for_copy(apr_int64_t *copyfrom_id,
- const char **copyfrom_relpath,
- svn_revnum_t *copyfrom_rev,
- svn_wc__db_status_t *status,
- svn_wc__db_kind_t *kind,
- svn_boolean_t *have_work,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
-{
- const char *repos_relpath;
- svn_revnum_t revision;
-
- SVN_ERR(read_info(status, kind, &revision, &repos_relpath, copyfrom_id,
- NULL /* changed_rev */,
- NULL /* changed_date */,
- NULL /* changed_author */,
- NULL /* last_mod_time */,
- NULL /* depth */,
- NULL /* checksum */,
- NULL /* translated_size */,
- NULL /* target */,
- NULL /* changelist */,
- NULL /* original_repos_relpath */,
- NULL /* original_repos_id */,
- NULL /* original_revision */,
- NULL /* props_mod */,
- NULL /* have_base */,
- have_work,
- NULL /* conflicted */,
- NULL /* lock */,
- wcroot, local_relpath, result_pool, scratch_pool));
-
- if (*status == svn_wc__db_status_excluded)
- {
- /* The parent cannot be excluded, so look at the parent and then
- adjust the relpath */
- const char *parent_relpath, *base_name;
- svn_wc__db_status_t parent_status;
- svn_wc__db_kind_t parent_kind;
- svn_boolean_t parent_have_work;
-
- svn_dirent_split(&parent_relpath, &base_name, local_relpath,
- scratch_pool);
- SVN_ERR(get_info_for_copy(copyfrom_id, copyfrom_relpath, copyfrom_rev,
- &parent_status,
- &parent_kind,
- &parent_have_work,
- wcroot, parent_relpath,
- scratch_pool, scratch_pool));
- if (*copyfrom_relpath)
- *copyfrom_relpath = svn_relpath_join(*copyfrom_relpath, base_name,
- result_pool);
- }
- else if (*status == svn_wc__db_status_added)
- {
- const char *op_root_relpath;
-
- SVN_ERR(scan_addition(NULL, &op_root_relpath,
- NULL, NULL, /* repos_* */
- copyfrom_relpath, copyfrom_id, copyfrom_rev,
- wcroot, local_relpath,
- scratch_pool, scratch_pool));
- if (*copyfrom_relpath)
- {
- *copyfrom_relpath
- = svn_relpath_join(*copyfrom_relpath,
- svn_dirent_skip_ancestor(op_root_relpath,
- local_relpath),
- result_pool);
- }
- }
- else if (*status == svn_wc__db_status_deleted)
- {
- const char *base_del_relpath, *work_del_relpath;
-
- SVN_ERR(scan_deletion(&base_del_relpath, NULL, &work_del_relpath,
- wcroot, local_relpath, scratch_pool,
- scratch_pool));
- if (work_del_relpath)
- {
- const char *op_root_relpath;
- const char *parent_del_relpath = svn_dirent_dirname(work_del_relpath,
- scratch_pool);
-
- /* Similar to, but not the same as, the _scan_addition and
- _join above. Can we use get_copyfrom here? */
- SVN_ERR(scan_addition(NULL, &op_root_relpath,
- NULL, NULL, /* repos_* */
- copyfrom_relpath, copyfrom_id, copyfrom_rev,
- wcroot, parent_del_relpath,
- scratch_pool, scratch_pool));
- *copyfrom_relpath
- = svn_relpath_join(*copyfrom_relpath,
- svn_dirent_skip_ancestor(op_root_relpath,
- local_relpath),
- result_pool);
- }
- else if (base_del_relpath)
- {
- SVN_ERR(base_get_info(NULL, NULL, copyfrom_rev, copyfrom_relpath,
- copyfrom_id,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL,
- wcroot, base_del_relpath,
- result_pool, scratch_pool));
- }
- else
- SVN_ERR_MALFUNCTION();
- }
- else
- {
- *copyfrom_relpath = repos_relpath;
- *copyfrom_rev = revision;
- }
-
- return SVN_NO_ERROR;
-}
-
-
-/* Forward declarations for db_op_copy() to use.
-
- ### these are just to avoid churn. a future commit should shuffle the
- ### functions around. */
-static svn_error_t *
-op_depth_of(apr_int64_t *op_depth,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath);
-
-static svn_error_t *
-op_depth_for_copy(apr_int64_t *op_depth,
- apr_int64_t copyfrom_repos_id,
- const char *copyfrom_relpath,
- svn_revnum_t copyfrom_revision,
- svn_wc__db_wcroot_t *wcroot,
- const char *local_relpath,
- apr_pool_t *scratch_pool);
-
-
-/* Like svn_wc__db_op_copy(), but with WCROOT+LOCAL_RELPATH instead of
- DB+LOCAL_ABSPATH. */
-static svn_error_t *
-db_op_copy(svn_wc__db_wcroot_t *src_wcroot,
- const char *src_relpath,
- svn_wc__db_wcroot_t *dst_wcroot,
- const char *dst_relpath,
- const svn_skel_t *work_items,
- apr_pool_t *scratch_pool)
-{
- const char *copyfrom_relpath;
- svn_revnum_t copyfrom_rev;
- svn_wc__db_status_t status;
- svn_wc__db_status_t dst_status;
- svn_boolean_t have_work;
- apr_int64_t copyfrom_id;
- apr_int64_t dst_op_depth;
- svn_wc__db_kind_t kind;
- const apr_array_header_t *children;
-
- SVN_ERR(get_info_for_copy(©from_id, ©from_relpath, ©from_rev,
- &status, &kind, &have_work, src_wcroot,
- src_relpath, scratch_pool, scratch_pool));
-
- SVN_ERR(op_depth_for_copy(&dst_op_depth, copyfrom_id,
- copyfrom_relpath, copyfrom_rev,
- dst_wcroot, dst_relpath, scratch_pool));
-
- SVN_ERR_ASSERT(kind == svn_wc__db_kind_file || kind == svn_wc__db_kind_dir);
-
- /* ### New status, not finished, see notes/wc-ng/copying */
- switch (status)
- {
- case svn_wc__db_status_normal:
- case svn_wc__db_status_added:
- case svn_wc__db_status_moved_here:
- case svn_wc__db_status_copied:
- dst_status = svn_wc__db_status_normal;
- break;
- case svn_wc__db_status_deleted:
- case svn_wc__db_status_not_present:
- dst_status = svn_wc__db_status_not_present;
- break;
- case svn_wc__db_status_excluded:
- dst_status = svn_wc__db_status_excluded;
- break;
- case svn_wc__db_status_absent:
- return svn_error_createf(SVN_ERR_AUTHZ_UNREADABLE, NULL,
- _("Cannot copy '%s' excluded by server"),
- path_for_error_message(src_wcroot,
- src_relpath,
- scratch_pool));
- default:
- return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
- _("Cannot handle status of '%s'"),
- path_for_error_message(src_wcroot,
- src_relpath,
- scratch_pool));
- }
-
- if (kind == svn_wc__db_kind_dir)
- {
- apr_int64_t src_op_depth;
-
- SVN_ERR(op_depth_of(&src_op_depth, src_wcroot, src_relpath));
- SVN_ERR(gather_repo_children(&children, src_wcroot, src_relpath,
- src_op_depth, scratch_pool, scratch_pool));
- }
- else
- children = NULL;
-
- if (src_wcroot == dst_wcroot)
- {
- svn_sqlite__stmt_t *stmt;
- const char *dst_parent_relpath = svn_relpath_dirname(dst_relpath,
- scratch_pool);
-
- if (have_work)
- SVN_ERR(svn_sqlite__get_statement(&stmt, src_wcroot->sdb,
- STMT_INSERT_WORKING_NODE_COPY_FROM_WORKING));
- else
- SVN_ERR(svn_sqlite__get_statement(&stmt, src_wcroot->sdb,
- STMT_INSERT_WORKING_NODE_COPY_FROM_BASE));
-
- SVN_ERR(svn_sqlite__bindf(stmt, "issisnnnt",
- src_wcroot->wc_id, src_relpath,
- dst_relpath,
- dst_op_depth,
- dst_parent_relpath,
- presence_map, dst_status));
-
- if (copyfrom_relpath)
- {
- SVN_ERR(svn_sqlite__bind_int64(stmt, 6, copyfrom_id));
- SVN_ERR(svn_sqlite__bind_text(stmt, 7, copyfrom_relpath));
- SVN_ERR(svn_sqlite__bind_int64(stmt, 8, copyfrom_rev));
- }
- SVN_ERR(svn_sqlite__step_done(stmt));
-
- /* ### Copying changelist is OK for a move but what about a copy? */
- SVN_ERR(svn_sqlite__get_statement(&stmt, src_wcroot->sdb,
- STMT_INSERT_ACTUAL_NODE_FROM_ACTUAL_NODE));
- SVN_ERR(svn_sqlite__bindf(stmt, "isss", src_wcroot->wc_id, src_relpath,
- dst_relpath, dst_parent_relpath));
- SVN_ERR(svn_sqlite__step_done(stmt));
-
- /* Insert incomplete children, if relevant.
- The children are part of the same op and so have the same op_depth.
- (The only time we'd want a different depth is during a recursive
- simple add, but we never insert children here during a simple add.) */
[... 7130 lines stripped ...]