[PATCH 4 of 6] localrepo: introduce peer.repo() and switch from peer to repo as appropriate
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Wed Jun 8 11:45:31 CDT 2011
# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1307550642 -7200
localrepo: introduce peer.repo() and switch from peer to repo as appropriate
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2072,12 +2072,13 @@
' (see init --mq)'))
qbase, destrev = None, None
if sr.local():
- if sr.mq.applied:
- qbase = sr.mq.applied[0].node
+ repo = sr.repo()
+ if repo.mq.applied:
+ qbase = repo.mq.applied[0].node
if not hg.islocal(dest):
- heads = set(sr.heads())
- destrev = list(heads.difference(sr.heads(qbase)))
- destrev.append(sr.changelog.parents(qbase)[0])
+ heads = set(repo.heads())
+ destrev = list(heads.difference(repo.heads(qbase)))
+ destrev.append(repo.changelog.parents(qbase)[0])
elif sr.capable('lookup'):
try:
qbase = sr.lookup('qbase')
@@ -2094,13 +2095,14 @@
pull=opts.get('pull'), update=not opts.get('noupdate'),
stream=opts.get('uncompressed'))
if dr.local():
+ repo = dr.repo()
if qbase:
ui.note(_('stripping applied patches from destination '
'repository\n'))
- dr.mq.strip(dr, [qbase], update=False, backup=None)
+ repo.mq.strip(repo, [qbase], update=False, backup=None)
if not opts.get('noupdate'):
ui.note(_('updating destination repository\n'))
- hg.update(dr, dr.changelog.tip())
+ hg.update(repo, repo.changelog.tip())
@command("qcommit|qci",
commands.table["^commit|ci"][1],
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -561,9 +561,9 @@
sourcerepo = opts.get('source')
if sourcerepo:
- source = hg.peer(ui, opts, ui.expandpath(sourcerepo))
- branches = map(source.lookup, opts.get('branch', ()))
- source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, source,
+ peer = hg.peer(ui, opts, ui.expandpath(sourcerepo))
+ branches = map(peer.lookup, opts.get('branch', ()))
+ source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, peer,
onlyheads=branches, force=True)
else:
source = repo
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -322,8 +322,8 @@
bundle = None
bundlerepo = None
- localrepo = other
- if bundlename or not other.local():
+ localrepo = other.local() and other.repo() or None
+ if bundlename or not localrepo:
# create a bundle (uncompressed if other repo is not local)
if other.capable('getbundle'):
@@ -334,12 +334,12 @@
rheads = None
else:
cg = other.changegroupsubset(incoming, rheads, 'incoming')
- bundletype = other.local() and "HG10BZ" or "HG10UN"
+ bundletype = localrepo and "HG10BZ" or "HG10UN"
fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
# keep written bundle?
if bundlename:
bundle = None
- if not other.local():
+ if not localrepo:
# use the created uncompressed bundlerepo
localrepo = bundlerepo = bundlerepository(ui, repo.root, fname)
# this repo contains local and other now, so filter out local again
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -10,7 +10,7 @@
from i18n import _, gettext
import os, re, sys, difflib, time, tempfile, errno
import hg, scmutil, util, revlog, extensions, copies, error, bookmarks
-import patch, help, url, encoding, templatekw, discovery, localrepo
+import patch, help, url, encoding, templatekw, discovery
import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
import merge as mergemod
import minirst, revset, fileset
@@ -2910,10 +2910,11 @@
if source:
source, branches = hg.parseurl(ui.expandpath(source))
- repo = hg.peer(ui, {}, source)
- revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
-
- if not repo.local():
+ peer = hg.peer(ui, {}, source)
+ repo = peer.local() and peer.repo() or None
+ revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
+
+ if not repo:
if num or branch or tags:
raise util.Abort(
_("can't query remote revision number, branch, or tags"))
@@ -2922,16 +2923,16 @@
if not rev:
rev = "tip"
- remoterev = repo.lookup(rev)
+ remoterev = peer.lookup(rev)
if default or id:
output = [hexfunc(remoterev)]
def getbms():
bms = []
- if 'bookmarks' in repo.listkeys('namespaces'):
+ if 'bookmarks' in peer.listkeys('namespaces'):
hexremoterev = hex(remoterev)
- bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems()
+ bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
if bmr == hexremoterev]
return bms
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -133,10 +133,10 @@
def repository(ui, path='', create=False):
"""return a repository object for the specified path"""
- repo = _repoorpeer(ui, path, create)
- if not repo.local():
- raise util.Abort(_("repository '%s' is not local") % (path or repo.url()))
- return repo
+ peer = _repoorpeer(ui, path, create)
+ if not peer.local():
+ raise util.Abort(_("repository '%s' is not local") % (path or peer.url()))
+ return peer.repo()
def defaultdest(source):
'''return default destination of clone if none is given'''
@@ -159,7 +159,7 @@
srcrepo = repository(ui, source)
rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
else:
- srcrepo = source
+ srcrepo = source.repo()
origsource = source = srcrepo.url()
checkout = None
@@ -249,12 +249,12 @@
if isinstance(source, str):
origsource = ui.expandpath(source)
source, branch = parseurl(origsource, branch)
- srcrepo = peer(ui, opts, source)
+ srcpeer = peer(ui, opts, source)
else:
- srcrepo = source
+ srcpeer = source
branch = (None, branch or [])
- origsource = source = srcrepo.url()
- rev, checkout = addbranchrevs(srcrepo, srcrepo, branch, rev)
+ origsource = source = srcpeer.url()
+ rev, checkout = addbranchrevs(srcpeer, srcpeer, branch, rev)
if dest is None:
dest = defaultdest(source)
@@ -291,10 +291,11 @@
dircleanup = DirCleanup(dest)
copy = False
- if srcrepo.cancopy() and islocal(dest):
+ if srcpeer.cancopy() and islocal(dest):
copy = not pull and not rev
if copy:
+ srcrepo = srcpeer.repo()
try:
# we use a lock here because if we race with commit, we
# can end up with extra data in the cloned revlogs that's
@@ -343,12 +344,12 @@
# we need to re-init the repo after manually copying the data
# into it
- destrepo = peer(ui, opts, dest)
+ destpeer = peer(ui, opts, dest)
srcrepo.hook('outgoing', source='clone',
node=node.hex(node.nullid))
else:
try:
- destrepo = peer(ui, opts, dest, create=True)
+ destpeer = peer(ui, opts, dest, create=True)
except OSError, inst:
if inst.errno == errno.EEXIST:
dircleanup.close()
@@ -358,23 +359,24 @@
revs = None
if rev:
- if not srcrepo.capable('lookup'):
+ if not srcpeer.capable('lookup'):
raise util.Abort(_("src repository does not support "
"revision lookup and so doesn't "
"support clone by revision"))
- revs = [srcrepo.lookup(r) for r in rev]
+ revs = [srcpeer.lookup(r) for r in rev]
checkout = revs[0]
- if destrepo.local():
- destrepo.clone(srcrepo, heads=revs, stream=stream)
- elif srcrepo.local():
- srcrepo.push(destrepo, revs=revs)
+ if destpeer.local():
+ destpeer.repo().clone(srcpeer, heads=revs, stream=stream)
+ elif srcpeer.local():
+ srcpeer.repo().push(destpeer, revs=revs)
else:
raise util.Abort(_("clone from remote to remote not supported"))
if dircleanup:
dircleanup.close()
- if destrepo.local():
+ if destpeer.local():
+ destrepo = destpeer.repo()
fp = destrepo.opener("hgrc", "w", text=True)
fp.write("[paths]\n")
fp.write("default = %s\n" % abspath)
@@ -385,8 +387,8 @@
if update:
if update is not True:
checkout = update
- if srcrepo.local():
- checkout = srcrepo.lookup(update)
+ if srcpeer.local():
+ checkout = srcpeer.repo().lookup(update)
for test in (checkout, 'default', 'tip'):
if test is None:
continue
@@ -400,8 +402,9 @@
_update(destrepo, uprev)
# clone all bookmarks
- if destrepo.local() and srcrepo.capable("pushkey"):
- rb = srcrepo.listkeys('bookmarks')
+ if destpeer.local() and srcpeer.capable("pushkey"):
+ destrepo = destpeer.repo()
+ rb = srcpeer.listkeys('bookmarks')
for k, n in rb.iteritems():
try:
m = destrepo.lookup(n)
@@ -410,11 +413,12 @@
pass
if rb:
bookmarks.write(destrepo)
- elif srcrepo.local() and destrepo.capable("pushkey"):
+ elif srcpeer.local() and destpeer.capable("pushkey"):
+ srcrepo = srcpeer.repo()
for k, n in srcrepo._bookmarks.iteritems():
- destrepo.pushkey('bookmarks', k, '', hex(n))
+ destpeer.pushkey('bookmarks', k, '', hex(n))
- return srcrepo, destrepo
+ return srcpeer, destpeer
finally:
release(srclock, destlock)
if dircleanup is not None:
diff --git a/mercurial/repo.py b/mercurial/repo.py
--- a/mercurial/repo.py
+++ b/mercurial/repo.py
@@ -10,6 +10,11 @@
import error
class repository(object):
+
+ def repo(self):
+ '''return peer as a repository - currently a no-op'''
+ return self
+
def capable(self, name):
'''tell whether repo supports named capability.
return False if not supported.
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -443,8 +443,9 @@
% (subrelpath(self), srcurl))
parentrepo = self._repo._subparent
shutil.rmtree(self._repo.root)
- other, self._repo = hg.clone(self._repo._subparent.ui, {}, other,
+ other, cloned = hg.clone(self._repo._subparent.ui, {}, other,
self._repo.root, update=False)
+ self._repo = cloned.repo()
self._initrepo(parentrepo, source, create=True)
else:
self._repo.ui.status(_('pulling subrepo %s from %s\n')
More information about the Mercurial-devel
mailing list