From patchwork Thu Apr 3 17:45:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,4] localrepo: move the getbundle method in changegroup module From: Pierre-Yves David X-Patchwork-Id: 4207 Message-Id: <2e3ec879cd5b9e62daaf.1396547112@marginatus.alto.octopoid.net> To: mercurial-devel@selenic.com Cc: pierre-yves.david@ens-lyon.org Date: Thu, 03 Apr 2014 10:45:12 -0700 # HG changeset patch # User Pierre-Yves David # Date 1396388435 25200 # Tue Apr 01 14:40:35 2014 -0700 # Node ID 2e3ec879cd5b9e62daaf3cc9182bf2967db3cf60 # Parent 91c3538a3744bb1b2fa4f28ef587d7f076c0196a localrepo: move the getbundle method in changegroup module This is a gratuitous code move aimed at reducing the localrepo bloatness. The method had few callers, not enough to be kept in local repo. The peer API remains unchanged. diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -489,5 +489,25 @@ def getlocalbundle(repo, source, outgoin if not outgoing.missing: return None bundler = bundle10(repo, bundlecaps) return getsubset(repo, outgoing, bundler, source) +def getbundle(repo, source, heads=None, common=None, bundlecaps=None): + """Like changegroupsubset, but returns the set difference between the + ancestors of heads and the ancestors common. + + If heads is None, use the local heads. If common is None, use [nullid]. + + The nodes in common might not all be known locally due to the way the + current discovery protocol works. + """ + cl = repo.changelog + if common: + hasnode = cl.hasnode + common = [n for n in common if hasnode(n)] + else: + common = [nullid] + if not heads: + heads = cl.heads() + outgoing = discovery.outgoing(cl, common, heads) + return getlocalbundle(repo, source, outgoing, bundlecaps=bundlecaps) + diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1127,12 +1127,12 @@ def bundle(ui, repo, fname, dest=None, * if dest: raise util.Abort(_("--base is incompatible with specifying " "a destination")) common = [repo.lookup(rev) for rev in base] heads = revs and map(repo.lookup, revs) or revs - cg = repo.getbundle('bundle', heads=heads, common=common, - bundlecaps=bundlecaps) + cg = changegroup.getbundle(repo, 'bundle', heads=heads, common=common, + bundlecaps=bundlecaps) outgoing = None else: dest = ui.expandpath(dest or 'default-push', dest or 'default') dest, branches = hg.parseurl(dest, opts.get('branch')) other = hg.peer(repo, opts, dest) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -4,11 +4,11 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from node import hex, nullid, short from i18n import _ -import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview +import peer, changegroup, subrepo, pushkey, obsolete, repoview import changelog, dirstate, filelog, manifest, context, bookmarks, phases import lock as lockmod import transaction, store, encoding, exchange import scmutil, util, extensions, hook, error, revset import match as matchmod @@ -102,12 +102,12 @@ class localpeer(peer.peerrepository): def known(self, nodes): return self._repo.known(nodes) def getbundle(self, source, heads=None, common=None, bundlecaps=None): - return self._repo.getbundle(source, heads=heads, common=common, - bundlecaps=None) + return changegroup.getbundle(self._repo, source, heads=heads, + common=common, bundlecaps=None) # TODO We might want to move the next two calls into legacypeer and add # unbundle instead. def lock(self): @@ -1681,31 +1681,10 @@ class localrepository(object): pass def push(self, remote, force=False, revs=None, newbranch=False): return exchange.push(self, remote, force, revs, newbranch) - def getbundle(self, source, heads=None, common=None, bundlecaps=None): - """Like changegroupsubset, but returns the set difference between the - ancestors of heads and the ancestors common. - - If heads is None, use the local heads. If common is None, use [nullid]. - - The nodes in common might not all be known locally due to the way the - current discovery protocol works. - """ - cl = self.changelog - if common: - hasnode = cl.hasnode - common = [n for n in common if hasnode(n)] - else: - common = [nullid] - if not heads: - heads = cl.heads() - outgoing = discovery.outgoing(cl, common, heads) - return changegroup.getlocalbundle(self, source, outgoing, - bundlecaps=bundlecaps) - def changegroup(self, basenodes, source): # to avoid a race we use changegroupsubset() (issue1320) return changegroup.changegroupsubset(self, basenodes, self.heads(), source) diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -470,11 +470,11 @@ def getbundle(repo, proto, others): for k, v in opts.iteritems(): if k in ('heads', 'common'): opts[k] = decodelist(v) elif k == 'bundlecaps': opts[k] = set(v.split(',')) - cg = repo.getbundle('serve', **opts) + cg = changegroupmod.getbundle(repo, 'serve', **opts) return streamres(proto.groupchunks(cg)) def heads(repo, proto): h = repo.heads() return encodelist(h) + "\n"