Stefanus Du Toit  committed e1d177a

Add --svn-retry parameter to hgpullsvn to retry the svn update step if it fails. Useful on slow/unstable connections.

  • Participants
  • Parent commits b90f88a

Comments (0)

Files changed (1)

File hgsvn/run/

         raise OverwrittenSVNBranch(msg)
-def pull_svn_rev(log_entry, current_rev, svn_wc, wc_url, wc_base):
+def pull_svn_rev(log_entry, current_rev, svn_wc, wc_url, wc_base, retry):
     Pull SVN changes from the given log entry.
     Returns the new SVN revision. If an exception occurs, it will rollback
             args = ["up", "--ignore-externals"]
             if get_svn_client_version() >= (1, 5):
                 args.extend(['--accept', 'postpone'])
-            run_svn(args + ["-r", svn_rev, svn_wc])
+            ui.status('Attempting to update to revision %s...', str(svn_rev))
+            # We wrap the svn update invocation in a loop so it can
+            # re-execute on failure if the --svn-retry option is set.
+            while True:
+                try:
+                    run_svn(args + ["-r", svn_rev, svn_wc])
+                    break
+                except Exception, e:
+                    ui.status('SVN update failed: %s', str(e))
+                    if retry:
+                        ui.status('Trying to update again...')
+                        continue
+                    else:
+                        raise
             conflicts = []
             for status_entry in get_svn_status('.'):
                 if status_entry['status'] == 'conflicted':
             for log_entry in it_log_entries:
                 current_rev = pull_svn_rev(log_entry, current_rev,
-                                           svn_wc, wc_url, wc_base)
+                                           svn_wc, wc_url, wc_base, options.svnretry)
                 if current_rev is None:
                     return 1
                 ui.status("Pulled r%d %s (%s)", log_entry["revision"],
     parser.add_option("-n", "--dry-run", dest="dryrun", default=False,
                       help="show incoming changesets without pulling them")
+    parser.add_option("--svn-retry", dest="svnretry", default=False,
+                      action="store_true",
+                      help="retry SVN update command on failure")
     (options, args) = run_parser(parser, __doc__)
     if args:
         display_parser_error(parser, "incorrect number of arguments")