[PATCH 14 of 17 RFC] clfilter: disallow the use of localrepo in `addbranchrevs` XXX
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Mon Sep 3 07:58:38 CDT 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1346676817 -7200
# Node ID e7aed7d06e04a6b30e0c00bc6de16cd89377258b
# Parent 2482fac4a05dae3211484df1cbf3ab1340ad30fd
clfilter: disallow the use of localrepo in `addbranchrevs` XXX
We want to ensure it's a `peer` to make sure the caller can take care of closing the
peer. Closing peer will help keeping filtering on a wide scope under control.
This solution is not yet complete a test breakable in `test-bundle.t` show.
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -407,11 +407,15 @@ def histedit(ui, repo, *parent, **opts):
dest = ui.expandpath(parent or 'default-push', parent or 'default')
dest, revs = hg.parseurl(dest, None)[:2]
ui.status(_('comparing with %s\n') % util.hidepassword(dest))
- revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, revs, None)
+ finally:
+ peer.close()
other = hg.peer(repo, opts, dest)
if revs:
revs = [repo.lookup(rev) for rev in revs]
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -928,11 +928,16 @@ def overrideforget(orig, ui, repo, *pats
wlock.release()
def getoutgoinglfiles(ui, repo, dest=None, **opts):
dest = ui.expandpath(dest or 'default-push', dest or 'default')
dest, branches = hg.parseurl(dest, opts.get('branch'))
- revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, branches,
+ opts.get('rev'))
+ finally:
+ peer.close()
if revs:
revs = [repo.lookup(rev) for rev in scmutil.revrange(repo, revs)]
try:
remote = hg.peer(repo, opts, dest)
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -168,10 +168,13 @@ class bundlefilelog(bundlerevlog, filelo
self._repo.file(f)
class bundlepeer(localrepo.localpeer):
def canpush(self):
return False
+ def close(self):
+ # XXX bad
+ pass
class bundlerepository(localrepo.localrepository):
def __init__(self, ui, path, bundlename):
self._tempparent = None
try:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4688,11 +4688,15 @@ def push(ui, repo, dest=None, **opts):
opts.setdefault('rev', []).append("null")
dest = ui.expandpath(dest or 'default-push', dest or 'default')
dest, branches = hg.parseurl(dest, opts.get('branch'))
ui.status(_('pushing to %s\n') % util.hidepassword(dest))
- revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, branches, opts.get('rev'))
+ finally:
+ peer.close()
other = hg.peer(repo, opts, dest)
if revs:
revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
repo._subtoppath = dest
@@ -5544,11 +5548,15 @@ def summary(ui, repo, **opts):
repo.ui.popbuffer()
if incoming:
t.append(_('1 or more incoming'))
dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
- revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
+ finally:
+ peer.close()
if source != dest:
other = hg.peer(repo, {}, dest)
commoninc = None
ui.debug('comparing with %s\n' % util.hidepassword(dest))
repo.ui.pushbuffer()
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -18,12 +18,11 @@ import errno, os, shutil
def _local(path):
path = util.expandpath(util.urllocalpath(path))
return (os.path.isfile(path) and bundlerepo or localrepo)
-def addbranchrevs(lrepo, other, branches, revs):
- peer = other.peer() # a courtesy to callers using a localrepo for other
+def addbranchrevs(lrepo, peer, branches, revs):
hashbranch, branches = branches
if not hashbranch and not branches:
return revs or None, revs and revs[0] or None
revs = revs and list(revs) or []
if not peer.capable('branchmap'):
@@ -130,11 +129,15 @@ def share(ui, source, dest=None, update=
if isinstance(source, str):
origsource = ui.expandpath(source)
source, branches = parseurl(origsource)
srcrepo = repository(ui, source)
- rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
+ srcpeer = srcrepo.peer()
+ try:
+ rev, checkout = addbranchrevs(srcrepo, srcpeer, branches, None)
+ finally:
+ srcpeer.close()
else:
srcrepo = source.local()
origsource = source = srcrepo.url()
checkout = None
@@ -514,11 +517,15 @@ def incoming(ui, repo, source, opts):
def _outgoing(ui, repo, dest, opts):
dest = ui.expandpath(dest or 'default-push', dest or 'default')
dest, branches = parseurl(dest, opts.get('branch'))
ui.status(_('comparing with %s\n') % util.hidepassword(dest))
- revs, checkout = addbranchrevs(repo, repo, branches, opts.get('rev'))
+ rpeer = repo.peer()
+ try:
+ revs, checkout = addbranchrevs(repo, rpeer, branches, opts.get('rev'))
+ finally:
+ rpeer.close()
if revs:
revs = [repo.lookup(rev) for rev in scmutil.revrange(repo, revs)]
other = peer(repo, opts, dest)
outgoing = discovery.findcommonoutgoing(repo, other, revs,
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -999,11 +999,15 @@ def outgoing(repo, subset, x):
l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
# i18n: "outgoing" is a keyword
dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
dest, branches = hg.parseurl(dest)
- revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, branches, [])
+ finally:
+ peer.close()
if revs:
revs = [repo.lookup(rev) for rev in revs]
other = hg.peer(repo, {}, dest)
repo.ui.pushbuffer()
outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
@@ -1127,11 +1131,15 @@ def remote(repo, subset, x):
if len(l) > 1:
# i18n: "remote" is a keyword
dest = getstring(l[1], _("remote requires a repository path"))
dest = repo.ui.expandpath(dest or 'default')
dest, branches = hg.parseurl(dest)
- revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
+ peer = repo.peer()
+ try:
+ revs, checkout = hg.addbranchrevs(repo, peer, branches, [])
+ finally:
+ peer.close()
if revs:
revs = [repo.lookup(rev) for rev in revs]
other = hg.peer(repo, {}, dest)
n = other.lookup(q)
if n in repo:
More information about the Mercurial-devel
mailing list