changeset 8188:f3abe032fc89

add cmdutil.remoteui remoteui sorts out the issues of getting ssh config options from the local repo into the remote one while not copying other options like hooks.
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:43 -0500
parents d2504744e7a5
children d2899a856f9f
files hgext/fetch.py hgext/graphlog.py hgext/mq.py hgext/patchbomb.py mercurial/cmdutil.py mercurial/commands.py
diffstat 6 files changed, 32 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/fetch.py
+++ b/hgext/fetch.py
@@ -60,9 +60,8 @@
             raise util.Abort(_('multiple heads in this branch '
                                '(use "hg heads ." and "hg merge" to merge)'))
 
-        cmdutil.setremoteconfig(ui, opts)
-
-        other = hg.repository(ui, ui.expandpath(source))
+        other = hg.repository(cmdutil.remoteui(repo, opts),
+                              ui.expandpath(source))
         ui.status(_('pulling from %s\n') %
                   url.hidepassword(ui.expandpath(source)))
         revs = None
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -321,10 +321,9 @@
     dest, revs, checkout = hg.parseurl(
         ui.expandpath(dest or 'default-push', dest or 'default'),
         opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
     if revs:
         revs = [repo.lookup(rev) for rev in revs]
-    other = hg.repository(ui, dest)
+    other = hg.repository(cmdutil.remoteui(ui, opts), dest)
     ui.status(_('comparing with %s\n') % url.hidepassword(dest))
     o = repo.findoutgoing(other, force=opts.get('force'))
     if not o:
@@ -348,9 +347,7 @@
 
     check_unsupported_flags(opts)
     source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
-
-    other = hg.repository(ui, source)
+    other = hg.repository(cmdutil.remoteui(repo, opts), source)
     ui.status(_('comparing with %s\n') % url.hidepassword(source))
     if revs:
         revs = [other.lookup(rev) for rev in revs]
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1744,10 +1744,9 @@
         if url.endswith('/'):
             url = url[:-1]
         return url + '/.hg/patches'
-    cmdutil.setremoteconfig(ui, opts)
     if dest is None:
         dest = hg.defaultdest(source)
-    sr = hg.repository(ui, ui.expandpath(source))
+    sr = hg.repository(cmdutil.remoteui(ui, opts), ui.expandpath(source))
     if opts['patches']:
         patchespath = ui.expandpath(opts['patches'])
     else:
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -220,7 +220,7 @@
         '''Return the revisions present locally but not in dest'''
         dest = ui.expandpath(dest or 'default-push', dest or 'default')
         revs = [repo.lookup(rev) for rev in revs]
-        other = hg.repository(ui, dest)
+        other = hg.repository(cmdutil.remoteui(repo, opts), dest)
         ui.status(_('comparing with %s\n') % dest)
         o = repo.findoutgoing(other)
         if not o:
@@ -258,7 +258,6 @@
             or opts.get('patches')):
         raise util.Abort(_('specify at least one changeset with -r or -o'))
 
-    cmdutil.setremoteconfig(ui, opts)
     if opts.get('outgoing') and opts.get('bundle'):
         raise util.Abort(_("--outgoing mode always on with --bundle;"
                            " do not re-specify --outgoing"))
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -98,12 +98,25 @@
         limit = sys.maxint
     return limit
 
-def setremoteconfig(ui, opts):
-    "copy remote options to ui tree"
-    if opts.get('ssh'):
-        ui.setconfig("ui", "ssh", opts['ssh'])
-    if opts.get('remotecmd'):
-        ui.setconfig("ui", "remotecmd", opts['remotecmd'])
+def remoteui(src, opts):
+    'build a remote ui from ui or repo and opts'
+    if hasattr(src, 'ui'): # looks like a repository
+        dst = src.ui.parentui # drop repo-specific config
+        src = src.ui # copy target options from repo
+    else: # assume it's a ui object
+        dst = src # 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)
+
+    return dst
 
 def revpair(repo, revs):
     '''return pair of nodes, given list of revisions. second item can
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -521,10 +521,9 @@
                         seen[p] = 1
                         visit.append(p)
     else:
-        cmdutil.setremoteconfig(ui, opts)
         dest, revs, checkout = hg.parseurl(
             ui.expandpath(dest or 'default-push', dest or 'default'), revs)
-        other = hg.repository(ui, dest)
+        other = hg.repository(cmdutil.remoteui(repo, opts), dest)
         o = repo.findoutgoing(other, force=opts.get('force'))
 
     if revs:
@@ -615,8 +614,7 @@
     metadata under the .hg directory, such as mq.
 
     """
-    cmdutil.setremoteconfig(ui, opts)
-    hg.clone(ui, source, dest,
+    hg.clone(cmdutil.remoteui(ui, opts), source, dest,
              pull=opts.get('pull'),
              stream=opts.get('uncompressed'),
              rev=opts.get('rev'),
@@ -1766,9 +1764,7 @@
     """
     limit = cmdutil.loglimit(opts)
     source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
-
-    other = hg.repository(ui, source)
+    other = hg.repository(cmdutil.remoteui(repo, opts), source)
     ui.status(_('comparing with %s\n') % url.hidepassword(source))
     if revs:
         revs = [other.lookup(rev) for rev in revs]
@@ -1834,8 +1830,7 @@
     It is possible to specify an ssh:// URL as the destination.
     See 'hg help urls' for more information.
     """
-    cmdutil.setremoteconfig(ui, opts)
-    hg.repository(ui, dest, create=1)
+    hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
 
 def locate(ui, repo, *pats, **opts):
     """locate files matching specific patterns
@@ -2084,11 +2079,10 @@
     limit = cmdutil.loglimit(opts)
     dest, revs, checkout = hg.parseurl(
         ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
     if revs:
         revs = [repo.lookup(rev) for rev in revs]
 
-    other = hg.repository(ui, dest)
+    other = hg.repository(cmdutil.remoteui(repo, opts), dest)
     ui.status(_('comparing with %s\n') % url.hidepassword(dest))
     o = repo.findoutgoing(other, force=opts.get('force'))
     if not o:
@@ -2199,9 +2193,7 @@
     See 'hg help urls' for more information.
     """
     source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
-
-    other = hg.repository(ui, source)
+    other = hg.repository(cmdutil.remoteui(repo, opts), source)
     ui.status(_('pulling from %s\n') % url.hidepassword(source))
     if revs:
         try:
@@ -2237,9 +2229,7 @@
     """
     dest, revs, checkout = hg.parseurl(
         ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
-    cmdutil.setremoteconfig(ui, opts)
-
-    other = hg.repository(ui, dest)
+    other = hg.repository(cmdutil.remoteui(repo, opts), dest)
     ui.status(_('pushing to %s\n') % url.hidepassword(dest))
     if revs:
         revs = [repo.lookup(rev) for rev in revs]