# HG changeset patch # User Pierre-Yves David # Date 1396387503 25200 # Node ID 24a44394862709ef29b00da62237b4276ea510f0 # Parent 7c1ed40e3325b373ac5e501cd96b08a2124b6e5b localrepo: move the changegroupsubset 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 -r 7c1ed40e3325 -r 24a443948627 hgext/shelve.py --- a/hgext/shelve.py Tue Apr 01 14:13:34 2014 -0700 +++ b/hgext/shelve.py Tue Apr 01 14:25:03 2014 -0700 @@ -25,7 +25,7 @@ from mercurial.node import nullid, nullrev, bin, hex from mercurial import changegroup, cmdutil, scmutil, phases, commands from mercurial import error, hg, mdiff, merge, patch, repair, util -from mercurial import templatefilters +from mercurial import templatefilters, changegroup from mercurial import lock as lockmod from hgext import rebase import errno @@ -227,7 +227,7 @@ fp.write('\0'.join(shelvedfiles)) bases = list(publicancestors(repo[node])) - cg = repo.changegroupsubset(bases, [node], 'shelve') + cg = changegroup.changegroupsubset(repo, bases, [node], 'shelve') changegroup.writebundle(cg, shelvedfile(repo, name, 'hg').filename(), 'HG10UN') cmdutil.export(repo, [node], diff -r 7c1ed40e3325 -r 24a443948627 mercurial/changegroup.py --- a/mercurial/changegroup.py Tue Apr 01 14:13:34 2014 -0700 +++ b/mercurial/changegroup.py Tue Apr 01 14:25:03 2014 -0700 @@ -6,9 +6,10 @@ # GNU General Public License version 2 or any later version. from i18n import _ -from node import nullrev, hex +from node import nullrev, nullid, hex import mdiff, util, dagutil import struct, os, bz2, zlib, tempfile +import discovery _BUNDLE10_DELTA_HEADER = "20s20s20s20s" @@ -453,3 +454,29 @@ _changegroupinfo(repo, csets, source) gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source) return unbundle10(util.chunkbuffer(gengroup), 'UN') + +def changegroupsubset(repo, roots, heads, source): + """Compute a changegroup consisting of all the nodes that are + descendants of any of the roots and ancestors of any of the heads. + Return a chunkbuffer object whose read() method will return + successive changegroup chunks. + + It is fairly complex as determining which filenodes and which + manifest nodes need to be included for the changeset to be complete + is non-trivial. + + Another wrinkle is doing the reverse, figuring out which changeset in + the changegroup a particular filenode or manifestnode belongs to. + """ + cl = repo.changelog + if not roots: + roots = [nullid] + # TODO: remove call to nodesbetween. + csets, roots, heads = cl.nodesbetween(roots, heads) + discbases = [] + for n in roots: + discbases.extend([p for p in cl.parents(n) if p != nullid]) + outgoing = discovery.outgoing(cl, discbases, heads) + bundler = bundle10(repo) + return getsubset(repo, outgoing, bundler, source) + diff -r 7c1ed40e3325 -r 24a443948627 mercurial/localrepo.py --- a/mercurial/localrepo.py Tue Apr 01 14:13:34 2014 -0700 +++ b/mercurial/localrepo.py Tue Apr 01 14:25:03 2014 -0700 @@ -143,7 +143,7 @@ return self._repo.changegroup(basenodes, source) def changegroupsubset(self, bases, heads, source): - return self._repo.changegroupsubset(bases, heads, source) + return changegroup.changegroupsubset(self._repo, bases, heads, source) class localrepository(object): @@ -1683,31 +1683,6 @@ def push(self, remote, force=False, revs=None, newbranch=False): return exchange.push(self, remote, force, revs, newbranch) - def changegroupsubset(self, roots, heads, source): - """Compute a changegroup consisting of all the nodes that are - descendants of any of the roots and ancestors of any of the heads. - Return a chunkbuffer object whose read() method will return - successive changegroup chunks. - - It is fairly complex as determining which filenodes and which - manifest nodes need to be included for the changeset to be complete - is non-trivial. - - Another wrinkle is doing the reverse, figuring out which changeset in - the changegroup a particular filenode or manifestnode belongs to. - """ - cl = self.changelog - if not roots: - roots = [nullid] - # TODO: remove call to nodesbetween. - csets, roots, heads = cl.nodesbetween(roots, heads) - discbases = [] - for n in roots: - discbases.extend([p for p in cl.parents(n) if p != nullid]) - outgoing = discovery.outgoing(cl, discbases, heads) - bundler = changegroup.bundle10(self) - return changegroup.getsubset(self, outgoing, bundler, source) - def getlocalbundle(self, source, outgoing, bundlecaps=None): """Like getbundle, but taking a discovery.outgoing as an argument. @@ -1741,7 +1716,8 @@ def changegroup(self, basenodes, source): # to avoid a race we use changegroupsubset() (issue1320) - return self.changegroupsubset(basenodes, self.heads(), source) + return changegroup.changegroupsubset(self, basenodes, self.heads(), + source) @unfilteredmethod def addchangegroup(self, source, srctype, url, emptyok=False): diff -r 7c1ed40e3325 -r 24a443948627 mercurial/repair.py --- a/mercurial/repair.py Tue Apr 01 14:13:34 2014 -0700 +++ b/mercurial/repair.py Tue Apr 01 14:25:03 2014 -0700 @@ -14,7 +14,7 @@ def _bundle(repo, bases, heads, node, suffix, compress=True): """create a bundle with the specified revisions as a backup""" - cg = repo.changegroupsubset(bases, heads, 'strip') + cg = changegroup.changegroupsubset(repo, bases, heads, 'strip') backupdir = repo.join("strip-backup") if not os.path.isdir(backupdir): os.mkdir(backupdir) diff -r 7c1ed40e3325 -r 24a443948627 mercurial/wireproto.py --- a/mercurial/wireproto.py Tue Apr 01 14:13:34 2014 -0700 +++ b/mercurial/wireproto.py Tue Apr 01 14:25:03 2014 -0700 @@ -585,7 +585,7 @@ def changegroupsubset(repo, proto, bases, heads): bases = decodelist(bases) heads = decodelist(heads) - cg = repo.changegroupsubset(bases, heads, 'serve') + cg = changegroupmod.changegroupsubset(repo, bases, heads, 'serve') return streamres(proto.groupchunks(cg)) @wireprotocommand('debugwireargs', 'one two *')