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 2010/12/11 01:16:08 UTC

svn commit: r1044548 [33/39] - in /subversion/branches/ignore-mergeinfo: ./ build/ build/ac-macros/ build/generator/ build/generator/templates/ build/win32/ contrib/client-side/ contrib/hook-scripts/ contrib/server-side/ notes/api-errata/ notes/api-err...

Modified: subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.c Sat Dec 11 00:15:55 2010
@@ -39,7 +39,7 @@
 #define SVNRDUMP_PROP_LOCK SVN_PROP_PREFIX "rdump-lock"
 #define LOCK_RETRIES 10
 
-#ifdef SVN_DEBUG
+#if 0
 #define LDR_DBG(x) SVN_DBG(x)
 #else
 #define LDR_DBG(x) while(0)
@@ -56,6 +56,12 @@ commit_callback(const svn_commit_info_t 
   return SVN_NO_ERROR;
 }
 
+/* See subversion/svnsync/main.c for docstring */
+static svn_boolean_t is_atomicity_error(svn_error_t *err)
+{
+  return svn_error_has_cause(err, SVN_ERR_FS_PROP_BASEVALUE_MISMATCH);
+}
+
 /* Acquire a lock (of sorts) on the repository associated with the
  * given RA SESSION. This lock is just a revprop change attempt in a
  * time-delay loop. This function is duplicated by svnsync in main.c.
@@ -65,14 +71,33 @@ commit_callback(const svn_commit_info_t 
  * applications to avoid duplication.
  */
 static svn_error_t *
-get_lock(svn_ra_session_t *session, apr_pool_t *pool)
+get_lock(const svn_string_t **lock_string_p,
+         svn_ra_session_t *session,
+         svn_cancel_func_t cancel_func,
+         void *cancel_baton,
+         apr_pool_t *pool)
 {
   char hostname_str[APRMAXHOSTLEN + 1] = { 0 };
   svn_string_t *mylocktoken, *reposlocktoken;
   apr_status_t apr_err;
+  svn_boolean_t be_atomic;
   apr_pool_t *subpool;
   int i;
 
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                pool));
+  if (! be_atomic)
+    {
+      /* Pre-1.7 servers can't lock without a race condition.  (Issue #3546) */
+      svn_error_t *err =
+        svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+                         _("Target server does not support atomic revision "
+                           "property edits; consider upgrading it to 1.7."));
+      svn_handle_warning2(stderr, err, "svnrdump: ");
+      svn_error_clear(err);
+    }
+
   apr_err = apr_gethostname(hostname_str, sizeof(hostname_str), pool);
   if (apr_err)
     return svn_error_wrap_apr(apr_err, _("Can't get local hostname"));
@@ -80,35 +105,63 @@ get_lock(svn_ra_session_t *session, apr_
   mylocktoken = svn_string_createf(pool, "%s:%s", hostname_str,
                                    svn_uuid_generate(pool));
 
+  /* If we succeed, this is what the property will be set to. */
+  *lock_string_p = mylocktoken;
+
   subpool = svn_pool_create(pool);
 
   for (i = 0; i < LOCK_RETRIES; ++i)
     {
+      svn_error_t *err;
+
       svn_pool_clear(subpool);
 
+      SVN_ERR(cancel_func(cancel_baton));
       SVN_ERR(svn_ra_rev_prop(session, 0, SVNRDUMP_PROP_LOCK, &reposlocktoken,
                               subpool));
 
       if (reposlocktoken)
         {
-          /* Did we get it? If so, we're done, otherwise we sleep. */
+          /* Did we get it? If so, we're done. */
           if (strcmp(reposlocktoken->data, mylocktoken->data) == 0)
             return SVN_NO_ERROR;
-          else
-            {
-              SVN_ERR(svn_cmdline_printf
-                      (pool, _("Failed to get lock on destination "
-                               "repos, currently held by '%s'\n"),
-                       reposlocktoken->data));
 
-              apr_sleep(apr_time_from_sec(1));
-            }
+          /* ...otherwise, tell the user that someone else has the
+             lock and sleep before retrying. */
+          SVN_ERR(svn_cmdline_printf
+                  (pool, _("Failed to get lock on destination "
+                           "repos, currently held by '%s'\n"),
+                   reposlocktoken->data));
+          
+          apr_sleep(apr_time_from_sec(1));
         }
       else if (i < LOCK_RETRIES - 1)
         {
+          const svn_string_t *unset = NULL;
+
           /* Except in the very last iteration, try to set the lock. */
-          SVN_ERR(svn_ra_change_rev_prop(session, 0, SVNRDUMP_PROP_LOCK,
-                                         mylocktoken, subpool));
+          err = svn_ra_change_rev_prop2(session, 0, SVNRDUMP_PROP_LOCK,
+                                        be_atomic ? &unset : NULL,
+                                        mylocktoken, subpool);
+
+          if (be_atomic && err && is_atomicity_error(err))
+            {
+              /* Someone else has the lock.  Let's loop. */
+              svn_error_clear(err);
+            }
+          else if (be_atomic && err == SVN_NO_ERROR)
+            {
+              /* We have the lock.  However, for compatibility with
+                 concurrent svnrdumps that don't support atomicity, loop
+                 anyway to double-check that they haven't overwritten
+                 our lock. */
+              continue;
+            }
+          else
+            {
+              /* Genuine error, or we aren't atomic and need to loop. */
+              SVN_ERR(err);
+            }
         }
     }
 
@@ -117,6 +170,33 @@ get_lock(svn_ra_session_t *session, apr_
                              "after %d attempts"), i);
 }
 
+/* Remove the lock on SESSION iff the lock is owned by MYLOCKTOKEN. */
+static svn_error_t *
+maybe_unlock(svn_ra_session_t *session,
+             const svn_string_t *mylocktoken,
+             apr_pool_t *scratch_pool)
+{
+  svn_string_t *reposlocktoken;
+  svn_boolean_t be_atomic;
+
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                scratch_pool));
+  SVN_ERR(svn_ra_rev_prop(session, 0, SVNRDUMP_PROP_LOCK,
+                          &reposlocktoken, scratch_pool));
+  if (reposlocktoken && strcmp(reposlocktoken->data, mylocktoken->data) == 0)
+    {
+      svn_error_t *err =
+        svn_ra_change_rev_prop2(session, 0, SVNRDUMP_PROP_LOCK,
+                                be_atomic ? &mylocktoken : NULL, NULL,
+                                scratch_pool);
+      if (is_atomicity_error(err))
+        return svn_error_quick_wrap(err, _("svnrdump's lock was stolen; "
+                                           "can't remove it"));
+    }
+  return SVN_NO_ERROR;
+}
+
 static svn_error_t *
 new_revision_record(void **revision_baton,
 		    apr_hash_t *headers,
@@ -231,7 +311,7 @@ new_node_record(void **node_baton,
       child_db = apr_pcalloc(rb->pool, sizeof(*child_db));
       child_db->baton = child_baton;
       child_db->depth = 0;
-      child_db->relpath = svn_relpath_canonicalize("/", rb->pool);
+      child_db->relpath = "";
       child_db->parent = NULL;
       rb->db = child_db;
     }
@@ -395,8 +475,8 @@ set_revision_property(void *baton,
   else
     /* Special handling for revision 0; this is safe because the
        commit_editor hasn't been created yet. */
-    SVN_ERR(svn_ra_change_rev_prop(rb->pb->session, rb->rev, name, value,
-                                   rb->pool));
+    SVN_ERR(svn_ra_change_rev_prop2(rb->pb->session, rb->rev,
+                                    name, NULL, value, rb->pool));
 
   /* Remember any datestamp/ author that passes through (see comment
      in close_revision). */
@@ -539,7 +619,9 @@ close_revision(void *baton)
           SVN_ERR(commit_editor->close_directory(rb->db->baton, rb->pool));
           rb->db = rb->db->parent;
         }
+      /* root dir's baton */
       LDR_DBG(("Closing edit on %p\n", commit_edit_baton));
+      SVN_ERR(commit_editor->close_directory(rb->db->baton, rb->pool));
       SVN_ERR(commit_editor->close_edit(commit_edit_baton, rb->pool));
     }
   else
@@ -555,17 +637,18 @@ close_revision(void *baton)
 
       LDR_DBG(("Opened root %p\n", child_baton));
       LDR_DBG(("Closing edit on %p\n", commit_edit_baton));
+      SVN_ERR(commit_editor->close_directory(child_baton, rb->pool));
       SVN_ERR(commit_editor->close_edit(commit_edit_baton, rb->pool));
     }
 
   /* svn_fs_commit_txn rewrites the datestamp/ author property-
      rewrite it by hand after closing the commit_editor. */
-  SVN_ERR(svn_ra_change_rev_prop(rb->pb->session, rb->rev,
-                                 SVN_PROP_REVISION_DATE,
-                                 rb->datestamp, rb->pool));
-  SVN_ERR(svn_ra_change_rev_prop(rb->pb->session, rb->rev,
-                                 SVN_PROP_REVISION_AUTHOR,
-                                 rb->author, rb->pool));
+  SVN_ERR(svn_ra_change_rev_prop2(rb->pb->session, rb->rev,
+                                  SVN_PROP_REVISION_DATE,
+                                  NULL, rb->datestamp, rb->pool));
+  SVN_ERR(svn_ra_change_rev_prop2(rb->pb->session, rb->rev,
+                                  SVN_PROP_REVISION_AUTHOR,
+                                  NULL, rb->author, rb->pool));
 
   svn_pool_destroy(rb->pool);
 
@@ -608,16 +691,28 @@ drive_dumpstream_loader(svn_stream_t *st
                         const svn_repos_parse_fns2_t *parser,
                         void *parse_baton,
                         svn_ra_session_t *session,
+                        svn_cancel_func_t cancel_func,
+                        void *cancel_baton,
                         apr_pool_t *pool)
 {
-  struct parse_baton *pb;
-  pb = parse_baton;
-
-  SVN_ERR(get_lock(session, pool));
+  struct parse_baton *pb = parse_baton;
+  const svn_string_t *lock_string;
+  svn_boolean_t be_atomic;
+  svn_error_t *err;
+
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                pool));
+  SVN_ERR(get_lock(&lock_string, session, cancel_func, cancel_baton, pool));
   SVN_ERR(svn_ra_get_repos_root2(session, &(pb->root_url), pool));
-  SVN_ERR(svn_repos_parse_dumpstream2(stream, parser, parse_baton,
-                                      NULL, NULL, pool));
-  SVN_ERR(svn_ra_change_rev_prop(session, 0, SVNRDUMP_PROP_LOCK, NULL, pool));
+  err = svn_repos_parse_dumpstream2(stream, parser, parse_baton,
+                                    cancel_func, cancel_baton, pool);
 
-  return SVN_NO_ERROR;
+  /* If all goes well, or if we're cancelled cleanly, don't leave a
+     stray lock behind. */
+  if ((! err) 
+      || (err && (err->apr_err == SVN_ERR_CANCELLED)))
+    err = svn_error_compose_create(maybe_unlock(session, lock_string, pool),
+                                   err);
+  return err;
 }

Modified: subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.h
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.h?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.h (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnrdump/load_editor.h Sat Dec 11 00:15:55 2010
@@ -89,11 +89,10 @@ struct revision_baton
 };
 
 /**
- * Build up a load editor @a parser for parsing a dumpfile stream from @a stream
- * set to fire the appropriate callbacks in load editor along with a
- * @a parser_baton, using @a pool for all memory allocations. The
- * @a editor/ @a edit_baton are central to the functionality of the
- *  parser.
+ * Build up a dumpstream parser @a parser (and corresponding baton @a
+ * parse_baton) to fire the appropriate callbacks in a commit editor
+ * set to commit to session @a session. Use @a pool for all memory
+ * allocations.
  */
 svn_error_t *
 get_dumpstream_loader(const svn_repos_parse_fns2_t **parser,
@@ -102,14 +101,20 @@ get_dumpstream_loader(const svn_repos_pa
                       apr_pool_t *pool);
 
 /**
- * Drive the load editor @a editor using the data in @a stream using
- * @a pool for all memory allocations.
+ * Drive the dumpstream loader described by @a parser and @a
+ * parse_baton to parse and commit the stream @a stream to the
+ * location described by @a session. Use @a pool for all memory
+ * allocations.  Use @a cancel_func and @a cancel_baton to check for
+ * user cancellation of the operation (for timely-but-safe
+ * termination).
  */
 svn_error_t *
 drive_dumpstream_loader(svn_stream_t *stream,
                         const svn_repos_parse_fns2_t *parser,
                         void *parse_baton,
                         svn_ra_session_t *session,
+                        svn_cancel_func_t cancel_func,
+                        void *cancel_baton,
                         apr_pool_t *pool);
 
 #endif

Modified: subversion/branches/ignore-mergeinfo/subversion/svnrdump/svnrdump.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnrdump/svnrdump.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnrdump/svnrdump.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnrdump/svnrdump.c Sat Dec 11 00:15:55 2010
@@ -1,6 +1,6 @@
 /*
  *  svnrdump.c: Produce a dumpfile of a local or remote repository
- *  without touching the filesystem, but for temporary files.
+ *              without touching the filesystem, but for temporary files.
  *
  * ====================================================================
  *    Licensed to the Apache Software Foundation (ASF) under one
@@ -22,6 +22,8 @@
  * ====================================================================
  */
 
+#include <apr_signal.h>
+
 #include "svn_pools.h"
 #include "svn_cmdline.h"
 #include "svn_client.h"
@@ -39,63 +41,105 @@
 
 #include "private/svn_cmdline_private.h"
 
+
+
+/*** Cancellation ***/
+
+/* A flag to see if we've been cancelled by the client or not. */
+static volatile sig_atomic_t cancelled = FALSE;
+
+/* A signal handler to support cancellation. */
+static void
+signal_handler(int signum)
+{
+  apr_signal(signum, SIG_IGN);
+  cancelled = TRUE;
+}
+
+/* Our cancellation callback. */
+static svn_error_t *
+check_cancel(void *baton)
+{
+  if (cancelled)
+    return svn_error_create(SVN_ERR_CANCELLED, NULL, _("Caught signal"));
+  else
+    return SVN_NO_ERROR;
+}
+
+
+
+
 static svn_opt_subcommand_t dump_cmd, load_cmd;
 
 enum svn_svnrdump__longopt_t
   {
     opt_config_dir = SVN_OPT_FIRST_LONGOPT_ID,
+    opt_config_option,
     opt_auth_username,
     opt_auth_password,
-    opt_non_interactive,
     opt_auth_nocache,
+    opt_non_interactive,
+    opt_incremental,
     opt_version,
-    opt_config_option,
   };
 
+#define SVN_SVNRDUMP__BASE_OPTIONS opt_config_dir, \
+                                   opt_config_option, \
+                                   opt_auth_username, \
+                                   opt_auth_password, \
+                                   opt_auth_nocache, \
+                                   opt_non_interactive
+
 static const svn_opt_subcommand_desc2_t svnrdump__cmd_table[] =
-  {
-    { "dump", dump_cmd, { 0 },
-      N_("usage: svnrdump dump URL [-r LOWER[:UPPER]]\n\n"
-         "Dump revisions LOWER to UPPER of repository at remote URL "
-         "to stdout in a 'dumpfile' portable format.\n"
-         "If only LOWER is given, dump that one revision.\n"),
-      { 0 } },
-    { "load", load_cmd, { 0 },
-      N_("usage: svnrdump load URL\n\n"
-         "Load a 'dumpfile' given on stdin to a repository "
-         "at remote URL.\n"),
-      { 0 } },
-    { "help", 0, { "?", "h" },
-      N_("usage: svnrdump help [SUBCOMMAND...]\n\n"
-         "Describe the usage of this program or its subcommands.\n"),
-      { 0 } },
-    { NULL, NULL, { 0 }, NULL, { 0 } }
-  };
+{
+  { "dump", dump_cmd, { 0 },
+    N_("usage: svnrdump dump URL [-r LOWER[:UPPER]]\n\n"
+       "Dump revisions LOWER to UPPER of repository at remote URL to stdout\n"
+       "in a 'dumpfile' portable format.  If only LOWER is given, dump that\n"
+       "one revision.\n"),
+    { 'r', 'q', opt_incremental, SVN_SVNRDUMP__BASE_OPTIONS } },
+  { "load", load_cmd, { 0 },
+    N_("usage: svnrdump load URL\n\n"
+       "Load a 'dumpfile' given on stdin to a repository at remote URL.\n"),
+    { 'q', SVN_SVNRDUMP__BASE_OPTIONS } },
+  { "help", 0, { "?", "h" },
+    N_("usage: svnrdump help [SUBCOMMAND...]\n\n"
+       "Describe the usage of this program or its subcommands.\n"),
+    { 0 } },
+  { NULL, NULL, { 0 }, NULL, { 0 } }
+};
 
 static const apr_getopt_option_t svnrdump__options[] =
   {
-    {"revision",     'r', 1, N_("specify revision number ARG (or X:Y range)")},
-    {"quiet",         'q', 0, N_("no progress (only errors) to stderr")},
-    {"config-dir",    opt_config_dir, 1, N_("read user configuration files from"
-                                            " directory ARG") },
-    {"username",      opt_auth_username, 1, N_("specify a username ARG")},
-    {"password",      opt_auth_password, 1, N_("specify a password ARG")},
-    {"non-interactive", opt_non_interactive, 0, N_("do no interactive"
-                                                   " prompting")},
-    {"no-auth-cache", opt_auth_nocache, 0, N_("do not cache authentication"
-                                              " tokens")},
-  
-    {"help",          'h', 0, N_("display this help")},
-    {"version",       opt_version, 0, N_("show program version information")},
+    {"revision",     'r', 1, 
+                      N_("specify revision number ARG (or X:Y range)")},
+    {"quiet",         'q', 0,
+                      N_("no progress (only errors) to stderr")},
+    {"incremental",   opt_incremental, 0,
+                      N_("dump incrementally")},
+    {"config-dir",    opt_config_dir, 1,
+                      N_("read user configuration files from directory ARG")},
+    {"username",      opt_auth_username, 1,
+                      N_("specify a username ARG")},
+    {"password",      opt_auth_password, 1,
+                      N_("specify a password ARG")},
+    {"non-interactive", opt_non_interactive, 0,
+                      N_("do no interactive prompting")},
+    {"no-auth-cache", opt_auth_nocache, 0,
+                      N_("do not cache authentication tokens")},
+    {"help",          'h', 0,
+                      N_("display this help")},
+    {"version",       opt_version, 0,
+                      N_("show program version information")},
     {"config-option", opt_config_option, 1,
-                    N_("set user configuration option in the format:\n"
-                       "                             "
-                       "    FILE:SECTION:OPTION=[VALUE]\n"
-                       "                             "
-                       "For example:\n"
-                       "                             "
-                       "    servers:global:http-library=serf")},
-    {0,                  0,   0, 0}
+                      N_("set user configuration option in the format:\n"
+                         "                             "
+                         "    FILE:SECTION:OPTION=[VALUE]\n"
+                         "                             "
+                         "For example:\n"
+                         "                             "
+                         "    servers:global:http-library=serf")},
+    {0, 0, 0, 0}
   };
 
 /* Baton for the RA replay session. */
@@ -110,14 +154,19 @@ struct replay_baton {
   svn_boolean_t quiet;
 };
 
-typedef struct {
+/* Option set */
+typedef struct opt_baton_t {
   svn_ra_session_t *session;
   const char *url;
-  svn_revnum_t start_revision;
-  svn_revnum_t end_revision;
+  svn_opt_revision_t start_revision;
+  svn_opt_revision_t end_revision;
   svn_boolean_t quiet;
+  svn_boolean_t incremental;
 } opt_baton_t;
 
+/* Print dumpstream-formatted information about REVISION.
+ * Implements the `svn_ra_replay_revstart_callback_t' interface.
+ */
 static svn_error_t *
 replay_revstart(svn_revnum_t revision,
                 void *replay_baton,
@@ -131,7 +180,7 @@ replay_revstart(svn_revnum_t revision,
   svn_stream_t *stdout_stream;
   svn_stream_t *revprop_stream;
 
-  svn_stream_for_stdout(&stdout_stream, pool);
+  SVN_ERR(svn_stream_for_stdout(&stdout_stream, pool));
 
   /* Revision-number: 19 */
   SVN_ERR(svn_stream_printf(stdout_stream, pool,
@@ -168,6 +217,8 @@ replay_revstart(svn_revnum_t revision,
   return SVN_NO_ERROR;
 }
 
+/* Print progress information about the dump of REVISION.
+   Implements the `svn_ra_replay_revfinish_callback_t' interface. */
 static svn_error_t *
 replay_revend(svn_revnum_t revision,
               void *replay_baton,
@@ -179,15 +230,17 @@ replay_revend(svn_revnum_t revision,
   /* No resources left to free. */
   struct replay_baton *rb = replay_baton;
   if (! rb->quiet)
-    svn_cmdline_fprintf(stderr, pool, "* Dumped revision %lu.\n", revision);
+    SVN_ERR(svn_cmdline_fprintf(stderr, pool, "* Dumped revision %lu.\n",
+                                revision));
   return SVN_NO_ERROR;
 }
 
-/* Return in *SESSION a new RA session to URL.
- * Allocate *SESSION and related data structures in POOL.
- * Use CONFIG_DIR and pass USERNAME, PASSWORD, CONFIG_DIR and
- * NO_AUTH_CACHE to initialize the authorization baton.
- * CONFIG_OPTIONS (if not NULL) is a list of configuration overrides. */
+/* Set *SESSION to a new RA session opened to URL.  Allocate *SESSION
+ * and related data structures in POOL.  Use CONFIG_DIR and pass
+ * USERNAME, PASSWORD, CONFIG_DIR and NO_AUTH_CACHE to initialize the
+ * authorization baton.  CONFIG_OPTIONS (if not NULL) is a list of
+ * configuration overrides.
+ */
 static svn_error_t *
 open_connection(svn_ra_session_t **session,
                 const char *url,
@@ -216,6 +269,9 @@ open_connection(svn_ra_session_t **sessi
   cfg_config = apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG,
                             APR_HASH_KEY_STRING);
 
+  /* Set up our cancellation support. */
+  ctx->cancel_func = check_cancel;
+
   /* Default authentication providers for non-interactive use */
   SVN_ERR(svn_cmdline_create_auth_baton(&(ctx->auth_baton), non_interactive,
                                         username, password, config_dir,
@@ -226,10 +282,63 @@ open_connection(svn_ra_session_t **sessi
   return SVN_NO_ERROR;
 }
 
+/* Print a revision record header for REVISION to STDOUT_STREAM.  Use
+ * SESSION to contact the repository for revision properties and
+ * such.
+ */
 static svn_error_t *
-replay_revisions(svn_ra_session_t *session, const char *url,
-                 svn_revnum_t start_revision, svn_revnum_t end_revision,
-                 svn_boolean_t quiet, apr_pool_t *pool)
+dump_revision_header(svn_ra_session_t *session,
+                     svn_stream_t *stdout_stream, 
+                     svn_revnum_t revision,
+                     apr_pool_t *pool)
+{
+  apr_hash_t *prophash;
+  svn_stringbuf_t *propstring;
+  svn_stream_t *propstream;
+
+  SVN_ERR(svn_stream_printf(stdout_stream, pool,
+                            SVN_REPOS_DUMPFILE_REVISION_NUMBER
+                            ": %ld\n", revision));
+
+  prophash = apr_hash_make(pool);
+  propstring = svn_stringbuf_create("", pool);
+  SVN_ERR(svn_ra_rev_proplist(session, revision, &prophash, pool));
+
+  propstream = svn_stream_from_stringbuf(propstring, pool);
+  SVN_ERR(svn_hash_write2(prophash, propstream, "PROPS-END", pool));
+  SVN_ERR(svn_stream_close(propstream));
+
+  /* Property-content-length: 14; Content-length: 14 */
+  SVN_ERR(svn_stream_printf(stdout_stream, pool,
+                            SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH
+                            ": %" APR_SIZE_T_FMT "\n",
+                            propstring->len));
+  SVN_ERR(svn_stream_printf(stdout_stream, pool,
+                            SVN_REPOS_DUMPFILE_CONTENT_LENGTH
+                            ": %" APR_SIZE_T_FMT "\n\n",
+                            propstring->len));
+  /* The properties */
+  SVN_ERR(svn_stream_write(stdout_stream, propstring->data,
+                           &(propstring->len)));
+  SVN_ERR(svn_stream_printf(stdout_stream, pool, "\n"));
+
+  return SVN_NO_ERROR;
+}
+
+/* Replay revisions START_REVISION thru END_REVISION (inclusive) of
+ * the repository located at URL, using callbacks which generate
+ * Subversion repository dumpstreams describing the changes made in
+ * those revisions.  If QUIET is set, don't generate progress
+ * messages.
+ */
+static svn_error_t *
+replay_revisions(svn_ra_session_t *session,
+                 const char *url,
+                 svn_revnum_t start_revision,
+                 svn_revnum_t end_revision,
+                 svn_boolean_t quiet,
+                 svn_boolean_t incremental,
+                 apr_pool_t *pool)
 {
   const svn_delta_editor_t *dump_editor;
   struct replay_baton *replay_baton;
@@ -239,7 +348,8 @@ replay_revisions(svn_ra_session_t *sessi
 
   SVN_ERR(svn_stream_for_stdout(&stdout_stream, pool));
 
-  SVN_ERR(get_dump_editor(&dump_editor, &dump_baton, stdout_stream, pool));
+  SVN_ERR(get_dump_editor(&dump_editor, &dump_baton, stdout_stream, 
+                          check_cancel, NULL, pool));
 
   replay_baton = apr_pcalloc(pool, sizeof(*replay_baton));
   replay_baton->editor = dump_editor;
@@ -257,52 +367,75 @@ replay_revisions(svn_ra_session_t *sessi
   /* Fake revision 0 if necessary */
   if (start_revision == 0)
     {
-      apr_hash_t *prophash;
-      svn_stringbuf_t *propstring;
-      svn_stream_t *propstream;
-      SVN_ERR(svn_stream_printf(stdout_stream, pool,
-                                SVN_REPOS_DUMPFILE_REVISION_NUMBER
-                                ": %ld\n", start_revision));
-
-      prophash = apr_hash_make(pool);
-      propstring = svn_stringbuf_create("", pool);
-
-      SVN_ERR(svn_ra_rev_proplist(session, start_revision,
-                                  &prophash, pool));
-
-      propstream = svn_stream_from_stringbuf(propstring, pool);
-      SVN_ERR(svn_hash_write2(prophash, propstream, "PROPS-END", pool));
-      SVN_ERR(svn_stream_close(propstream));
-
-      /* Property-content-length: 14; Content-length: 14 */
-      SVN_ERR(svn_stream_printf(stdout_stream, pool,
-                                SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH
-                                ": %" APR_SIZE_T_FMT "\n",
-                                propstring->len));
-      SVN_ERR(svn_stream_printf(stdout_stream, pool,
-                                SVN_REPOS_DUMPFILE_CONTENT_LENGTH
-                                ": %" APR_SIZE_T_FMT "\n\n",
-                                propstring->len));
-      /* The properties */
-      SVN_ERR(svn_stream_write(stdout_stream, propstring->data,
-                               &(propstring->len)));
-      SVN_ERR(svn_stream_printf(stdout_stream, pool, "\n"));
+      SVN_ERR(dump_revision_header(session, stdout_stream,
+                                   start_revision, pool));
+
+      /* Revision 0 has no tree changes, so we're done. */
       if (! quiet)
-        svn_cmdline_fprintf(stderr, pool, "* Dumped revision %lu.\n", start_revision);
+        SVN_ERR(svn_cmdline_fprintf(stderr, pool, "* Dumped revision %lu.\n",
+                                    start_revision));
+      start_revision++;
 
+      /* If our first revision is 0, we can treat this as an
+         incremental dump. */
+      incremental = TRUE;
+    }
+
+  if (incremental)
+    {
+      SVN_ERR(svn_ra_replay_range(session, start_revision, end_revision,
+                                  0, TRUE, replay_revstart, replay_revend,
+                                  replay_baton, pool));
+    }
+  else
+    {
+      const svn_ra_reporter3_t *reporter;
+      void *report_baton;
+
+      /* First, we need to dump the start_revision in full.  We'll
+         start with a revision record header. */
+      SVN_ERR(dump_revision_header(session, stdout_stream,
+                                   start_revision, pool));
+
+      /* Then, we'll drive the dump editor with what would look like a
+         full checkout of the repository as it looked in
+         START_REVISION.  We do this by manufacturing a basic 'report'
+         to the update reporter, telling it that we have nothing to
+         start with.  The delta between nothing and everything-at-REV
+         is, effectively, a full dump of REV. */
+      SVN_ERR(svn_ra_do_update2(session, &reporter, &report_baton,
+                                start_revision, "", svn_depth_infinity,
+                                FALSE, dump_editor, dump_baton, pool));
+      SVN_ERR(reporter->set_path(report_baton, "", start_revision,
+                                 svn_depth_infinity, TRUE, NULL, pool));
+      SVN_ERR(reporter->finish_report(report_baton, pool));
+      
+      /* All finished with START_REVISION! */
+      if (! quiet)
+        SVN_ERR(svn_cmdline_fprintf(stderr, pool, "* Dumped revision %lu.\n",
+                                    start_revision));
       start_revision++;
+
+      /* Now go pick up additional revisions in the range, if any. */
+      if (start_revision <= end_revision)
+        SVN_ERR(svn_ra_replay_range(session, start_revision, end_revision,
+                                    0, TRUE, replay_revstart, replay_revend,
+                                    replay_baton, pool));
     }
 
-  SVN_ERR(svn_ra_replay_range(session, start_revision, end_revision,
-                              0, TRUE, replay_revstart, replay_revend,
-                              replay_baton, pool));
   SVN_ERR(svn_stream_close(stdout_stream));
   return SVN_NO_ERROR;
 }
 
+/* Read a dumpstream from stdin, and use it to feed a loader capable
+ * of transmitting that information to the repository located at URL
+ * (to which SESSION has been opened).
+ */
 static svn_error_t *
-load_revisions(svn_ra_session_t *session, const char *url,
-               svn_boolean_t quiet, apr_pool_t *pool)
+load_revisions(svn_ra_session_t *session,
+               const char *url,
+               svn_boolean_t quiet,
+               apr_pool_t *pool)
 {
   apr_file_t *stdin_file;
   svn_stream_t *stdin_stream;
@@ -313,113 +446,203 @@ load_revisions(svn_ra_session_t *session
   stdin_stream = svn_stream_from_aprfile2(stdin_file, FALSE, pool);
 
   SVN_ERR(get_dumpstream_loader(&parser, &parse_baton, session, pool));
-  SVN_ERR(drive_dumpstream_loader(stdin_stream, parser, parse_baton, session, pool));
+  SVN_ERR(drive_dumpstream_loader(stdin_stream, parser, parse_baton,
+                                  session, check_cancel, NULL, pool));
 
-  svn_stream_close(stdin_stream);
+  SVN_ERR(svn_stream_close(stdin_stream));
 
   return SVN_NO_ERROR;
 }
 
-
+/* Return a program name for this program, the basename of the path
+ * represented by PROGNAME if not NULL; use "svnrdump" otherwise.
+ */
 static const char *
-ensure_appname(const char *progname, apr_pool_t *pool)
+ensure_appname(const char *progname,
+               apr_pool_t *pool)
 {
   if (!progname)
     return "svnrdump";
-  
-  progname = svn_dirent_internal_style(progname, pool);
-  return svn_dirent_basename(progname, NULL);
+
+  return svn_dirent_basename(svn_dirent_internal_style(progname, pool), NULL);
 }
 
+/* Print a simple usage string. */
 static svn_error_t *
-usage(const char *progname, apr_pool_t *pool)
+usage(const char *progname,
+      apr_pool_t *pool)
 {
-  progname = ensure_appname(progname, pool);
-
-  SVN_ERR(svn_cmdline_fprintf(stderr, pool,
-                              _("Type '%s help' for usage.\n"),
-                              progname));
-  return SVN_NO_ERROR;
+  return svn_cmdline_fprintf(stderr, pool,
+                             _("Type '%s help' for usage.\n"),
+                             ensure_appname(progname, pool));
 }
 
+/* Print information about the version of this program and dependent
+ * modules.
+ */
 static svn_error_t *
-version(const char *progname, apr_pool_t *pool)
+version(const char *progname,
+        apr_pool_t *pool)
 {
-  const char *ra_desc_start
-    = _("The following repository access (RA) modules are available:\n\n");
-
-  svn_stringbuf_t *version_footer = svn_stringbuf_create(ra_desc_start,
-                                                         pool);
+  svn_stringbuf_t *version_footer = 
+    svn_stringbuf_create(_("The following repository access (RA) modules "
+                           "are available:\n\n"),
+                         pool);
 
   SVN_ERR(svn_ra_print_modules(version_footer, pool));
-
-  progname = ensure_appname(progname, pool);
-
-  return svn_opt_print_help3(NULL, progname, TRUE, FALSE,
-                             version_footer->data, NULL, NULL,
-                             NULL, NULL, NULL, pool);
+  return svn_opt_print_help3(NULL, ensure_appname(progname, pool),
+                             TRUE, FALSE, version_footer->data,
+                             NULL, NULL, NULL, NULL, NULL, pool);
 }
 
 
-/** A statement macro, similar to @c SVN_ERR, but returns an integer.
- *
+/* A statement macro, similar to @c SVN_ERR, but returns an integer.
  * Evaluate @a expr. If it yields an error, handle that error and
  * return @c EXIT_FAILURE.
  */
-#define SVNRDUMP_ERR(expr)                                              \
-  do                                                                    \
-    {                                                                   \
-      svn_error_t *svn_err__temp = (expr);                              \
-      if (svn_err__temp)                                                \
-        {                                                               \
+#define SVNRDUMP_ERR(expr)                                               \
+  do                                                                     \
+    {                                                                    \
+      svn_error_t *svn_err__temp = (expr);                               \
+      if (svn_err__temp)                                                 \
+        {                                                                \
           svn_handle_error2(svn_err__temp, stderr, FALSE, "svnrdump: "); \
-          svn_error_clear(svn_err__temp);                               \
-          return EXIT_FAILURE;                                          \
-        }                                                               \
-    }                                                                   \
+          svn_error_clear(svn_err__temp);                                \
+          return EXIT_FAILURE;                                           \
+        }                                                                \
+    }                                                                    \
   while (0)
 
+/* Handle the "dump" subcommand.  Implements `svn_opt_subcommand_t'.  */
 static svn_error_t *
-dump_cmd(apr_getopt_t *os, void *baton, apr_pool_t *pool)
+dump_cmd(apr_getopt_t *os,
+         void *baton,
+         apr_pool_t *pool)
 {
   opt_baton_t *opt_baton = baton;
-  SVN_ERR(replay_revisions(opt_baton->session, opt_baton->url,
-                           opt_baton->start_revision, opt_baton->end_revision,
-                           opt_baton->quiet, pool));
-  return SVN_NO_ERROR;
+  return replay_revisions(opt_baton->session, opt_baton->url,
+                          opt_baton->start_revision.value.number,
+                          opt_baton->end_revision.value.number,
+                          opt_baton->quiet, opt_baton->incremental, pool);
 }
 
+/* Handle the "load" subcommand.  Implements `svn_opt_subcommand_t'.  */
 static svn_error_t *
-load_cmd(apr_getopt_t *os, void *baton, apr_pool_t *pool)
+load_cmd(apr_getopt_t *os,
+         void *baton,
+         apr_pool_t *pool)
 {
   opt_baton_t *opt_baton = baton;
-  SVN_ERR(load_revisions(opt_baton->session, opt_baton->url,
-                         opt_baton->quiet, pool));  
-  return SVN_NO_ERROR;
+  return load_revisions(opt_baton->session, opt_baton->url,
+                        opt_baton->quiet, pool);
 }
 
+/* Handle the "help" subcommand.  Implements `svn_opt_subcommand_t'.  */
 static svn_error_t *
-help_cmd(apr_getopt_t *os, void *baton, apr_pool_t *pool)
+help_cmd(apr_getopt_t *os,
+         void *baton,
+         apr_pool_t *pool)
 {
   const char *header =
     _("general usage: svnrdump SUBCOMMAND URL [-r LOWER[:UPPER]]\n"
-      "Type 'svnrdump help <subcommand>' for help on a specific subcommand.\n\n"
+      "Type 'svnrdump help <subcommand>' for help on a specific subcommand.\n"
+      "\n"
       "Available subcommands:\n");
 
-  SVN_ERR(svn_opt_print_help3(os, "svnrdump", FALSE, FALSE, NULL, header,
-                              svnrdump__cmd_table, svnrdump__options, NULL,
-                              NULL, pool));
+  return svn_opt_print_help3(os, "svnrdump", FALSE, FALSE, NULL, header,
+                             svnrdump__cmd_table, svnrdump__options, NULL,
+                             NULL, pool);
+}
+
+/* Examine the OPT_BATON's 'start_revision' and 'end_revision'
+ * members, making sure that they make sense (in general, and as
+ * applied to a repository whose current youngest revision is
+ * LATEST_REVISION).
+ */
+static svn_error_t *
+validate_and_resolve_revisions(opt_baton_t *opt_baton,
+                               svn_revnum_t latest_revision,
+                               apr_pool_t *pool)
+{
+  svn_revnum_t provided_start_rev = SVN_INVALID_REVNUM;
+
+  /* Ensure that the start revision is something we can handle.  We
+     want a number >= 0.  If unspecified, make it a number (r0) --
+     anything else is bogus.  */
+  if (opt_baton->start_revision.kind == svn_opt_revision_number)
+    {
+      provided_start_rev = opt_baton->start_revision.value.number;
+    }
+  else if (opt_baton->start_revision.kind == svn_opt_revision_unspecified)
+    {
+      opt_baton->start_revision.kind = svn_opt_revision_number;
+      opt_baton->start_revision.value.number = 0;
+    }
+
+  if (opt_baton->start_revision.kind != svn_opt_revision_number)
+    {
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("Unsupported revision specifier used; use "
+                                "only integer values or 'HEAD'"));
+    }
+
+  if ((opt_baton->start_revision.value.number < 0) ||
+      (opt_baton->start_revision.value.number > latest_revision))
+    {
+      return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                               _("Revision '%ld' does not exist"),
+                               opt_baton->start_revision.value.number);
+    }
+
+  /* Ensure that the end revision is something we can handle.  We want
+     a number <= the youngest, and > the start revision.  If
+     unspecified, make it a number (start_revision + 1 if that was
+     specified, the youngest revision in the repository otherwise) --
+     anything else is bogus.  */
+  if (opt_baton->end_revision.kind == svn_opt_revision_unspecified)
+    {
+      opt_baton->end_revision.kind = svn_opt_revision_number;
+      if (SVN_IS_VALID_REVNUM(provided_start_rev))
+        opt_baton->end_revision.value.number = provided_start_rev;
+      else
+        opt_baton->end_revision.value.number = latest_revision;
+    }
+
+  if (opt_baton->end_revision.kind != svn_opt_revision_number)
+    {
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("Unsupported revision specifier used; use "
+                                "only integer values or 'HEAD'"));
+    }
+
+  if ((opt_baton->end_revision.value.number < 0) ||
+      (opt_baton->end_revision.value.number > latest_revision))
+    {
+      return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                               _("Revision '%ld' does not exist"),
+                               opt_baton->end_revision.value.number);
+    }
 
+  /* Finally, make sure that the end revision is younger than the
+     start revision.  We don't do "backwards" 'round here.  */
+  if (opt_baton->end_revision.value.number < 
+      opt_baton->start_revision.value.number)
+    {
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("LOWER revision cannot be greater than "
+                                "UPPER revision; consider reversing your "
+                                "revision range"));
+    }
   return SVN_NO_ERROR;
 }
 
 int
 main(int argc, const char **argv)
 {
+  svn_error_t *err = SVN_NO_ERROR;
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
   opt_baton_t *opt_baton;
-  char *revision_cut = NULL;
-  svn_revnum_t latest_revision = svn_opt_revision_unspecified;
+  svn_revnum_t latest_revision = SVN_INVALID_REVNUM;
   apr_pool_t *pool = NULL;
   const char *config_dir = NULL;
   const char *username = NULL;
@@ -429,20 +652,47 @@ main(int argc, const char **argv)
   apr_array_header_t *config_options = NULL;
   apr_getopt_t *os;
   const char *first_arg;
+  apr_array_header_t *received_opts;
+  int i;
 
   if (svn_cmdline_init ("svnrdump", stderr) != EXIT_SUCCESS)
     return EXIT_FAILURE;
 
   pool = svn_pool_create(NULL);
   opt_baton = apr_pcalloc(pool, sizeof(*opt_baton));
-  opt_baton->start_revision = svn_opt_revision_unspecified;
-  opt_baton->end_revision = svn_opt_revision_unspecified;
+  opt_baton->start_revision.kind = svn_opt_revision_unspecified;
+  opt_baton->end_revision.kind = svn_opt_revision_unspecified;
   opt_baton->url = NULL;
 
   SVNRDUMP_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
 
   os->interleave = TRUE; /* Options and arguments can be interleaved */
 
+  /* Set up our cancellation support. */
+  apr_signal(SIGINT, signal_handler);
+#ifdef SIGBREAK
+  /* SIGBREAK is a Win32 specific signal generated by ctrl-break. */
+  apr_signal(SIGBREAK, signal_handler);
+#endif
+#ifdef SIGHUP
+  apr_signal(SIGHUP, signal_handler);
+#endif
+#ifdef SIGTERM
+  apr_signal(SIGTERM, signal_handler);
+#endif
+#ifdef SIGPIPE
+  /* Disable SIGPIPE generation for the platforms that have it. */
+  apr_signal(SIGPIPE, SIG_IGN);
+#endif
+#ifdef SIGXFSZ
+  /* Disable SIGXFSZ generation for the platforms that have it, otherwise
+   * working with large files when compiled against an APR that doesn't have
+   * large file support will crash the program, which is uncool. */
+  apr_signal(SIGXFSZ, SIG_IGN);
+#endif
+
+  received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));
+
   while (1)
     {
       int opt;
@@ -458,22 +708,34 @@ main(int argc, const char **argv)
           exit(EXIT_FAILURE);
         }
 
+      /* Stash the option code in an array before parsing it. */
+      APR_ARRAY_PUSH(received_opts, int) = opt;
+
       switch(opt)
         {
         case 'r':
           {
-            revision_cut = strchr(opt_arg, ':');
-            if (revision_cut)
+            /* Make sure we've not seen -r already. */
+            if (opt_baton->start_revision.kind != svn_opt_revision_unspecified)
               {
-                opt_baton->start_revision = (svn_revnum_t)strtoul(opt_arg,
-                                                                  &revision_cut, 10);
-                opt_baton->end_revision = (svn_revnum_t)strtoul(revision_cut + 1,
-                                                                NULL, 10);
+                err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                       _("Multiple revision arguments "
+                                         "encountered; try '-r N:M' instead "
+                                         "of '-r N -r M'"));
+                return svn_cmdline_handle_exit_error(err, pool, "svnrdump: ");
               }
-            else
+            /* Parse the -r argument. */
+            if (svn_opt_parse_revision(&(opt_baton->start_revision),
+                                       &(opt_baton->end_revision),
+                                       opt_arg, pool) != 0)
               {
-                opt_baton->start_revision = (svn_revnum_t)strtoul(opt_arg, NULL, 10);
-                opt_baton->end_revision = opt_baton->start_revision;
+                const char *utf8_opt_arg;
+                err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
+                if (! err)
+                  err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                          _("Syntax error in revision "
+                                            "argument '%s'"), utf8_opt_arg);
+                return svn_cmdline_handle_exit_error(err, pool, "svnrdump: ");
               }
           }
           break;
@@ -503,6 +765,9 @@ main(int argc, const char **argv)
         case opt_non_interactive:
           non_interactive = TRUE;
           break;
+        case opt_incremental:
+          opt_baton->incremental = TRUE;
+          break;
         case opt_config_option:
           if (!config_options)
               config_options =
@@ -517,9 +782,8 @@ main(int argc, const char **argv)
 
   if (os->ind >= os->argc)
     {
-      svn_error_clear
-                (svn_cmdline_fprintf(stderr, pool,
-                                     _("Subcommand argument required\n")));
+      svn_error_clear(svn_cmdline_fprintf(stderr, pool,
+                                          _("Subcommand argument required\n")));
       SVNRDUMP_ERR(help_cmd(NULL, NULL, pool));
       svn_pool_destroy(pool);
       exit(EXIT_FAILURE);
@@ -533,8 +797,7 @@ main(int argc, const char **argv)
   if (subcommand == NULL)
     {
       const char *first_arg_utf8;
-      svn_error_t *err = svn_utf_cstring_to_utf8(&first_arg_utf8,
-                                                 first_arg, pool);
+      err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg, pool);
       if (err)
         return svn_cmdline_handle_exit_error(err, pool, "svnrdump: ");
       svn_error_clear(svn_cmdline_fprintf(stderr, pool,
@@ -545,6 +808,39 @@ main(int argc, const char **argv)
       exit(EXIT_FAILURE);
     }
 
+  /* Check that the subcommand wasn't passed any inappropriate options. */
+  for (i = 0; i < received_opts->nelts; i++)
+    {
+      int opt_id = APR_ARRAY_IDX(received_opts, i, int);
+
+      /* All commands implicitly accept --help, so just skip over this
+         when we see it. Note that we don't want to include this option
+         in their "accepted options" list because it would be awfully
+         redundant to display it in every commands' help text. */
+      if (opt_id == 'h' || opt_id == '?')
+        continue;
+
+      if (! svn_opt_subcommand_takes_option3(subcommand, opt_id, NULL))
+        {
+          const char *optstr;
+          const apr_getopt_option_t *badopt =
+            svn_opt_get_option_from_code2(opt_id, svnrdump__options,
+                                          subcommand, pool);
+          svn_opt_format_option(&optstr, badopt, FALSE, pool);
+          if (subcommand->name[0] == '-')
+            SVN_INT_ERR(help_cmd(NULL, NULL, pool));
+          else
+            svn_error_clear
+              (svn_cmdline_fprintf
+               (stderr, pool,
+                _("Subcommand '%s' doesn't accept option '%s'\n"
+                  "Type 'svnrdump help %s' for usage.\n"),
+                subcommand->name, optstr, subcommand->name));
+          svn_pool_destroy(pool);
+          return EXIT_FAILURE;
+        }
+    }
+
   if (subcommand && strcmp(subcommand->name, "help") == 0)
     {
       SVNRDUMP_ERR(help_cmd(os, opt_baton, pool));
@@ -559,7 +855,8 @@ main(int argc, const char **argv)
       exit(EXIT_FAILURE);
     }
 
-  SVNRDUMP_ERR(svn_utf_cstring_to_utf8(&(opt_baton->url), os->argv[os->ind], pool));
+  SVNRDUMP_ERR(svn_utf_cstring_to_utf8(&(opt_baton->url),
+                                       os->argv[os->ind], pool));
 
   opt_baton->url = svn_uri_canonicalize(os->argv[os->ind], pool);
 
@@ -573,31 +870,19 @@ main(int argc, const char **argv)
                                config_options,
                                pool));
 
-  /* Have sane opt_baton->start_revision and end_revision defaults if unspecified */
-  SVNRDUMP_ERR(svn_ra_get_latest_revnum(opt_baton->session, &latest_revision, pool));
-  if (opt_baton->start_revision == svn_opt_revision_unspecified)
-    opt_baton->start_revision = 0;
-  if (opt_baton->end_revision == svn_opt_revision_unspecified)
-    opt_baton->end_revision = latest_revision;
-  if (opt_baton->end_revision > latest_revision)
-    {
-      SVN_INT_ERR(svn_cmdline_fprintf(stderr, pool,
-                                      _("Revision %ld does not exist.\n"),
-                                      opt_baton->end_revision));
-      exit(EXIT_FAILURE);
-    }
-  if (opt_baton->end_revision < opt_baton->start_revision)
-    {
-      SVN_INT_ERR(svn_cmdline_fprintf(stderr, pool,
-                                      _("LOWER cannot be greater "
-                                        "than UPPER.\n")));
-      exit(EXIT_FAILURE);
-    }
+  /* Have sane opt_baton->start_revision and end_revision defaults if
+     unspecified.  */
+  SVNRDUMP_ERR(svn_ra_get_latest_revnum(opt_baton->session,
+                                        &latest_revision, pool));
+
+  /* Make sure any provided revisions make sense. */
+  SVNRDUMP_ERR(validate_and_resolve_revisions(opt_baton, 
+                                              latest_revision, pool));
 
   /* Dispatch the subcommand */
   SVNRDUMP_ERR((*subcommand->cmd_func)(os, opt_baton, pool));
 
   svn_pool_destroy(pool);
 
-  return 0;
+  return EXIT_SUCCESS;
 }

Modified: subversion/branches/ignore-mergeinfo/subversion/svnserve/cyrus_auth.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnserve/cyrus_auth.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnserve/cyrus_auth.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnserve/cyrus_auth.c Sat Dec 11 00:15:55 2010
@@ -360,8 +360,10 @@ svn_error_t *cyrus_auth_request(svn_ra_s
         return fail_cmd(conn, pool, sasl_ctx);
 
       if ((p = strchr(user, '@')) != NULL)
-        /* Drop the realm part. */
-        b->user = apr_pstrndup(b->pool, user, p - (const char *)user);
+        {
+          /* Drop the realm part. */
+          b->user = apr_pstrndup(b->pool, user, p - (const char *)user);
+        }
       else
         {
           svn_error_t *err;

Modified: subversion/branches/ignore-mergeinfo/subversion/svnserve/main.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnserve/main.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnserve/main.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnserve/main.c Sat Dec 11 00:15:55 2010
@@ -372,6 +372,7 @@ int main(int argc, const char *argv[])
   apr_sockaddr_t *sa;
   apr_pool_t *pool;
   apr_pool_t *connection_pool;
+  apr_allocator_t *allocator;
   svn_error_t *err;
   apr_getopt_t *os;
   int opt;
@@ -431,6 +432,7 @@ int main(int argc, const char *argv[])
   params.pwdb = NULL;
   params.authzdb = NULL;
   params.log_file = NULL;
+  params.username_case = CASE_ASIS;
 
   while (1)
     {
@@ -592,11 +594,11 @@ int main(int argc, const char *argv[])
   /* If a configuration file is specified, load it and any referenced
    * password and authorization files. */
   if (config_filename)
-      SVN_INT_ERR(load_configs(&params.cfg, &params.pwdb, &params.authzdb,
-                               config_filename, TRUE,
-                               svn_dirent_dirname(config_filename, pool),
-                               NULL, NULL, /* server baton, conn */
-                               pool));
+    SVN_INT_ERR(load_configs(&params.cfg, &params.pwdb, &params.authzdb,
+                             &params.username_case, config_filename, TRUE,
+                             svn_dirent_dirname(config_filename, pool),
+                             NULL, NULL, /* server baton, conn */
+                             pool));
 
   if (log_filename)
     SVN_INT_ERR(svn_io_file_open(&params.log_file, log_filename,
@@ -793,10 +795,22 @@ int main(int argc, const char *argv[])
         return ERROR_SUCCESS;
 #endif
 
+      /* If we are using fulltext caches etc. we will allocate many large
+         chunks of memory of various sizes outside the cache for those
+         fulltexts. Make sure we use the memory wisely: use an allocator
+         that causes memory fragments to be given back to the OS early. */
+
+      if (apr_allocator_create(&allocator))
+        return EXIT_FAILURE;
+
+      apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
+
       /* Non-standard pool handling.  The main thread never blocks to join
          the connection threads so it cannot clean up after each one.  So
-         separate pools, that can be cleared at thread exit, are used */
-      connection_pool = svn_pool_create(NULL);
+         separate pools that can be cleared at thread exit are used. */
+
+      connection_pool = svn_pool_create_ex(NULL, allocator);
+      apr_allocator_owner_set(allocator, connection_pool);
 
       status = apr_socket_accept(&usock, sock, connection_pool);
       if (handling_mode == connection_mode_fork)

Modified: subversion/branches/ignore-mergeinfo/subversion/svnserve/serve.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnserve/serve.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnserve/serve.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnserve/serve.c Sat Dec 11 00:15:55 2010
@@ -223,6 +223,7 @@ static svn_error_t *log_command(server_b
 svn_error_t *load_configs(svn_config_t **cfg,
                           svn_config_t **pwdb,
                           svn_authz_t **authzdb,
+                          enum username_case_type *username_case,
                           const char *filename,
                           svn_boolean_t must_exist,
                           const char *base,
@@ -286,6 +287,8 @@ svn_error_t *load_configs(svn_config_t *
                  SVN_CONFIG_OPTION_AUTHZ_DB, NULL);
   if (authzdb_path)
     {
+      const char *case_force_val;
+
       authzdb_path = svn_dirent_join(base, authzdb_path, pool);
       err = svn_repos_authz_read(authzdb, authzdb_path, TRUE, pool);
       if (err)
@@ -304,10 +307,25 @@ svn_error_t *load_configs(svn_config_t *
              * will go to standard error for the admin to see. */
             return err;
         }
+      
+      /* Are we going to be case-normalizing usernames when we consult
+       * this authz file? */
+      svn_config_get(*cfg, &case_force_val, SVN_CONFIG_SECTION_GENERAL,
+                     SVN_CONFIG_OPTION_FORCE_USERNAME_CASE, NULL);
+      if (case_force_val)
+        {
+          if (strcmp(case_force_val, "upper") == 0)
+            *username_case = CASE_FORCE_UPPER;
+          else if (strcmp(case_force_val, "lower") == 0)
+            *username_case = CASE_FORCE_LOWER;
+          else
+            *username_case = CASE_ASIS;
+        }
     }
   else
     {
       *authzdb = NULL;
+      *username_case = CASE_ASIS;
     }
 
   return SVN_NO_ERROR;
@@ -340,6 +358,18 @@ static svn_error_t *get_fs_path(const ch
 
 /* --- AUTHENTICATION AND AUTHORIZATION FUNCTIONS --- */
 
+/* Convert TEXT to upper case if TO_UPPERCASE is TRUE, else
+   converts it to lower case. */
+static void convert_case(char *text, svn_boolean_t to_uppercase)
+{
+  char *c = text;
+  while (*c)
+    {
+      *c = (to_uppercase ? apr_toupper(*c) : apr_tolower(*c));
+      ++c;
+    }
+}
+
 /* Set *ALLOWED to TRUE if PATH is accessible in the REQUIRED mode to
    the user described in BATON according to the authz rules in BATON.
    Use POOL for temporary allocations only.  If no authz rules are
@@ -369,8 +399,20 @@ static svn_error_t *authz_check_access(s
   if (path && *path != '/')
     path = svn_uri_join("/", path, pool);
 
+  /* If we have a username, and we've not yet used it + any username
+     case normalization that might be requested to determine "the
+     username we used for authz purposes", do so now. */
+  if (b->user && (! b->authz_user))
+    {
+      b->authz_user = apr_pstrdup(b->pool, b->user);
+      if (b->username_case == CASE_FORCE_UPPER)
+        convert_case((char *)b->authz_user, TRUE);
+      else if (b->username_case == CASE_FORCE_LOWER)
+        convert_case((char *)b->authz_user, FALSE);
+    }
+
   return svn_repos_authz_check_access(b->authzdb, b->authz_repos_name,
-                                      path, b->user, required,
+                                      path, b->authz_user, required,
                                       allowed, pool);
 }
 
@@ -994,6 +1036,65 @@ static svn_error_t *get_dated_rev(svn_ra
   return SVN_NO_ERROR;
 }
 
+/* Common logic for change_rev_prop() and change_rev_prop2(). */
+static svn_error_t *do_change_rev_prop(svn_ra_svn_conn_t *conn,
+                                       server_baton_t *b,
+                                       svn_revnum_t rev,
+                                       const char *name,
+                                       const svn_string_t *const *old_value_p,
+                                       const svn_string_t *value,
+                                       apr_pool_t *pool)
+{
+  SVN_ERR(must_have_access(conn, pool, b, svn_authz_write, NULL, FALSE));
+  SVN_ERR(log_command(b, conn, pool, "%s",
+                      svn_log__change_rev_prop(rev, name, pool)));
+  SVN_CMD_ERR(svn_repos_fs_change_rev_prop4(b->repos, rev, b->user,
+                                            name, old_value_p, value,
+                                            TRUE, TRUE,
+                                            authz_check_access_cb_func(b), b,
+                                            pool));
+  SVN_ERR(svn_ra_svn_write_cmd_response(conn, pool, ""));
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *change_rev_prop2(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
+                                     apr_array_header_t *params, void *baton)
+{
+  server_baton_t *b = baton;
+  svn_revnum_t rev;
+  const char *name;
+  svn_string_t *value;
+  const svn_string_t *const *old_value_p;
+  svn_string_t *old_value;
+  svn_boolean_t dont_care;
+
+  SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "rc(?s)(b?s)",
+                                 &rev, &name, &value,
+                                 &dont_care, &old_value));
+
+  /* Argument parsing. */
+  if (dont_care)
+    old_value_p = NULL;
+  else
+    old_value_p = (const svn_string_t *const *)&old_value;
+
+  /* Input validation. */
+  if (dont_care && old_value)
+    {
+      svn_error_t *err;
+      err = svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
+                             "'previous-value' and 'dont-care' cannot both be "
+                             "set in 'change-rev-prop2' request");
+      return log_fail_and_flush(err, b, conn, pool);
+    }
+
+  /* Do it. */
+  SVN_ERR(do_change_rev_prop(conn, b, rev, name, old_value_p, value, pool));
+
+  return SVN_NO_ERROR;
+}
+
 static svn_error_t *change_rev_prop(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
                                     apr_array_header_t *params, void *baton)
 {
@@ -1006,14 +1107,8 @@ static svn_error_t *change_rev_prop(svn_
      optional element pattern "(?s)" isn't used. */
   SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "rc?s", &rev, &name, &value));
 
-  SVN_ERR(must_have_access(conn, pool, b, svn_authz_write, NULL, FALSE));
-  SVN_ERR(log_command(b, conn, pool, "%s",
-                      svn_log__change_rev_prop(rev, name, pool)));
-  SVN_CMD_ERR(svn_repos_fs_change_rev_prop3(b->repos, rev, b->user,
-                                            name, value, TRUE, TRUE,
-                                            authz_check_access_cb_func(b), b,
-                                            pool));
-  SVN_ERR(svn_ra_svn_write_cmd_response(conn, pool, ""));
+  SVN_ERR(do_change_rev_prop(conn, b, rev, name, NULL, value, pool));
+
   return SVN_NO_ERROR;
 }
 
@@ -1376,7 +1471,6 @@ static svn_error_t *get_dir(svn_ra_svn_c
   apr_uint64_t dirent_fields;
   apr_array_header_t *dirent_fields_list = NULL;
   svn_ra_svn_item_t *elt;
-  int i;
 
   SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "c(?r)bb?l", &path, &rev,
                                  &want_props, &want_contents,
@@ -1388,6 +1482,8 @@ static svn_error_t *get_dir(svn_ra_svn_c
     }
   else
     {
+      int i;
+
       dirent_fields = 0;
 
       for (i = 0; i < dirent_fields_list->nelts; ++i)
@@ -1742,11 +1838,14 @@ static svn_error_t *get_mergeinfo(svn_ra
   apr_hash_index_t *hi;
   const char *inherit_word;
   svn_mergeinfo_inheritance_t inherit;
+  svn_boolean_t validate_inherited_mergeinfo;
   svn_boolean_t include_descendants;
   apr_pool_t *iterpool;
 
-  SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "l(?r)wb", &paths, &rev,
-                                 &inherit_word, &include_descendants));
+  SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "l(?r)wb?b", &paths, &rev,
+                                 &inherit_word,
+                                 &include_descendants,
+                                 &validate_inherited_mergeinfo));
   inherit = svn_inheritance_from_word(inherit_word);
 
   /* Canonicalize the paths which mergeinfo has been requested for. */
@@ -1772,12 +1871,13 @@ static svn_error_t *get_mergeinfo(svn_ra
                                              pool)));
 
   SVN_ERR(trivial_auth_request(conn, pool, b));
-  SVN_CMD_ERR(svn_repos_fs_get_mergeinfo(&mergeinfo, b->repos,
-                                         canonical_paths, rev,
-                                         inherit,
-                                         include_descendants,
-                                         authz_check_access_cb_func(b), b,
-                                         pool));
+  SVN_CMD_ERR(svn_repos_fs_get_mergeinfo2(&mergeinfo, b->repos,
+                                          canonical_paths, rev,
+                                          inherit,
+                                          validate_inherited_mergeinfo,
+                                          include_descendants,
+                                          authz_check_access_cb_func(b), b,
+                                          pool));
   SVN_ERR(svn_mergeinfo__remove_prefix_from_catalog(&mergeinfo, mergeinfo,
                                                     b->fs_path->data, pool));
   SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "w((!", "success"));
@@ -1795,7 +1895,8 @@ static svn_error_t *get_mergeinfo(svn_ra
                                      mergeinfo_string));
     }
   svn_pool_destroy(iterpool);
-  SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!))"));
+  SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b)",
+    validate_inherited_mergeinfo));
 
   return SVN_NO_ERROR;
 }
@@ -2763,6 +2864,7 @@ static const svn_ra_svn_cmd_entry_t main
   { "get-latest-rev",  get_latest_rev },
   { "get-dated-rev",   get_dated_rev },
   { "change-rev-prop", change_rev_prop },
+  { "change-rev-prop2",change_rev_prop2 },
   { "rev-proplist",    rev_proplist },
   { "rev-prop",        rev_prop },
   { "commit",          commit },
@@ -2907,7 +3009,7 @@ static svn_error_t *find_repos(const cha
   /* If the svnserve configuration files have not been loaded then
      load them from the repository. */
   if (NULL == b->cfg)
-    SVN_ERR(load_configs(&b->cfg, &b->pwdb, &b->authzdb,
+    SVN_ERR(load_configs(&b->cfg, &b->pwdb, &b->authzdb, &b->username_case,
                          svn_repos_svnserve_conf(b->repos, pool), FALSE,
                          svn_repos_conf_dir(b->repos, pool),
                          b, conn,
@@ -2976,6 +3078,8 @@ svn_error_t *serve(svn_ra_svn_conn_t *co
   b.tunnel_user = get_tunnel_user(params, pool);
   b.read_only = params->read_only;
   b.user = NULL;
+  b.username_case = params->username_case;
+  b.authz_user = NULL;
   b.cfg = params->cfg;
   b.pwdb = params->pwdb;
   b.authzdb = params->authzdb;
@@ -2986,7 +3090,8 @@ svn_error_t *serve(svn_ra_svn_conn_t *co
 
   /* Send greeting.  We don't support version 1 any more, so we can
    * send an empty mechlist. */
-  SVN_ERR(svn_ra_svn_write_cmd_response(conn, pool, "nn()(wwwwwww)",
+  /* Server-side capabilities list: */
+  SVN_ERR(svn_ra_svn_write_cmd_response(conn, pool, "nn()(wwwwwwww)",
                                         (apr_uint64_t) 2, (apr_uint64_t) 2,
                                         SVN_RA_SVN_CAP_EDIT_PIPELINE,
                                         SVN_RA_SVN_CAP_SVNDIFF1,
@@ -2994,6 +3099,7 @@ svn_error_t *serve(svn_ra_svn_conn_t *co
                                         SVN_RA_SVN_CAP_COMMIT_REVPROPS,
                                         SVN_RA_SVN_CAP_DEPTH,
                                         SVN_RA_SVN_CAP_LOG_REVPROPS,
+                                        SVN_RA_SVN_CAP_ATOMIC_REVPROPS,
                                         SVN_RA_SVN_CAP_PARTIAL_REPLAY));
 
   /* Read client response, which we assume to be in version 2 format:

Modified: subversion/branches/ignore-mergeinfo/subversion/svnserve/server.h
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnserve/server.h?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnserve/server.h (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnserve/server.h Sat Dec 11 00:15:55 2010
@@ -36,6 +36,8 @@ extern "C" {
 #include "svn_repos.h"
 #include "svn_ra_svn.h"
 
+enum username_case_type { CASE_FORCE_UPPER, CASE_FORCE_LOWER, CASE_ASIS };
+
 typedef struct server_baton_t {
   svn_repos_t *repos;
   const char *repos_name;  /* URI-encoded name of repository (not for authz) */
@@ -47,7 +49,9 @@ typedef struct server_baton_t {
   const char *realm;       /* Authentication realm */
   const char *repos_url;   /* URL to base of repository */
   svn_stringbuf_t *fs_path;/* Decoded base in-repos path (w/ leading slash) */
-  const char *user;
+  const char *user;        /* Authenticated username of the user */
+  enum username_case_type username_case; /* Case-normalize the username? */
+  const char *authz_user;  /* Username for authz ('user' + 'username_case') */
   svn_boolean_t tunnel;    /* Tunneled through login agent */
   const char *tunnel_user; /* Allow EXTERNAL to authenticate as this */
   svn_boolean_t read_only; /* Disallow write access (global flag) */
@@ -101,6 +105,10 @@ typedef struct serve_params_t {
 
   /* A filehandle open for writing logs to; possibly NULL. */
   apr_file_t *log_file;
+
+  /* Username case normalization style. */
+  enum username_case_type username_case;
+
 } serve_params_t;
 
 /* Serve the connection CONN according to the parameters PARAMS. */
@@ -108,11 +116,16 @@ svn_error_t *serve(svn_ra_svn_conn_t *co
                    apr_pool_t *pool);
 
 /* Load a svnserve configuration file located at FILENAME into CFG,
-   any referenced password database into PWDB and any referenced
-   authorization database into AUTHZDB.  If MUST_EXIST is true and
-   FILENAME does not exist, then this returns an error.  BASE may be
-   specified as the base path to any referenced password and
-   authorization files found in FILENAME.
+   and if such as found, then:
+
+    - set *PWDB to any referenced password database,
+    - set *AUTHZDB to any referenced authorization database, and
+    - set *USERNAME_CASE to the enumerated value of the
+      'force-username-case' configuration value (or its default).
+
+   If MUST_EXIST is true and FILENAME does not exist, then return an
+   error.  BASE may be specified as the base path to any referenced
+   password and authorization files found in FILENAME.
 
    If SERVER is not NULL, log the real errors with SERVER and CONN but
    return generic errors to the client.  CONN must not be NULL if SERVER
@@ -120,6 +133,7 @@ svn_error_t *serve(svn_ra_svn_conn_t *co
 svn_error_t *load_configs(svn_config_t **cfg,
                           svn_config_t **pwdb,
                           svn_authz_t **authzdb,
+                          enum username_case_type *username_case,
                           const char *filename,
                           svn_boolean_t must_exist,
                           const char *base,

Modified: subversion/branches/ignore-mergeinfo/subversion/svnsync/main.c
URL: http://svn.apache.org/viewvc/subversion/branches/ignore-mergeinfo/subversion/svnsync/main.c?rev=1044548&r1=1044547&r2=1044548&view=diff
==============================================================================
--- subversion/branches/ignore-mergeinfo/subversion/svnsync/main.c (original)
+++ subversion/branches/ignore-mergeinfo/subversion/svnsync/main.c Sat Dec 11 00:15:55 2010
@@ -284,6 +284,14 @@ check_lib_versions(void)
 }
 
 
+/* Does ERR mean "the current value of the revprop isn't equal to
+   the *OLD_VALUE_P you gave me"?
+ */
+static svn_boolean_t is_atomicity_error(svn_error_t *err)
+{
+  return svn_error_has_cause(err, SVN_ERR_FS_PROP_BASEVALUE_MISMATCH);
+}
+
 /* Remove the lock on SESSION iff the lock is owned by MYLOCKTOKEN. */
 static svn_error_t *
 maybe_unlock(svn_ra_session_t *session,
@@ -291,12 +299,18 @@ maybe_unlock(svn_ra_session_t *session,
              apr_pool_t *scratch_pool)
 {
   svn_string_t *reposlocktoken;
+  svn_boolean_t be_atomic;
+
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                scratch_pool));
 
   SVN_ERR(svn_ra_rev_prop(session, 0, SVNSYNC_PROP_LOCK, &reposlocktoken,
                           scratch_pool));
   if (reposlocktoken && strcmp(reposlocktoken->data, mylocktoken->data) == 0)
-    SVN_ERR(svn_ra_change_rev_prop(session, 0, SVNSYNC_PROP_LOCK, NULL,
-                                   scratch_pool));
+    SVN_ERR(svn_ra_change_rev_prop2(session, 0, SVNSYNC_PROP_LOCK, 
+                                    be_atomic ? &mylocktoken : NULL, NULL,
+                                    scratch_pool));
 
   return SVN_NO_ERROR;
 }
@@ -311,14 +325,36 @@ maybe_unlock(svn_ra_session_t *session,
  * applications to avoid duplication.
  */
 static svn_error_t *
-get_lock(svn_ra_session_t *session, apr_pool_t *pool)
+get_lock(const svn_string_t **lock_string_p,
+         svn_ra_session_t *session,
+         apr_pool_t *pool)
 {
   char hostname_str[APRMAXHOSTLEN + 1] = { 0 };
   svn_string_t *mylocktoken, *reposlocktoken;
   apr_status_t apr_err;
+  svn_boolean_t be_atomic;
   apr_pool_t *subpool;
   int i;
 
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                pool));
+  if (! be_atomic)
+    {
+      /* Pre-1.7 server.  Can't lock without a race condition.
+         See issue #3546.
+       */
+      svn_error_t *err;
+
+      err = svn_error_create(
+              SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+              _("Target server does not support atomic revision property "
+                "edits; consider upgrading it to 1.7 or using an external "
+                "locking program"));
+      svn_handle_warning2(stderr, err, "svnsync: ");
+      svn_error_clear(err);
+    }
+
   apr_err = apr_gethostname(hostname_str, sizeof(hostname_str), pool);
   if (apr_err)
     return svn_error_wrap_apr(apr_err, _("Can't get local hostname"));
@@ -326,6 +362,9 @@ get_lock(svn_ra_session_t *session, apr_
   mylocktoken = svn_string_createf(pool, "%s:%s", hostname_str,
                                    svn_uuid_generate(pool));
 
+  /* If we succeed, this is what the property will be set to. */
+  *lock_string_p = mylocktoken;
+
   subpool = svn_pool_create(pool);
 
 #define SVNSYNC_LOCK_RETRIES 10
@@ -363,9 +402,27 @@ get_lock(svn_ra_session_t *session, apr_
         }
       else if (i < SVNSYNC_LOCK_RETRIES - 1)
         {
+          const svn_string_t *unset = NULL;
+
           /* Except in the very last iteration, try to set the lock. */
-          SVN_ERR(svn_ra_change_rev_prop(session, 0, SVNSYNC_PROP_LOCK,
-                                         mylocktoken, subpool));
+          err = svn_ra_change_rev_prop2(session, 0, SVNSYNC_PROP_LOCK,
+                                        be_atomic ? &unset : NULL,
+                                        mylocktoken, subpool);
+
+          if (be_atomic && err && is_atomicity_error(err))
+            /* Someone else has the lock.  Let's loop. */
+            svn_error_clear(err);
+          else if (be_atomic && err == SVN_NO_ERROR)
+            /* We have the lock. 
+
+               However, for compatibility with concurrent svnsync's that don't
+               support atomicity, loop anyway to double-check that they haven't
+               overwritten our lock.
+             */
+            continue;
+          else
+            /* Genuine error, or we aren't atomic and need to loop. */
+            SVN_ERR(err);
         }
     }
 
@@ -413,12 +470,24 @@ with_locked(svn_ra_session_t *session,
             apr_pool_t *pool)
 {
   svn_error_t *err, *err2;
+  const svn_string_t *lock_string;
+  svn_boolean_t be_atomic;
 
-  SVN_ERR(get_lock(session, pool));
+  SVN_ERR(svn_ra_has_capability(session, &be_atomic,
+                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
+                                pool));
+
+  SVN_ERR(get_lock(&lock_string, session, pool));
 
   err = func(session, baton, pool);
 
-  err2 = svn_ra_change_rev_prop(session, 0, SVNSYNC_PROP_LOCK, NULL, pool);
+  err2 = svn_ra_change_rev_prop2(session, 0, SVNSYNC_PROP_LOCK,
+                                 be_atomic ? &lock_string : NULL, NULL, pool);
+  if (is_atomicity_error(err2))
+    err2 = svn_error_quick_wrap(err2,
+                                _("svnsync's lock was stolen; "
+                                  "can't remove it"));
+
 
   return svn_error_compose_create(err, svn_error_return(err2));
 }
@@ -461,6 +530,8 @@ check_if_session_is_at_repos_root(svn_ra
 /* Remove the properties in TARGET_PROPS but not in SOURCE_PROPS from
  * revision REV of the repository associated with RA session SESSION.
  *
+ * For REV zero, don't remove properties with the "svn:sync-" prefix.
+ * 
  * All allocations will be done in a subpool of POOL.
  */
 static svn_error_t *
@@ -481,10 +552,14 @@ remove_props_not_in_source(svn_ra_sessio
 
       svn_pool_clear(subpool);
 
+      if (rev == 0 && !strncmp(propname, SVNSYNC_PROP_PREFIX,
+                               sizeof(SVNSYNC_PROP_PREFIX) - 1))
+        continue;
+
       /* Delete property if the name can't be found in SOURCE_PROPS. */
       if (! apr_hash_get(source_props, propname, APR_HASH_KEY_STRING))
-        SVN_ERR(svn_ra_change_rev_prop(session, rev, propname, NULL,
-                                       subpool));
+        SVN_ERR(svn_ra_change_rev_prop2(session, rev, propname, NULL,
+                                        NULL, subpool));
     }
 
   svn_pool_destroy(subpool);
@@ -567,8 +642,8 @@ write_revprops(int *filtered_count,
       if (strncmp(propname, SVNSYNC_PROP_PREFIX,
                   sizeof(SVNSYNC_PROP_PREFIX) - 1) != 0)
         {
-          SVN_ERR(svn_ra_change_rev_prop(session, rev, propname, propval,
-                                         subpool));
+          SVN_ERR(svn_ra_change_rev_prop2(session, rev, propname, NULL,
+                                          propval, subpool));
         }
       else
         {
@@ -702,6 +777,11 @@ make_subcommand_baton(opt_baton_t *opt_b
   return b;
 }
 
+static svn_error_t *
+open_target_session(svn_ra_session_t **to_session_p,
+                    subcommand_baton_t *baton,
+                    apr_pool_t *pool);
+
 
 /*** `svnsync init' ***/
 
@@ -775,17 +855,17 @@ do_initialize(svn_ra_session_t *to_sessi
              "repository"));
     }
 
-  SVN_ERR(svn_ra_change_rev_prop(to_session, 0, SVNSYNC_PROP_FROM_URL,
-                                 svn_string_create(baton->from_url, pool),
-                                 pool));
+  SVN_ERR(svn_ra_change_rev_prop2(to_session, 0, SVNSYNC_PROP_FROM_URL, NULL,
+                                  svn_string_create(baton->from_url, pool),
+                                  pool));
 
   SVN_ERR(svn_ra_get_uuid2(from_session, &uuid, pool));
-  SVN_ERR(svn_ra_change_rev_prop(to_session, 0, SVNSYNC_PROP_FROM_UUID,
-                                 svn_string_create(uuid, pool), pool));
+  SVN_ERR(svn_ra_change_rev_prop2(to_session, 0, SVNSYNC_PROP_FROM_UUID, NULL,
+                                  svn_string_create(uuid, pool), pool));
 
-  SVN_ERR(svn_ra_change_rev_prop(to_session, 0, SVNSYNC_PROP_LAST_MERGED_REV,
-                                 svn_string_createf(pool, "%ld", latest),
-                                 pool));
+  SVN_ERR(svn_ra_change_rev_prop2(to_session, 0, SVNSYNC_PROP_LAST_MERGED_REV,
+                                  NULL, svn_string_createf(pool, "%ld", latest),
+                                  pool));
 
   /* Copy all non-svnsync revprops from the LATEST rev in the source
      repository into the destination, notifying about normalized
@@ -841,9 +921,7 @@ initialize_cmd(apr_getopt_t *os, void *b
                              _("Path '%s' is not a URL"), from_url);
 
   baton = make_subcommand_baton(opt_baton, to_url, from_url, 0, 0, pool);
-  SVN_ERR(svn_ra_open4(&to_session, NULL, baton->to_url, NULL,
-                       &(baton->sync_callbacks), baton, baton->config, pool));
-  SVN_ERR(check_if_session_is_at_repos_root(to_session, baton->to_url, pool));
+  SVN_ERR(open_target_session(&to_session, baton, pool));
   if (opt_baton->disable_locking)
     SVN_ERR(do_initialize(to_session, baton, pool));
   else
@@ -923,6 +1001,23 @@ open_source_session(svn_ra_session_t **f
   return SVN_NO_ERROR;
 }
 
+/* Set *TARGET_SESSION_P to an RA session associated with the target
+ * repository of the synchronization.
+ */
+static svn_error_t *
+open_target_session(svn_ra_session_t **target_session_p,
+                    subcommand_baton_t *baton,
+                    apr_pool_t *pool)
+{
+  svn_ra_session_t *target_session;
+  SVN_ERR(svn_ra_open4(&target_session, NULL, baton->to_url, NULL,
+                       &(baton->sync_callbacks), baton, baton->config, pool));
+  SVN_ERR(check_if_session_is_at_repos_root(target_session, baton->to_url, pool));
+
+  *target_session_p = target_session;
+  return SVN_NO_ERROR;
+}
+
 /* Replay baton, used during sychnronization. */
 typedef struct {
   svn_ra_session_t *from_session;
@@ -1029,11 +1124,11 @@ replay_rev_started(svn_revnum_t revision
      NOTE: We have to set this before we start the commit editor,
      because ra_svn doesn't let you change rev props during a
      commit. */
-  SVN_ERR(svn_ra_change_rev_prop(rb->to_session, 0,
-                                 SVNSYNC_PROP_CURRENTLY_COPYING,
-                                 svn_string_createf(pool, "%ld",
-                                                    revision),
-                                 pool));
+  SVN_ERR(svn_ra_change_rev_prop2(rb->to_session, 0,
+                                  SVNSYNC_PROP_CURRENTLY_COPYING,
+                                  NULL,
+                                  svn_string_createf(pool, "%ld", revision),
+                                  pool));
 
   /* The actual copy is just a replay hooked up to a commit.  Include
      all the revision properties from the source repositories, except
@@ -1142,19 +1237,20 @@ replay_rev_finished(svn_revnum_t revisio
   svn_pool_clear(subpool);
 
   /* Ok, we're done, bring the last-merged-rev property up to date. */
-  SVN_ERR(svn_ra_change_rev_prop
-          (rb->to_session,
+  SVN_ERR(svn_ra_change_rev_prop2(
+           rb->to_session,
            0,
            SVNSYNC_PROP_LAST_MERGED_REV,
+           NULL,
            svn_string_create(apr_psprintf(pool, "%ld", revision),
                              subpool),
            subpool));
 
   /* And finally drop the currently copying prop, since we're done
      with this revision. */
-  SVN_ERR(svn_ra_change_rev_prop(rb->to_session, 0,
-                                 SVNSYNC_PROP_CURRENTLY_COPYING,
-                                 NULL, subpool));
+  SVN_ERR(svn_ra_change_rev_prop2(rb->to_session, 0,
+                                  SVNSYNC_PROP_CURRENTLY_COPYING,
+                                  NULL, NULL, subpool));
 
   /* Notify the user that we copied revision properties. */
   if (! rb->sb->quiet)
@@ -1247,12 +1343,12 @@ do_synchronize(svn_ra_session_t *to_sess
              end up not being able to tell if there have been bogus
              (i.e. non-svnsync) commits to the dest repository. */
 
-          SVN_ERR(svn_ra_change_rev_prop(to_session, 0,
-                                         SVNSYNC_PROP_LAST_MERGED_REV,
-                                         last_merged_rev, pool));
-          SVN_ERR(svn_ra_change_rev_prop(to_session, 0,
-                                         SVNSYNC_PROP_CURRENTLY_COPYING,
-                                         NULL, pool));
+          SVN_ERR(svn_ra_change_rev_prop2(to_session, 0,
+                                          SVNSYNC_PROP_LAST_MERGED_REV,
+                                          NULL, last_merged_rev, pool));
+          SVN_ERR(svn_ra_change_rev_prop2(to_session, 0,
+                                          SVNSYNC_PROP_CURRENTLY_COPYING,
+                                          NULL, NULL, pool));
         }
       /* If copying > to_latest, then we just fall through to
          attempting to copy the revision again. */
@@ -1341,9 +1437,7 @@ synchronize_cmd(apr_getopt_t *os, void *
     }
 
   baton = make_subcommand_baton(opt_baton, to_url, from_url, 0, 0, pool);
-  SVN_ERR(svn_ra_open4(&to_session, NULL, baton->to_url, NULL,
-                       &(baton->sync_callbacks), baton, baton->config, pool));
-  SVN_ERR(check_if_session_is_at_repos_root(to_session, baton->to_url, pool));
+  SVN_ERR(open_target_session(&to_session, baton, pool));
   if (opt_baton->disable_locking)
     SVN_ERR(do_synchronize(to_session, baton, pool));
   else
@@ -1399,7 +1493,7 @@ do_copy_revprops(svn_ra_session_t *to_se
     {
       int normalized_count;
       SVN_ERR(check_cancel(NULL));
-      SVN_ERR(copy_revprops(from_session, to_session, i, FALSE,
+      SVN_ERR(copy_revprops(from_session, to_session, i, TRUE,
                             baton->quiet, &normalized_count, pool));
       normalized_rev_props_count += normalized_count;
     }
@@ -1577,9 +1671,7 @@ copy_revprops_cmd(apr_getopt_t *os, void
       
   baton = make_subcommand_baton(opt_baton, to_url, from_url,
                                 start_rev, end_rev, pool);
-  SVN_ERR(svn_ra_open4(&to_session, NULL, baton->to_url, NULL,
-                       &(baton->sync_callbacks), baton, baton->config, pool));
-  SVN_ERR(check_if_session_is_at_repos_root(to_session, baton->to_url, pool));
+  SVN_ERR(open_target_session(&to_session, baton, pool));
   if (opt_baton->disable_locking)
     SVN_ERR(do_copy_revprops(to_session, baton, pool));
   else
@@ -1621,9 +1713,7 @@ info_cmd(apr_getopt_t *os, void *b, apr_
 
   /* Open an RA session to the mirror repository URL. */
   baton = make_subcommand_baton(opt_baton, to_url, NULL, 0, 0, pool);
-  SVN_ERR(svn_ra_open4(&to_session, NULL, baton->to_url, NULL,
-                       &(baton->sync_callbacks), baton, baton->config, pool));
-  SVN_ERR(check_if_session_is_at_repos_root(to_session, baton->to_url, pool));
+  SVN_ERR(open_target_session(&to_session, baton, pool));
 
   /* Verify that the repos has been initialized for synchronization. */
   SVN_ERR(svn_ra_rev_prop(to_session, 0, SVNSYNC_PROP_FROM_URL,
@@ -1739,7 +1829,7 @@ main(int argc, const char *argv[])
 
   if (argc <= 1)
     {
-      help_cmd(NULL, NULL, pool);
+      SVN_INT_ERR(help_cmd(NULL, NULL, pool));
       svn_pool_destroy(pool);
       return EXIT_FAILURE;
     }
@@ -1760,7 +1850,7 @@ main(int argc, const char *argv[])
         break;
       else if (apr_err)
         {
-          help_cmd(NULL, NULL, pool);
+          SVN_INT_ERR(help_cmd(NULL, NULL, pool));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }
@@ -1880,7 +1970,7 @@ main(int argc, const char *argv[])
 
           default:
             {
-              help_cmd(NULL, NULL, pool);
+              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
               svn_pool_destroy(pool);
               return EXIT_FAILURE;
             }
@@ -1951,7 +2041,7 @@ main(int argc, const char *argv[])
             }
           else
             {
-              help_cmd(NULL, NULL, pool);
+              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
               svn_pool_destroy(pool);
               return EXIT_FAILURE;
             }
@@ -1963,7 +2053,7 @@ main(int argc, const char *argv[])
                                                          first_arg);
           if (subcommand == NULL)
             {
-              help_cmd(NULL, NULL, pool);
+              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
               svn_pool_destroy(pool);
               return EXIT_FAILURE;
             }
@@ -1986,7 +2076,7 @@ main(int argc, const char *argv[])
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
           if (subcommand->name[0] == '-')
             {
-              help_cmd(NULL, NULL, pool);
+              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
             }
           else
             {
@@ -2065,15 +2155,7 @@ main(int argc, const char *argv[])
                                         check_cancel, NULL,
                                         pool);
   if (! err)
-    {
-      /* svnsync can safely create instance of QApplication class. */
-      svn_auth_set_parameter(opt_baton.source_auth_baton,
-                             "svn:auth:qapplication-safe", "1");
-      svn_auth_set_parameter(opt_baton.sync_auth_baton,
-                             "svn:auth:qapplication-safe", "1");
-
-      err = (*subcommand->cmd_func)(os, &opt_baton, pool);
-    }
+    err = (*subcommand->cmd_func)(os, &opt_baton, pool);
   if (err)
     {
       /* For argument-related problems, suggest using the 'help'

Propchange: subversion/branches/ignore-mergeinfo/subversion/tests/cmdline/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Dec 11 00:15:55 2010
@@ -6,4 +6,5 @@ httpd-*
 *~
 .*~
 entries-dump
+atomic-ra-revprop-change
 .libs