diff --git a/hgext/fetch.py b/hgext/fetch.py --- a/hgext/fetch.py +++ b/hgext/fetch.py @@ -60,9 +60,8 @@ def fetch(ui, repo, source='default', ** 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 diff --git a/hgext/graphlog.py b/hgext/graphlog.py --- a/hgext/graphlog.py +++ b/hgext/graphlog.py @@ -321,10 +321,9 @@ def goutgoing(ui, repo, dest=None, **opt 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 @@ def gincoming(ui, repo, source="default" 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] diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -1744,10 +1744,9 @@ def clone(ui, source, dest=None, **opts) 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: diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -220,7 +220,7 @@ def patchbomb(ui, repo, *revs, **opts): '''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 @@ def patchbomb(ui, repo, *revs, **opts): 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")) diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -98,12 +98,25 @@ def loglimit(opts): 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 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -521,10 +521,9 @@ def bundle(ui, repo, fname, dest=None, * 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 @@ def clone(ui, source, dest=None, **opts) 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 @@ def incoming(ui, repo, source="default", """ 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 @@ def init(ui, dest=".", **opts): 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 @@ def outgoing(ui, repo, dest=None, **opts 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 @@ def pull(ui, repo, source="default", **o 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 @@ def push(ui, repo, dest=None, **opts): """ 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]