[PATCH] allow hgext/convert paths to declare their repo types

David Champion dgc at uchicago.edu
Sun Sep 16 12:47:08 CDT 2007

This introduces a notation for declaring repository types to the convert
extension.  It's not option-based, because that looks like it affects
code I haven't read through yet and because "hg convert -cvs repo-cvs
-hg repo-hg" would violate conventions for option processing anyway.
Instead it uses a "path//type" notation:

    hg convert project//cvs project//hg

I wanted this so that I can use a single working copy for both the CVS
wc and the hg repo, such that "project/CVS" and "project/.hg" both
exist.  It lets me sync future changes in cvs to the existing hg repo
using convert, but with only one working directory.

I'm willing to make changes as needed, if anyone wants to move this

# HG changeset patch
# User David Champion <dgc at uchicago.edu>
# Date 1189964472 18000
# Node ID 6256455deaaa59f5e95899326679065859e24419
# Parent  5b0b0834419c042cfad3185bf4d9c00ca89b319a
[mq]: typedconvert

diff -r 5b0b0834419c -r 6256455deaaa hgext/convert/__init__.py
--- a/hgext/convert/__init__.py	Fri Sep 14 22:47:15 2007 +0200
+++ b/hgext/convert/__init__.py	Sun Sep 16 12:41:12 2007 -0500
@@ -15,17 +15,41 @@ from mercurial import hg, ui, util, comm
 commands.norepo += " convert"
-converters = [convert_cvs, convert_git, convert_mercurial]
-def converter(ui, path):
+converters = {'cvs': convert_cvs, 'git': convert_git, 'hg': convert_mercurial}
+def typedconverter(ui, path, c):
     if not os.path.isdir(path):
         raise util.Abort("%s: not a directory" % path)
-    for c in converters:
+    # try only the specified repo type
+    if c:
+        try:
+            return c(ui, path)
+        except NoRepo, e:
+            raise util.Abort(str(e))
+    # guess at repo type
+    for c in converters.values():
             return c(ui, path)
         except NoRepo:
     raise util.Abort("%s: unknown repository type" % path)
+def converter(ui, path):
+    lpath = type = None
+    try:
+        (lpath, type) = path.split('//', 1)
+    except ValueError:
+        pass
+    if lpath and type:
+        if not converters.has_key(type):
+            raise util.Abort("%s: unknown repository type '%s'" % (lpath, type))
+        return typedconverter(ui, lpath, converters[type])
+    return typedconverter(ui, path, None)
 class convert(object):
     def __init__(self, ui, source, dest, mapfile, opts):

More information about the Mercurial-devel mailing list