[PATCH 1 of 3] convert: create a helper function from the body of convert function command
Alexis S. L. Carvalho
alexis at cecm.usp.br
Sat Sep 1 01:56:36 CDT 2007
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1188629314 10800
# Node ID 7a0981570761487210b271a5e48305e95317070d
# Parent a176f9c8b26e0a7cd526b7220bdb76be0b9e8fa9
convert: create a helper function from the body of convert function command
diff -r a176f9c8b26e -r 7a0981570761 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py Sat Sep 01 02:49:18 2007 -0300
+++ b/hgext/convert/__init__.py Sat Sep 01 03:48:34 2007 -0300
@@ -363,6 +363,57 @@ class filemapper(object):
def active(self):
return bool(self.include or self.exclude or self.rename)
+def _convert(ui, src, dest, revmapfile, opts):
+ util._encoding = 'UTF-8'
+
+ if not dest:
+ dest = hg.defaultdest(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:
+ hg.repository(ui, dest)
+ ui.status("destination %s is a Mercurial repository\n" % dest)
+ except hg.RepoError:
+ raise util.Abort(
+ "destination directory %s is not empty.\n"
+ "Please specify an empty directory to be initialized\n"
+ "or an already initialized mercurial repository"
+ % dest)
+ 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 = convertsink(ui, dest)
+
+ try:
+ srcc = convertsource(ui, src, rev=opts.get('rev'))
+ except Exception:
+ if created:
+ shutil.rmtree(dest, True)
+ raise
+
+ if not revmapfile:
+ try:
+ revmapfile = destc.revmapfile()
+ except:
+ revmapfile = os.path.join(destc, "map")
+
+
+ c = converter(ui, srcc, destc, revmapfile, filemapper(ui, opts['filemap']),
+ opts)
+ c.convert()
+
def convert(ui, src, dest=None, revmapfile=None, **opts):
"""Convert a foreign SCM repository to a Mercurial one.
@@ -415,56 +466,7 @@ def convert(ui, src, dest=None, revmapfi
from a subdirectory into the root of the repository, use '.' as
the path to rename to.
"""
-
- util._encoding = 'UTF-8'
-
- if not dest:
- dest = hg.defaultdest(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:
- hg.repository(ui, dest)
- ui.status("destination %s is a Mercurial repository\n" % dest)
- except hg.RepoError:
- raise util.Abort(
- "destination directory %s is not empty.\n"
- "Please specify an empty directory to be initialized\n"
- "or an already initialized mercurial repository"
- % dest)
- 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 = convertsink(ui, dest)
-
- try:
- srcc = convertsource(ui, src, rev=opts.get('rev'))
- except Exception:
- if created:
- shutil.rmtree(dest, True)
- raise
-
- if not revmapfile:
- try:
- revmapfile = destc.revmapfile()
- except:
- revmapfile = os.path.join(destc, "map")
-
-
- c = converter(ui, srcc, destc, revmapfile, filemapper(ui, opts['filemap']),
- opts)
- c.convert()
+ return _convert(ui, src, dest, revmapfile, opts)
cmdtable = {
More information about the Mercurial-devel
mailing list