changeset 402:d453cf1aafa3

uisetup: move clone and push/pull wrappers to wrappers module
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 10 Jun 2009 11:35:59 +0200
parents 9e87f7047bf1
children 37c96b78b8c0
files hgsubversion/__init__.py hgsubversion/wrappers.py
diffstat 2 files changed, 66 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/__init__.py
+++ b/hgsubversion/__init__.py
@@ -28,27 +28,13 @@ from mercurial import commands
 from mercurial import extensions
 from mercurial import hg
 from mercurial import util as hgutil
-from mercurial import cmdutil as hgcmdutil
 
 from svn import core
 
 import svncommands
 import cmdutil
 import svnrepo
-import util
 import wrappers
-import svnexternals
-
-optionmap = {
-    'tagpaths': ('hgsubversion', 'tagpaths'),
-    'authors': ('hgsubversion', 'authormap'),
-    'filemap': ('hgsubversion', 'filemap'),
-    'stupid': ('hgsubversion', 'stupid'),
-    'defaulthost': ('hgsubversion', 'defaulthost'),
-    'defaultauthors': ('hgsubversion', 'defaultauthors'),
-    'usebranchnames': ('hgsubversion', 'usebranchnames'),
-}
-dontretain = { 'hgsubversion': set(['authormap', 'filemap']) }
 
 svnopts = (('', 'stupid', None, 'use slower, but more compatible, protocol for '
             'Subversion'),)
@@ -60,48 +46,7 @@ svncloneopts = (('T', 'tagpaths', '', 'l
                 ('', 'filemap', '', 'path to file containing rules for '
                  'remapping Subversion repository paths'),)
 
-def wrapper(orig, ui, repo, *args, **opts):
-    """
-    Subversion %(target)s can be used for %(command)s. See 'hg help
-    %(extension)s' for more on the conversion process.
-    """
-    for opt, (section, name) in optionmap.iteritems():
-        if opt in opts and opts[opt]:
-            if isinstance(repo, str):
-                ui.setconfig(section, name, opts.pop(opt))
-            else:
-                repo.ui.setconfig(section, name, opts.pop(opt))
-
-    return orig(ui, repo, *args, **opts)
-
-def clonewrapper(orig, ui, source, dest=None, **opts):
-    """
-    Some of the options listed below only apply to Subversion
-    %(target)s. See 'hg help %(extension)s' for more information on
-    them as well as other ways of customising the conversion process.
-    """
-
-    for opt, (section, name) in optionmap.iteritems():
-        if opt in opts and opts[opt]:
-            ui.setconfig(section, name, str(opts.pop(opt)))
-
-    # this must be kept in sync with mercurial/commands.py
-    srcrepo, dstrepo = hg.clone(hgcmdutil.remoteui(ui, opts), source, dest,
-                                pull=opts.get('pull'),
-                                stream=opts.get('uncompressed'),
-                                rev=opts.get('rev'),
-                                update=not opts.get('noupdate'))
-
-    if dstrepo.local() and srcrepo.capable('subversion'):
-        fd = dstrepo.opener("hgrc", "a", text=True)
-        for section in set(s for s, v in optionmap.itervalues()):
-            config = dict(ui.configitems(section))
-            for name in dontretain[section]:
-                config.pop(name, None)
-
-            if config:
-                fd.write('\n[%s]\n' % section)
-                map(fd.write, ('%s = %s\n' % p for p in config.iteritems()))
+wraptype = {False: wrappers.generic, True: wrappers.clone}
 
 def uisetup(ui):
     """Do our UI setup.
@@ -118,17 +63,20 @@ def uisetup(ui):
     entry[1].append(('', 'svn', None,
                      "show svn-style diffs, default against svn parent"))
 
+    docvals = {'extension': 'hgsubversion'}
     for command, target, isclone in [('clone', 'sources', True),
                                      ('pull', 'sources', False),
                                      ('push', 'destinations', False)]:
-        doc = wrapper.__doc__.strip() % { 'command': command,
-                                          'Command': command.capitalize(),
-                                          'extension': 'hgsubversion',
-                                          'target': target }
+
+        docvals['command'] = command
+        docvals['Command'] = command.capitalize()
+        docvals['target'] = target
+        doc = wrappers.generic.__doc__.strip() % docvals
         fn = getattr(commands, command)
         fn.__doc__ = fn.__doc__.rstrip() + '\n\n    ' + doc
-        entry = extensions.wrapcommand(commands.table, command,
-                                       (wrapper, clonewrapper)[isclone])
+
+        wrapped = wraptype[isclone]
+        entry = extensions.wrapcommand(commands.table, command, wrapped)
         entry[1].extend(svnopts)
         if isclone: entry[1].extend(svncloneopts)
 
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -309,3 +309,59 @@ def rebase(orig, ui, repo, **opts):
     return orig(ui, repo, dest=node.hex(target_rev.node()),
                 base=node.hex(sourcerev),
                 extrafn=extrafn)
+
+
+optionmap = {
+    'tagpaths': ('hgsubversion', 'tagpaths'),
+    'authors': ('hgsubversion', 'authormap'),
+    'filemap': ('hgsubversion', 'filemap'),
+    'stupid': ('hgsubversion', 'stupid'),
+    'defaulthost': ('hgsubversion', 'defaulthost'),
+    'defaultauthors': ('hgsubversion', 'defaultauthors'),
+    'usebranchnames': ('hgsubversion', 'usebranchnames'),
+}
+
+dontretain = { 'hgsubversion': set(['authormap', 'filemap']) }
+
+def clone(orig, ui, source, dest=None, **opts):
+    """
+    Some of the options listed below only apply to Subversion
+    %(target)s. See 'hg help %(extension)s' for more information on
+    them as well as other ways of customising the conversion process.
+    """
+
+    for opt, (section, name) in optionmap.iteritems():
+        if opt in opts and opts[opt]:
+            ui.setconfig(section, name, str(opts.pop(opt)))
+
+    # this must be kept in sync with mercurial/commands.py
+    srcrepo, dstrepo = hg.clone(hgcmdutil.remoteui(ui, opts), source, dest,
+                                pull=opts.get('pull'),
+                                stream=opts.get('uncompressed'),
+                                rev=opts.get('rev'),
+                                update=not opts.get('noupdate'))
+
+    if dstrepo.local() and srcrepo.capable('subversion'):
+        fd = dstrepo.opener("hgrc", "a", text=True)
+        for section in set(s for s, v in optionmap.itervalues()):
+            config = dict(ui.configitems(section))
+            for name in dontretain[section]:
+                config.pop(name, None)
+
+            if config:
+                fd.write('\n[%s]\n' % section)
+                map(fd.write, ('%s = %s\n' % p for p in config.iteritems()))
+
+
+def generic(orig, ui, repo, *args, **opts):
+    """
+    Subversion %(target)s can be used for %(command)s. See 'hg help
+    %(extension)s' for more on the conversion process.
+    """
+    for opt, (section, name) in optionmap.iteritems():
+        if opt in opts and opts[opt]:
+            if isinstance(repo, str):
+                ui.setconfig(section, name, opts.pop(opt))
+            else:
+                repo.ui.setconfig(section, name, opts.pop(opt))
+    return orig(ui, repo, *args, **opts)