diff mercurial/hg.py @ 11273:d1908cb95a82

remoteui: move from cmdutil to hg
author Matt Mackall <mpm@selenic.com>
date Tue, 01 Jun 2010 11:18:57 -0500
parents 94b7b3a1ae1b
children 24eeca1f2791
line wrap: on
line diff
--- a/mercurial/hg.py	Thu Jun 03 21:38:30 2010 +0200
+++ b/mercurial/hg.py	Tue Jun 01 11:18:57 2010 -0500
@@ -400,3 +400,29 @@
 def verify(repo):
     """verify the consistency of a repository"""
     return verifymod.verify(repo)
+
+def remoteui(src, opts):
+    'build a remote ui from ui or repo and opts'
+    if hasattr(src, 'baseui'): # looks like a repository
+        dst = src.baseui.copy() # drop repo-specific config
+        src = src.ui # copy target options from repo
+    else: # assume it's a global ui object
+        dst = src.copy() # keep all global options
+
+    # copy ssh-specific options
+    for o in 'ssh', 'remotecmd':
+        v = opts.get(o) or src.config('ui', o)
+        if v:
+            dst.setconfig("ui", o, v)
+
+    # copy bundle-specific options
+    r = src.config('bundle', 'mainreporoot')
+    if r:
+        dst.setconfig('bundle', 'mainreporoot', r)
+
+    # copy auth and http_proxy section settings
+    for sect in ('auth', 'http_proxy'):
+        for key, val in src.configitems(sect):
+            dst.setconfig(sect, key, val)
+
+    return dst