Anonymous avatar Anonymous committed e1d177a

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

Comments (0)

Files changed (1)

hgsvn/run/hgpullsvn.py

         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':
         try:
             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,
                       action="store_true",
                       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")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.