comparison mercurial/commands.py @ 14556:517e1d88bf7e

hg: change various repository() users to use peer() where appropriate This gets all the easy cases (peers that aren't also used as repositories).
author Matt Mackall <mpm@selenic.com>
date Fri, 10 Jun 2011 11:43:38 -0500
parents d976542986d2
children f966979f61ce
comparison
equal deleted inserted replaced
14555:1ceb2cf9f9d9 14556:517e1d88bf7e
889 common = [repo.lookup(rev) for rev in base] 889 common = [repo.lookup(rev) for rev in base]
890 heads = revs and map(repo.lookup, revs) or revs 890 heads = revs and map(repo.lookup, revs) or revs
891 else: 891 else:
892 dest = ui.expandpath(dest or 'default-push', dest or 'default') 892 dest = ui.expandpath(dest or 'default-push', dest or 'default')
893 dest, branches = hg.parseurl(dest, opts.get('branch')) 893 dest, branches = hg.parseurl(dest, opts.get('branch'))
894 other = hg.repository(hg.remoteui(repo, opts), dest) 894 other = hg.peer(repo, opts, dest)
895 revs, checkout = hg.addbranchrevs(repo, other, branches, revs) 895 revs, checkout = hg.addbranchrevs(repo, other, branches, revs)
896 heads = revs and map(repo.lookup, revs) or revs 896 heads = revs and map(repo.lookup, revs) or revs
897 common, outheads = discovery.findcommonoutgoing(repo, other, 897 common, outheads = discovery.findcommonoutgoing(repo, other,
898 onlyheads=heads, 898 onlyheads=heads,
899 force=opts.get('force')) 899 force=opts.get('force'))
1540 ] + remoteopts, 1540 ] + remoteopts,
1541 _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) 1541 _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]'))
1542 def debugdiscovery(ui, repo, remoteurl="default", **opts): 1542 def debugdiscovery(ui, repo, remoteurl="default", **opts):
1543 """runs the changeset discovery protocol in isolation""" 1543 """runs the changeset discovery protocol in isolation"""
1544 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch')) 1544 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch'))
1545 remote = hg.repository(hg.remoteui(repo, opts), remoteurl) 1545 remote = hg.peer(repo, opts, remoteurl)
1546 ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) 1546 ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl))
1547 1547
1548 # make sure tests are repeatable 1548 # make sure tests are repeatable
1549 random.seed(12323) 1549 random.seed(12323)
1550 1550
1627 """retrieves a bundle from a repo 1627 """retrieves a bundle from a repo
1628 1628
1629 Every ID must be a full-length hex node id string. Saves the bundle to the 1629 Every ID must be a full-length hex node id string. Saves the bundle to the
1630 given file. 1630 given file.
1631 """ 1631 """
1632 repo = hg.repository(ui, repopath) 1632 repo = hg.peer(ui, opts, repopath)
1633 if not repo.capable('getbundle'): 1633 if not repo.capable('getbundle'):
1634 raise util.Abort("getbundle() not supported by target repository") 1634 raise util.Abort("getbundle() not supported by target repository")
1635 args = {} 1635 args = {}
1636 if common: 1636 if common:
1637 args['common'] = [bin(s) for s in common] 1637 args['common'] = [bin(s) for s in common]
1802 """test whether node ids are known to a repo 1802 """test whether node ids are known to a repo
1803 1803
1804 Every ID must be a full-length hex node id string. Returns a list of 0s and 1s 1804 Every ID must be a full-length hex node id string. Returns a list of 0s and 1s
1805 indicating unknown/known. 1805 indicating unknown/known.
1806 """ 1806 """
1807 repo = hg.repository(ui, repopath) 1807 repo = hg.peer(ui, opts, repopath)
1808 if not repo.capable('known'): 1808 if not repo.capable('known'):
1809 raise util.Abort("known() not supported by target repository") 1809 raise util.Abort("known() not supported by target repository")
1810 flags = repo.known([bin(s) for s in ids]) 1810 flags = repo.known([bin(s) for s in ids])
1811 ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) 1811 ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags])))
1812 1812
1813 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) 1813 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
1814 def debugpushkey(ui, repopath, namespace, *keyinfo): 1814 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
1815 '''access the pushkey key/value protocol 1815 '''access the pushkey key/value protocol
1816 1816
1817 With two args, list the keys in the given namespace. 1817 With two args, list the keys in the given namespace.
1818 1818
1819 With five args, set a key to new if it currently is set to old. 1819 With five args, set a key to new if it currently is set to old.
1820 Reports success or failure. 1820 Reports success or failure.
1821 ''' 1821 '''
1822 1822
1823 target = hg.repository(ui, repopath) 1823 target = hg.peer(ui, {}, repopath)
1824 if keyinfo: 1824 if keyinfo:
1825 key, old, new = keyinfo 1825 key, old, new = keyinfo
1826 r = target.pushkey(namespace, key, old, new) 1826 r = target.pushkey(namespace, key, old, new)
1827 ui.status(str(r) + '\n') 1827 ui.status(str(r) + '\n')
1828 return not r 1828 return not r
2115 ('', 'four', '', 'four'), 2115 ('', 'four', '', 'four'),
2116 ('', 'five', '', 'five'), 2116 ('', 'five', '', 'five'),
2117 ] + remoteopts, 2117 ] + remoteopts,
2118 _('REPO [OPTIONS]... [ONE [TWO]]')) 2118 _('REPO [OPTIONS]... [ONE [TWO]]'))
2119 def debugwireargs(ui, repopath, *vals, **opts): 2119 def debugwireargs(ui, repopath, *vals, **opts):
2120 repo = hg.repository(hg.remoteui(ui, opts), repopath) 2120 repo = hg.peer(ui, opts, repopath)
2121 for opt in remoteopts: 2121 for opt in remoteopts:
2122 del opts[opt[1]] 2122 del opts[opt[1]]
2123 args = {} 2123 args = {}
2124 for k, v in opts.iteritems(): 2124 for k, v in opts.iteritems():
2125 if v: 2125 if v:
2912 output = [] 2912 output = []
2913 revs = [] 2913 revs = []
2914 2914
2915 if source: 2915 if source:
2916 source, branches = hg.parseurl(ui.expandpath(source)) 2916 source, branches = hg.parseurl(ui.expandpath(source))
2917 repo = hg.repository(ui, source) 2917 repo = hg.peer(ui, {}, source)
2918 revs, checkout = hg.addbranchrevs(repo, repo, branches, None) 2918 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
2919 2919
2920 if not repo.local(): 2920 if not repo.local():
2921 if num or branch or tags: 2921 if num or branch or tags:
2922 raise util.Abort( 2922 raise util.Abort(
3197 raise util.Abort(_('cannot combine --bundle and --subrepos')) 3197 raise util.Abort(_('cannot combine --bundle and --subrepos'))
3198 3198
3199 if opts.get('bookmarks'): 3199 if opts.get('bookmarks'):
3200 source, branches = hg.parseurl(ui.expandpath(source), 3200 source, branches = hg.parseurl(ui.expandpath(source),
3201 opts.get('branch')) 3201 opts.get('branch'))
3202 other = hg.repository(hg.remoteui(repo, opts), source) 3202 other = hg.peer(repo, opts, source)
3203 if 'bookmarks' not in other.listkeys('namespaces'): 3203 if 'bookmarks' not in other.listkeys('namespaces'):
3204 ui.warn(_("remote doesn't support bookmarks\n")) 3204 ui.warn(_("remote doesn't support bookmarks\n"))
3205 return 0 3205 return 0
3206 ui.status(_('comparing with %s\n') % util.hidepassword(source)) 3206 ui.status(_('comparing with %s\n') % util.hidepassword(source))
3207 return bookmarks.diff(ui, repo, other) 3207 return bookmarks.diff(ui, repo, other)
3225 It is possible to specify an ``ssh://`` URL as the destination. 3225 It is possible to specify an ``ssh://`` URL as the destination.
3226 See :hg:`help urls` for more information. 3226 See :hg:`help urls` for more information.
3227 3227
3228 Returns 0 on success. 3228 Returns 0 on success.
3229 """ 3229 """
3230 hg.repository(hg.remoteui(ui, opts), ui.expandpath(dest), create=True) 3230 hg.peer(ui, opts, ui.expandpath(dest), create=True)
3231 3231
3232 @command('locate', 3232 @command('locate',
3233 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), 3233 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
3234 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), 3234 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
3235 ('f', 'fullpath', None, _('print complete paths from the filesystem root')), 3235 ('f', 'fullpath', None, _('print complete paths from the filesystem root')),
3559 """ 3559 """
3560 3560
3561 if opts.get('bookmarks'): 3561 if opts.get('bookmarks'):
3562 dest = ui.expandpath(dest or 'default-push', dest or 'default') 3562 dest = ui.expandpath(dest or 'default-push', dest or 'default')
3563 dest, branches = hg.parseurl(dest, opts.get('branch')) 3563 dest, branches = hg.parseurl(dest, opts.get('branch'))
3564 other = hg.repository(hg.remoteui(repo, opts), dest) 3564 other = hg.peer(repo, opts, dest)
3565 if 'bookmarks' not in other.listkeys('namespaces'): 3565 if 'bookmarks' not in other.listkeys('namespaces'):
3566 ui.warn(_("remote doesn't support bookmarks\n")) 3566 ui.warn(_("remote doesn't support bookmarks\n"))
3567 return 0 3567 return 0
3568 ui.status(_('comparing with %s\n') % util.hidepassword(dest)) 3568 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
3569 return bookmarks.diff(ui, other, repo) 3569 return bookmarks.diff(ui, other, repo)
3711 See :hg:`help urls` for more information. 3711 See :hg:`help urls` for more information.
3712 3712
3713 Returns 0 on success, 1 if an update had unresolved files. 3713 Returns 0 on success, 1 if an update had unresolved files.
3714 """ 3714 """
3715 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) 3715 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
3716 other = hg.repository(hg.remoteui(repo, opts), source) 3716 other = hg.peer(repo, opts, source)
3717 ui.status(_('pulling from %s\n') % util.hidepassword(source)) 3717 ui.status(_('pulling from %s\n') % util.hidepassword(source))
3718 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) 3718 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
3719 3719
3720 if opts.get('bookmark'): 3720 if opts.get('bookmark'):
3721 if not revs: 3721 if not revs:
3808 3808
3809 dest = ui.expandpath(dest or 'default-push', dest or 'default') 3809 dest = ui.expandpath(dest or 'default-push', dest or 'default')
3810 dest, branches = hg.parseurl(dest, opts.get('branch')) 3810 dest, branches = hg.parseurl(dest, opts.get('branch'))
3811 ui.status(_('pushing to %s\n') % util.hidepassword(dest)) 3811 ui.status(_('pushing to %s\n') % util.hidepassword(dest))
3812 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) 3812 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
3813 other = hg.repository(hg.remoteui(repo, opts), dest) 3813 other = hg.peer(repo, opts, dest)
3814 if revs: 3814 if revs:
3815 revs = [repo.lookup(rev) for rev in revs] 3815 revs = [repo.lookup(rev) for rev in revs]
3816 3816
3817 repo._subtoppath = dest 3817 repo._subtoppath = dest
3818 try: 3818 try:
4740 (new, len(bheads))) 4740 (new, len(bheads)))
4741 4741
4742 if opts.get('remote'): 4742 if opts.get('remote'):
4743 t = [] 4743 t = []
4744 source, branches = hg.parseurl(ui.expandpath('default')) 4744 source, branches = hg.parseurl(ui.expandpath('default'))
4745 other = hg.repository(hg.remoteui(repo, {}), source) 4745 other = hg.peer(repo, {}, source)
4746 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) 4746 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
4747 ui.debug('comparing with %s\n' % util.hidepassword(source)) 4747 ui.debug('comparing with %s\n' % util.hidepassword(source))
4748 repo.ui.pushbuffer() 4748 repo.ui.pushbuffer()
4749 commoninc = discovery.findcommonincoming(repo, other) 4749 commoninc = discovery.findcommonincoming(repo, other)
4750 _common, incoming, _rheads = commoninc 4750 _common, incoming, _rheads = commoninc
4753 t.append(_('1 or more incoming')) 4753 t.append(_('1 or more incoming'))
4754 4754
4755 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) 4755 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
4756 revs, checkout = hg.addbranchrevs(repo, repo, branches, None) 4756 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
4757 if source != dest: 4757 if source != dest:
4758 other = hg.repository(hg.remoteui(repo, {}), dest) 4758 other = hg.peer(repo, {}, dest)
4759 commoninc = None 4759 commoninc = None
4760 ui.debug('comparing with %s\n' % util.hidepassword(dest)) 4760 ui.debug('comparing with %s\n' % util.hidepassword(dest))
4761 repo.ui.pushbuffer() 4761 repo.ui.pushbuffer()
4762 common, outheads = discovery.findcommonoutgoing(repo, other, 4762 common, outheads = discovery.findcommonoutgoing(repo, other,
4763 commoninc=commoninc) 4763 commoninc=commoninc)