# HG changeset patch # User Brendan Cully # Date 1183342990 25200 # Node ID 7c8cd400e86add44f7a3056eb24720ed136e9ba4 # Parent 07efcce17d28305556014ea2ea0a361ab380d978 convert: initialize source after destination, cleaning up if source is unusable diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -10,7 +10,7 @@ from cvs import convert_cvs from git import convert_git from hg import convert_mercurial -import os +import os, shutil from mercurial import hg, ui, util, commands commands.norepo += " convert" @@ -274,15 +274,12 @@ def _convert(ui, src, dest=None, mapfile srcauthor=whatever string you want ''' - srcc = converter(ui, src, rev=opts.get('rev')) - if not hasattr(srcc, "getcommit"): - raise util.Abort("%s: can't read from this repo type" % src) - if not dest: dest = src + "-hg" ui.status("assuming destination %s\n" % dest) # Try to be smart and initalize things when required + created = False if os.path.isdir(dest): if len(os.listdir(dest)) > 0: try: @@ -297,16 +294,27 @@ def _convert(ui, src, dest=None, mapfile else: ui.status("initializing destination %s repository\n" % dest) hg.repository(ui, dest, create=True) + created = True elif os.path.exists(dest): raise util.Abort("destination %s exists and is not a directory" % dest) else: ui.status("initializing destination %s repository\n" % dest) hg.repository(ui, dest, create=True) + created = True destc = converter(ui, dest) if not hasattr(destc, "putcommit"): raise util.Abort("%s: can't write to this repo type" % src) + try: + srcc = converter(ui, src, rev=opts.get('rev')) + if not hasattr(srcc, "getcommit"): + raise util.Abort("%s: can't read from this repo type" % src) + except Exception: + if created: + shutil.rmtree(dest, True) + raise + if not mapfile: try: mapfile = destc.mapfile()