localrepo: move the changegroupsubset method in changegroup module
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 01 Apr 2014 14:25:03 -0700
changeset 20927 24a443948627
parent 20926 7c1ed40e3325
child 20928 91b47139d0cb
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.
hgext/shelve.py
mercurial/changegroup.py
mercurial/localrepo.py
mercurial/repair.py
mercurial/wireproto.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],
--- 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)
+
--- 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):
--- 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)
--- 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 *')