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/01/18 17:42:20 UTC

svn commit: r1060460 [2/2] - in /subversion/trunk/subversion/libsvn_wc: wc_db.c wc_db_pristine.c

Copied: subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c (from r1060430, subversion/trunk/subversion/libsvn_wc/wc_db.c)
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c?p2=subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c&p1=subversion/trunk/subversion/libsvn_wc/wc_db.c&r1=1060430&r2=1060460&rev=1060460&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c Tue Jan 18 16:42:19 2011
@@ -1,5 +1,5 @@
 /*
- * wc_db.c :  manipulating the administrative database
+ * wc_db_pristine.c :  Pristine ("text base") management
  *
  * ====================================================================
  *    Licensed to the Apache Software Foundation (ASF) under one
@@ -23,401 +23,15 @@
 
 #define SVN_WC__I_AM_WC_DB
 
-#include <assert.h>
-#include <apr_pools.h>
-#include <apr_hash.h>
-
-#include "svn_types.h"
-#include "svn_error.h"
 #include "svn_dirent_uri.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 PRISTINE_STORAGE_RELPATH "pristine"
 #define PRISTINE_TEMPDIR_RELPATH ""
-#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 wc_id;
-  const char *local_relpath;
-  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 wc_id;
-  const char *local_relpath;
-  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_pdh_t *pdh,
-                       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_pdh_t *pdh,
-          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_pdh_t *pdh,
-              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_pdh_t *pdh,
-              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_pdh_t *pdh,
-                 const char *local_relpath,
-                 svn_boolean_t exact,
-                 apr_pool_t *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);
-}
 
 
 
@@ -492,8651 +106,457 @@ get_pristine_fname(const char **pristine
 }
 
 
-/* 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_error_t *
+svn_wc__db_pristine_get_path(const char **pristine_abspath,
+                             svn_wc__db_t *db,
+                             const char *wri_abspath,
+                             const svn_checksum_t *sha1_checksum,
+                             apr_pool_t *result_pool,
+                             apr_pool_t *scratch_pool)
 {
-  svn_sqlite__stmt_t *stmt;
-  svn_boolean_t have_row;
+  svn_wc__db_pdh_t *pdh;
+  const char *local_relpath;
+  svn_boolean_t present;
 
-  if (!repos_root_url && !repos_uuid)
-    return SVN_NO_ERROR;
+  SVN_ERR_ASSERT(pristine_abspath != NULL);
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
+  SVN_ERR_ASSERT(sha1_checksum != NULL);
+  /* ### Transitional: accept MD-5 and look up the SHA-1.  Return an error
+   * if the pristine text is not in the store. */
+  if (sha1_checksum->kind != svn_checksum_sha1)
+    SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, db, wri_abspath,
+                                         sha1_checksum,
+                                         scratch_pool, scratch_pool));
+  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
 
-  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_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath,
+                                             db, wri_abspath,
+                                             svn_sqlite__mode_readonly,
+                                             scratch_pool, scratch_pool));
+  VERIFY_USABLE_PDH(pdh);
 
-  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);
+  SVN_ERR(svn_wc__db_pristine_check(&present, db, wri_abspath, sha1_checksum,
+                                    scratch_pool));
+  if (! present)
+    return svn_error_createf(SVN_ERR_WC_DB_ERROR, NULL,
+                             _("Pristine text not found"));
 
-  return svn_error_return(svn_sqlite__reset(stmt));
+  SVN_ERR(get_pristine_fname(pristine_abspath, pdh->wcroot->abspath,
+                             sha1_checksum,
+                             FALSE /* create_subdir */,
+                             result_pool, scratch_pool));
+
+  return SVN_NO_ERROR;
 }
 
-/* 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_wc__db_pdh_t *pdh,
-                            svn_sqlite__stmt_t *stmt,
-                            int col_repos_id,
-                            int col_revision,
-                            int col_repos_relpath,
-                            apr_pool_t *result_pool)
+svn_error_t *
+svn_wc__db_pristine_get_future_path(const char **pristine_abspath,
+                                    const char *wcroot_abspath,
+                                    svn_checksum_t *sha1_checksum,
+                                    apr_pool_t *result_pool,
+                                    apr_pool_t *scratch_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;
+  SVN_ERR(get_pristine_fname(pristine_abspath, wcroot_abspath,
+                             sha1_checksum,
+                             FALSE /* create_subdir */,
+                             result_pool, scratch_pool));
+  return SVN_NO_ERROR;
 }
 
-
-/* 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_error_t *
+svn_wc__db_pristine_read(svn_stream_t **contents,
+                         svn_wc__db_t *db,
+                         const char *wri_abspath,
+                         const svn_checksum_t *sha1_checksum,
+                         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));
+  svn_wc__db_pdh_t *pdh;
+  const char *local_relpath;
+  const char *pristine_abspath;
 
-  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));
+  SVN_ERR_ASSERT(contents != NULL);
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
+  SVN_ERR_ASSERT(sha1_checksum != NULL);
+  /* ### Transitional: accept MD-5 and look up the SHA-1.  Return an error
+   * if the pristine text is not in the store. */
+  if (sha1_checksum->kind != svn_checksum_sha1)
+    SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, db, wri_abspath,
+                                         sha1_checksum,
+                                         scratch_pool, scratch_pool));
+  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
 
-      return svn_error_compose_create(err, svn_sqlite__reset(stmt));
-    }
+  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
+                              wri_abspath, svn_sqlite__mode_readonly,
+                              scratch_pool, scratch_pool));
+  VERIFY_USABLE_PDH(pdh);
 
-  SVN_ERR_ASSERT(!svn_sqlite__column_is_null(stmt, 0));
-  SVN_ERR_ASSERT(!svn_sqlite__column_is_null(stmt, 1));
+  /* ### should we look in the PRISTINE table for anything?  */
 
-  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);
+  SVN_ERR(get_pristine_fname(&pristine_abspath, pdh->wcroot->abspath,
+                             sha1_checksum,
+                             FALSE /* create_subdir */,
+                             scratch_pool, scratch_pool));
+  return svn_error_return(svn_stream_open_readonly(
+                            contents, pristine_abspath,
+                            result_pool, scratch_pool));
 }
 
 
-/* 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_error_t *
+svn_wc__db_pristine_get_tempdir(const char **temp_dir_abspath,
+                                svn_wc__db_t *db,
+                                const char *wri_abspath,
+                                apr_pool_t *result_pool,
+                                apr_pool_t *scratch_pool)
 {
   svn_wc__db_pdh_t *pdh;
   const char *local_relpath;
 
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
+  SVN_ERR_ASSERT(temp_dir_abspath != NULL);
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
 
   SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
+                              wri_abspath, svn_sqlite__mode_readonly,
                               scratch_pool, scratch_pool));
   VERIFY_USABLE_PDH(pdh);
 
-  SVN_ERR(svn_sqlite__get_statement(stmt, pdh->wcroot->sdb, stmt_idx));
-  SVN_ERR(svn_sqlite__bindf(*stmt, "is", pdh->wcroot->wc_id, local_relpath));
-
+  *temp_dir_abspath = svn_dirent_join_many(result_pool,
+                                           pdh->wcroot->abspath,
+                                           svn_wc_get_adm_dir(scratch_pool),
+                                           PRISTINE_TEMPDIR_RELPATH,
+                                           NULL);
   return SVN_NO_ERROR;
 }
 
 
-/* For a given REPOS_ROOT_URL/REPOS_UUID pair, set *REPOS_ID to the existing
-   REPOS_ID value. If one does not exist, throw an error. */
-static svn_error_t *
-fetch_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_error_t *
+svn_wc__db_pristine_install(svn_wc__db_t *db,
+                            const char *tempfile_abspath,
+                            const svn_checksum_t *sha1_checksum,
+                            const svn_checksum_t *md5_checksum,
+                            apr_pool_t *scratch_pool)
 {
-  svn_sqlite__stmt_t *get_stmt;
-
-  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_row(get_stmt));
+  svn_wc__db_pdh_t *pdh;
+  const char *local_relpath;
+  const char *wri_abspath;
+  const char *pristine_abspath;
+  apr_finfo_t finfo;
+  svn_sqlite__stmt_t *stmt;
+  svn_node_kind_t kind;
 
-  *repos_id = svn_sqlite__column_int64(get_stmt, 0);
-  return svn_error_return(svn_sqlite__reset(get_stmt));
-}
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(tempfile_abspath));
+  SVN_ERR_ASSERT(sha1_checksum != NULL);
+  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
+  SVN_ERR_ASSERT(md5_checksum != NULL);
+  SVN_ERR_ASSERT(md5_checksum->kind == svn_checksum_md5);
 
+  /* ### this logic assumes that TEMPFILE_ABSPATH follows this pattern:
+     ###   WCROOT_ABSPATH/COMPONENT/TEMPFNAME
+     ### if we change this (see PRISTINE_TEMPDIR_RELPATH), then this
+     ### logic should change.  */
+  wri_abspath = svn_dirent_dirname(svn_dirent_dirname(tempfile_abspath,
+                                                      scratch_pool),
+                                   scratch_pool);
 
-/* 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_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
+                              wri_abspath, svn_sqlite__mode_readonly,
+                              scratch_pool, scratch_pool));
+  VERIFY_USABLE_PDH(pdh);
 
-  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));
+  SVN_ERR(get_pristine_fname(&pristine_abspath, pdh->wcroot->abspath,
+                             sha1_checksum,
+                             TRUE /* create_subdir */,
+                             scratch_pool, scratch_pool));
 
-  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));
-}
+  SVN_ERR(svn_io_check_path(pristine_abspath, &kind, scratch_pool));
 
-
-/* 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_sqlite__db_t *sdb, 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 =
-    (*pibb->local_relpath == '\0') ? NULL
-    : svn_relpath_dirname(pibb->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, sdb, STMT_INSERT_NODE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "isisisr"
-                            "tstr"               /* 8 - 11 */
-                            "isnnnnns",          /* 12 - 19 */
-                            pibb->wc_id,         /* 1 */
-                            pibb->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(sdb, pibb->wc_id,
-                                       pibb->local_relpath,
-                                       pibb->repos_id,
-                                       pibb->repos_relpath,
-                                       pibb->revision,
-                                       pibb->children,
-                                       0 /* BASE */,
-                                       scratch_pool));
-
-  if (parent_relpath)
-    SVN_ERR(extend_parent_delete(sdb, pibb->wc_id, pibb->local_relpath,
-                                 scratch_pool));
-
-  SVN_ERR(add_work_items(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_sqlite__db_t *sdb,
-                    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(*piwb->local_relpath != '\0');
-  parent_relpath = svn_relpath_dirname(piwb->local_relpath, scratch_pool);
-
-  SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_INSERT_NODE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "isisnnntstrisn"
-                "nnnn" /* properties translated_size last_mod_time dav_cache */
-                "s",
-                piwb->wc_id, piwb->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(sdb, piwb->wc_id,
-                                       piwb->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(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);
-}
-
-
-/* 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_pdh_t *pdh,
-                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,
-                               pdh->wcroot->sdb, pdh->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 repository
-   children of the directory PDH:LOCAL_RELPATH - that is, the children at
-   the same op-depth. */
-static svn_error_t *
-gather_repo_children(const apr_array_header_t **children,
-                     svn_wc__db_pdh_t *pdh,
-                     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, pdh->wcroot->sdb,
-                                    STMT_SELECT_OP_DEPTH_CHILDREN));
-  SVN_ERR(svn_sqlite__bindf(stmt, "isi", pdh->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_pdh_t *pdh,
-              const char *local_abspath,
-              apr_pool_t *scratch_pool)
-{
-  if (pdh->adm_access)
-    svn_wc__adm_access_set_entries(pdh->adm_access, NULL);
-
-  if (local_abspath
-      && strcmp(local_abspath, pdh->local_abspath) == 0
-      && strcmp(local_abspath, pdh->wcroot->abspath) != 0)
-    {
-      svn_wc__db_pdh_t *parent_pdh;
-
-      SVN_ERR(svn_wc__db_pdh_navigate_to_parent(&parent_pdh, db, pdh,
-                                                svn_sqlite__mode_readonly,
-                                                scratch_pool));
-
-      if (parent_pdh->adm_access)
-        svn_wc__adm_access_set_entries(parent_pdh->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_pdh_t *pdh;
-  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));
-
-  /* Begin construction of the PDH.  */
-  pdh = apr_pcalloc(db->state_pool, sizeof(*pdh));
-  pdh->local_abspath = apr_pstrdup(db->state_pool, local_abspath);
-
-  /* Create the WCROOT for this directory.  */
-  SVN_ERR(svn_wc__db_pdh_create_wcroot(&pdh->wcroot, pdh->local_abspath,
-                        sdb, wc_id, FORMAT_FROM_SDB,
-                        FALSE /* auto-upgrade */,
-                        FALSE /* enforce_empty_wq */,
-                        db->state_pool, scratch_pool));
-
-  /* The PDH is complete. Stash it into DB.  */
-  apr_hash_set(db->dir_data, pdh->local_abspath, APR_HASH_KEY_STRING, pdh);
-
-  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.wc_id = wc_id;
-  ibb.local_relpath = "";
-  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, sdb, 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_pdh_t *pdh;
-
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readonly,
-                              result_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  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_pdh_t *pdh;
-  const char *unused_relpath;
-
-#if 0
-  SVN_ERR_ASSERT(svn_relpath_is_canonical(local_abspath));
-#endif
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &unused_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  *local_abspath = svn_dirent_join(pdh->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_pdh_t *pdh;
-  const char *unused_relpath;
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &unused_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-
-  /* Can't use VERIFY_USABLE_PDH, as this should be usable to detect
-     where call upgrade */
-
-  if (pdh->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, pdh->wcroot->abspath);
-
-  return SVN_NO_ERROR;
-}
-
-struct with_sqlite_lock_baton
-{
-  svn_wc__db_t *db;
-  svn_wc__db_sqlite_lock_cb lock_cb;
-  void *lock_baton;
-};
-
-static svn_error_t *
-call_sqlite_lock_cb(void *baton,
-                    svn_sqlite__db_t *sdb,
-                    apr_pool_t *scratch_pool)
-{
-  struct with_sqlite_lock_baton *lb = baton;
-
-  return svn_error_return(lb->lock_cb(lb->db, lb->lock_baton, scratch_pool));
-}
-
-svn_error_t *
-svn_wc__db_with_sqlite_lock(svn_wc__db_t *db,
-                            const char *wri_abspath,
-                            svn_wc__db_sqlite_lock_cb lock_cb,
-                            void *cb_baton,
-                            apr_pool_t *scratch_pool)
-{
-  svn_wc__db_pdh_t *pdh;
-  const char *unused_relpath;
-  struct with_sqlite_lock_baton baton;
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &unused_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-
-  /* Can't use VERIFY_USABLE_PDH, as this should be usable to detect
-     where call upgrade */
-
-  if (pdh->wcroot == NULL || !pdh->wcroot->sdb)
-    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));
-
-  baton.db = db;
-  baton.lock_cb = lock_cb;
-  baton.lock_baton = cb_baton;
-
-  return svn_error_return(
-            svn_sqlite__with_lock(pdh->wcroot->sdb,
-                                  call_sqlite_lock_cb,
-                                  &baton,
-                                  scratch_pool));
-}
-
-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_pdh_t *pdh;
-  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_absolute(repos_root_url));
-  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_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
-                          pdh->wcroot->sdb, scratch_pool));
-
-  blank_ibb(&ibb);
-
-  ibb.status = svn_wc__db_status_normal;
-  ibb.kind = svn_wc__db_kind_dir;
-  ibb.wc_id = pdh->wcroot->wc_id;
-  ibb.local_relpath = local_relpath;
-  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(svn_sqlite__with_transaction(pdh->wcroot->sdb,
-                                       insert_base_node, &ibb,
-                                       scratch_pool));
-
-  /* ### worry about flushing child subdirs?  */
-  SVN_ERR(flush_entries(db, pdh, 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_pdh_t *pdh;
-  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_absolute(repos_root_url));
-  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_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
-                          pdh->wcroot->sdb, scratch_pool));
-
-  blank_ibb(&ibb);
-
-  ibb.status = svn_wc__db_status_normal;
-  ibb.kind = svn_wc__db_kind_file;
-  ibb.wc_id = pdh->wcroot->wc_id;
-  ibb.local_relpath = local_relpath;
-  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(svn_sqlite__with_transaction(pdh->wcroot->sdb,
-                                       insert_base_node, &ibb,
-                                       scratch_pool));
-
-  SVN_ERR(flush_entries(db, pdh, 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_pdh_t *pdh;
-  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_absolute(repos_root_url));
-  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_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
-                          pdh->wcroot->sdb, scratch_pool));
-
-  blank_ibb(&ibb);
-
-  ibb.status = svn_wc__db_status_normal;
-  ibb.kind = svn_wc__db_kind_symlink;
-  ibb.wc_id = pdh->wcroot->wc_id;
-  ibb.local_relpath = local_relpath;
-  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(svn_sqlite__with_transaction(pdh->wcroot->sdb,
-                                       insert_base_node, &ibb,
-                                       scratch_pool));
-
-  SVN_ERR(flush_entries(db, pdh, 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_pdh_t *pdh;
-  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_absolute(repos_root_url));
-  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_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(create_repos_id(&repos_id, repos_root_url, repos_uuid,
-                          pdh->wcroot->sdb, scratch_pool));
-
-  blank_ibb(&ibb);
-
-  ibb.status = status;
-  ibb.kind = kind;
-  ibb.wc_id = pdh->wcroot->wc_id;
-  ibb.local_relpath = local_relpath;
-  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(svn_sqlite__with_transaction(pdh->wcroot->sdb,
-                                       insert_base_node, &ibb,
-                                       scratch_pool));
-
-  SVN_ERR(flush_entries(db, pdh, 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);
-}
-
-struct base_remove_baton {
-  const char *local_relpath;
-  apr_int64_t wc_id;
-};
-
-static svn_error_t *
-db_base_remove(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool)
-{
-  struct base_remove_baton *brb = baton;
-  svn_sqlite__stmt_t *stmt;
-  svn_boolean_t have_row;
-
-  SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_DELETE_BASE_NODE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "is", brb->wc_id, brb->local_relpath));
-  SVN_ERR(svn_sqlite__step_done(stmt));
-
-  SVN_ERR(retract_parent_delete(sdb, brb->wc_id, brb->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, sdb, STMT_SELECT_WORKING_NODE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "is", brb->wc_id, brb->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, sdb,
-                                    STMT_DELETE_ACTUAL_NODE_WITHOUT_CONFLICT));
-      SVN_ERR(svn_sqlite__bindf(stmt, "is", brb->wc_id, brb->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_pdh_t *pdh;
-  const char *local_relpath;
-  struct base_remove_baton brb;
-
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readwrite,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  brb.local_relpath = local_relpath;
-  brb.wc_id = pdh->wcroot->wc_id;
-
-  SVN_ERR(svn_sqlite__with_transaction(pdh->wcroot->sdb,
-                                       db_base_remove, &brb,
-                                       scratch_pool));
-
-  SVN_ERR(flush_entries(db, pdh, local_abspath, scratch_pool));
-
-  return SVN_NO_ERROR;
-}
-
-/* Like svn_wc__db_base_get_info(), but taking PDH+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_pdh_t *pdh,
-              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, pdh->wcroot->sdb,
-                                    lock ? STMT_SELECT_BASE_NODE_WITH_LOCK
-                                         : STMT_SELECT_BASE_NODE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "is", pdh->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,
-                                        pdh, 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(pdh->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(pdh->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_pdh_t *pdh;
-  const char *local_relpath;
-  apr_int64_t repos_id;
-
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              local_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  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,
-                        pdh, local_relpath, result_pool, scratch_pool));
-  SVN_ERR_ASSERT(repos_id != INVALID_REPOS_ID);
-  SVN_ERR(fetch_repos_info(repos_root_url, repos_uuid,
-                           pdh->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_pdh_t *pdh;
-  const char *local_relpath;
-
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                                             local_abspath,
-                                             svn_sqlite__mode_readonly,
-                                             scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  return gather_repo_children(children, pdh, 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_pdh_t *pdh;
-  const char *local_relpath;
-  const char *like_arg;
-  svn_sqlite__stmt_t *stmt;
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath,
-                                             db, local_abspath,
-                                             svn_sqlite__mode_readwrite,
-                                             scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  like_arg = construct_like_arg(local_relpath, scratch_pool);
-
-  SVN_ERR(svn_sqlite__get_statement(&stmt, pdh->wcroot->sdb,
-                                    STMT_CLEAR_BASE_NODE_RECURSIVE_DAV_CACHE));
-  SVN_ERR(svn_sqlite__bindf(stmt, "iss", pdh->wcroot->wc_id, local_relpath,
-                            like_arg));
-
-  SVN_ERR(svn_sqlite__step_done(stmt));
-
-  return SVN_NO_ERROR;
-}
-
-svn_error_t *
-svn_wc__db_pristine_get_path(const char **pristine_abspath,
-                             svn_wc__db_t *db,
-                             const char *wri_abspath,
-                             const svn_checksum_t *sha1_checksum,
-                             apr_pool_t *result_pool,
-                             apr_pool_t *scratch_pool)
-{
-  svn_wc__db_pdh_t *pdh;
-  const char *local_relpath;
-  svn_boolean_t present;
-
-  SVN_ERR_ASSERT(pristine_abspath != NULL);
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
-  SVN_ERR_ASSERT(sha1_checksum != NULL);
-  /* ### Transitional: accept MD-5 and look up the SHA-1.  Return an error
-   * if the pristine text is not in the store. */
-  if (sha1_checksum->kind != svn_checksum_sha1)
-    SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, db, wri_abspath,
-                                         sha1_checksum,
-                                         scratch_pool, scratch_pool));
-  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath,
-                                             db, wri_abspath,
-                                             svn_sqlite__mode_readonly,
-                                             scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(svn_wc__db_pristine_check(&present, db, wri_abspath, sha1_checksum,
-                                    scratch_pool));
-  if (! present)
-    return svn_error_createf(SVN_ERR_WC_DB_ERROR, NULL,
-                             _("Pristine text not found"));
-
-  SVN_ERR(get_pristine_fname(pristine_abspath, pdh->wcroot->abspath,
-                             sha1_checksum,
-                             FALSE /* create_subdir */,
-                             result_pool, scratch_pool));
-
-  return SVN_NO_ERROR;
-}
-
-svn_error_t *
-svn_wc__db_pristine_get_future_path(const char **pristine_abspath,
-                                    const char *wcroot_abspath,
-                                    svn_checksum_t *sha1_checksum,
-                                    apr_pool_t *result_pool,
-                                    apr_pool_t *scratch_pool)
-{
-  SVN_ERR(get_pristine_fname(pristine_abspath, wcroot_abspath,
-                             sha1_checksum,
-                             FALSE /* create_subdir */,
-                             result_pool, scratch_pool));
-  return SVN_NO_ERROR;
-}
-
-svn_error_t *
-svn_wc__db_pristine_read(svn_stream_t **contents,
-                         svn_wc__db_t *db,
-                         const char *wri_abspath,
-                         const svn_checksum_t *sha1_checksum,
-                         apr_pool_t *result_pool,
-                         apr_pool_t *scratch_pool)
-{
-  svn_wc__db_pdh_t *pdh;
-  const char *local_relpath;
-  const char *pristine_abspath;
-
-  SVN_ERR_ASSERT(contents != NULL);
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
-  SVN_ERR_ASSERT(sha1_checksum != NULL);
-  /* ### Transitional: accept MD-5 and look up the SHA-1.  Return an error
-   * if the pristine text is not in the store. */
-  if (sha1_checksum->kind != svn_checksum_sha1)
-    SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, db, wri_abspath,
-                                         sha1_checksum,
-                                         scratch_pool, scratch_pool));
-  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  /* ### should we look in the PRISTINE table for anything?  */
-
-  SVN_ERR(get_pristine_fname(&pristine_abspath, pdh->wcroot->abspath,
-                             sha1_checksum,
-                             FALSE /* create_subdir */,
-                             scratch_pool, scratch_pool));
-  return svn_error_return(svn_stream_open_readonly(
-                            contents, pristine_abspath,
-                            result_pool, scratch_pool));
-}
-
-
-svn_error_t *
-svn_wc__db_pristine_get_tempdir(const char **temp_dir_abspath,
-                                svn_wc__db_t *db,
-                                const char *wri_abspath,
-                                apr_pool_t *result_pool,
-                                apr_pool_t *scratch_pool)
-{
-  svn_wc__db_pdh_t *pdh;
-  const char *local_relpath;
-
-  SVN_ERR_ASSERT(temp_dir_abspath != NULL);
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  *temp_dir_abspath = svn_dirent_join_many(result_pool,
-                                           pdh->wcroot->abspath,
-                                           svn_wc_get_adm_dir(scratch_pool),
-                                           PRISTINE_TEMPDIR_RELPATH,
-                                           NULL);
-  return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_wc__db_pristine_install(svn_wc__db_t *db,
-                            const char *tempfile_abspath,
-                            const svn_checksum_t *sha1_checksum,
-                            const svn_checksum_t *md5_checksum,
-                            apr_pool_t *scratch_pool)
-{
-  svn_wc__db_pdh_t *pdh;
-  const char *local_relpath;
-  const char *wri_abspath;
-  const char *pristine_abspath;
-  apr_finfo_t finfo;
-  svn_sqlite__stmt_t *stmt;
-  svn_node_kind_t kind;
-
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(tempfile_abspath));
-  SVN_ERR_ASSERT(sha1_checksum != NULL);
-  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
-  SVN_ERR_ASSERT(md5_checksum != NULL);
-  SVN_ERR_ASSERT(md5_checksum->kind == svn_checksum_md5);
-
-  /* ### this logic assumes that TEMPFILE_ABSPATH follows this pattern:
-     ###   WCROOT_ABSPATH/COMPONENT/TEMPFNAME
-     ### if we change this (see PRISTINE_TEMPDIR_RELPATH), then this
-     ### logic should change.  */
-  wri_abspath = svn_dirent_dirname(svn_dirent_dirname(tempfile_abspath,
-                                                      scratch_pool),
-                                   scratch_pool);
-
-  SVN_ERR(svn_wc__db_pdh_parse_local_abspath(&pdh, &local_relpath, db,
-                              wri_abspath, svn_sqlite__mode_readonly,
-                              scratch_pool, scratch_pool));
-  VERIFY_USABLE_PDH(pdh);
-
-  SVN_ERR(get_pristine_fname(&pristine_abspath, pdh->wcroot->abspath,
-                             sha1_checksum,
-                             TRUE /* create_subdir */,
-                             scratch_pool, scratch_pool));
-
-
-  SVN_ERR(svn_io_check_path(pristine_abspath, &kind, scratch_pool));
-
-  if (kind == svn_node_file)
-    {
-      /* Remove the tempfile, it's already there */
-      return svn_error_return(
-                  svn_io_remove_file2(tempfile_abspath,
-                                      FALSE, scratch_pool));
-    }
-
-  /* Put the file into its target location.  */

[... 6939 lines stripped ...]