You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/02/15 13:57:18 UTC

svn commit: r910212 - /subversion/trunk/subversion/svnsync/main.c

Author: stsp
Date: Mon Feb 15 12:57:18 2010
New Revision: 910212

URL: http://svn.apache.org/viewvc?rev=910212&view=rev
Log:
Add a --disable-locking option to svnsync.

The built-in locking of svnsync has a known race condition (see issue #3546).
This option allows those who'd rather use an external locking mechaninism
(such as tools like flock and lockfile) to disable svnsync's internal locking
entirely. This avoids associated network overhead, and stale locks in case the
network connection drops unexpectedly.

* subversion/svnsync/main.c
  (svnsync__opt): Add svnsync_opt_disable_locking.
  (svnsync_cm): Enable the new --disable-locking option for the
   init, sync, and copy-revprops subcommands.
  (svnsync_options): Document --disable-locking option.
  (opt_baton_t): New field 'disable_locking'.
  (initialize_cmd, synchronize_cmd, copy_revprops_cmd): Don't use
   locking if the --disable-locking option was passed.
  (main): Pass the --disable-locking option into the opt baton.

Patch by: Jon Foster <Jo...@cabot.co.uk>
          me

Modified:
    subversion/trunk/subversion/svnsync/main.c

Modified: subversion/trunk/subversion/svnsync/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnsync/main.c?rev=910212&r1=910211&r2=910212&view=diff
==============================================================================
--- subversion/trunk/subversion/svnsync/main.c (original)
+++ subversion/trunk/subversion/svnsync/main.c Mon Feb 15 12:57:18 2010
@@ -61,6 +61,7 @@
   svnsync_opt_sync_password,
   svnsync_opt_config_dir,
   svnsync_opt_config_options,
+  svnsync_opt_disable_locking,
   svnsync_opt_version,
   svnsync_opt_trust_server_cert,
   svnsync_opt_allow_non_empty,
@@ -103,13 +104,14 @@
          "the destination repository by any method other than 'svnsync'.\n"
          "In other words, the destination repository should be a read-only\n"
          "mirror of the source repository.\n"),
-      { SVNSYNC_OPTS_DEFAULT, 'q', svnsync_opt_allow_non_empty } },
+      { SVNSYNC_OPTS_DEFAULT, 'q', svnsync_opt_allow_non_empty,
+        svnsync_opt_disable_locking } },
     { "synchronize", synchronize_cmd, { "sync" },
       N_("usage: svnsync synchronize DEST_URL\n"
          "\n"
          "Transfer all pending revisions to the destination from the source\n"
          "with which it was initialized.\n"),
-      { SVNSYNC_OPTS_DEFAULT, 'q' } },
+      { SVNSYNC_OPTS_DEFAULT, 'q', svnsync_opt_disable_locking } },
     { "copy-revprops", copy_revprops_cmd, { 0 },
       N_("usage: svnsync copy-revprops DEST_URL [REV[:REV2]]\n"
          "\n"
@@ -125,7 +127,7 @@
          "REV and REV2 must be revisions which were previously transferred\n"
          "to the destination.  You may use \"HEAD\" for either revision to\n"
          "mean \"the last revision transferred\".\n"),
-      { SVNSYNC_OPTS_DEFAULT, 'q' } },
+      { SVNSYNC_OPTS_DEFAULT, 'q', svnsync_opt_disable_locking } },
     { "info", info_cmd, { 0 },
       N_("usage: svnsync info DEST_URL\n"
          "\n"
@@ -180,6 +182,12 @@
                           "For example:\n"
                           "                             "
                           "    servers:global:http-library=serf")},
+    {"disable-locking",  svnsync_opt_disable_locking, 0,
+                       N_("Disable built-in locking. Use of this option can\n"
+                          "                             "
+                          "corrupt the mirror unless you ensure that no other\n"
+                          "                             "
+                          "instance of svnsync is running concurrently.")},
     {"version",        svnsync_opt_version, 0,
                        N_("show program version information")},
     {"help",           'h', 0,
@@ -201,6 +209,7 @@
   const char *sync_password;
   const char *config_dir;
   apr_hash_t *config;
+  svn_boolean_t disable_locking;
   svn_boolean_t quiet;
   svn_boolean_t allow_non_empty;
   svn_boolean_t version;
@@ -798,7 +807,10 @@
   SVN_ERR(svn_ra_open3(&to_session, 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(with_locked(to_session, do_initialize, baton, pool));
+  if (opt_baton->disable_locking)
+    SVN_ERR(do_initialize(to_session, baton, pool));
+  else
+    SVN_ERR(with_locked(to_session, do_initialize, baton, pool));
 
   return SVN_NO_ERROR;
 }
@@ -1276,7 +1288,10 @@
   SVN_ERR(svn_ra_open3(&to_session, 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(with_locked(to_session, do_synchronize, baton, pool));
+  if (opt_baton->disable_locking)
+    SVN_ERR(do_synchronize(to_session, baton, pool));
+  else
+    SVN_ERR(with_locked(to_session, do_synchronize, baton, pool));
 
   return SVN_NO_ERROR;
 }
@@ -1433,7 +1448,10 @@
   SVN_ERR(svn_ra_open3(&to_session, 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(with_locked(to_session, do_copy_revprops, baton, pool));
+  if (opt_baton->disable_locking)
+    SVN_ERR(do_copy_revprops(to_session, baton, pool));
+  else
+    SVN_ERR(with_locked(to_session, do_copy_revprops, baton, pool));
 
   return SVN_NO_ERROR;
 }
@@ -1664,6 +1682,11 @@
             if (err)
               return svn_cmdline_handle_exit_error(err, pool, "svnsync: ");
             break;
+
+          case svnsync_opt_disable_locking:
+            opt_baton.disable_locking = TRUE;
+            break;
+
           case svnsync_opt_version:
             opt_baton.version = TRUE;
             break;