Patchwork [2,of,5,(4,more,to,go)] localrepo: move the _changegroupsubset method in changegroup module

login
register
mail settings
Submitter Pierre-Yves David
Date April 2, 2014, 5:59 p.m.
Message ID <51dedd9e405716d7818d.1396461543@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4195/
State Accepted
Commit 5174c48ed8d8d1dcfccd3f70ad0d5f9b8dd9fa3a
Headers show

Comments

Pierre-Yves David - April 2, 2014, 5:59 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396385995 25200
#      Tue Apr 01 13:59:55 2014 -0700
# Node ID 51dedd9e405716d7818dcf0f2636b51da5165243
# Parent  c7d0eb8fe4afcb5e3deeb0080a6c32b1a3e20377
localrepo: move the _changegroupsubset method in changegroup module

This is a gratuitous code move aimed at reducing the localrepo bloatness.

The method had 3 callers total, far too few for being kept in local repo.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -426,5 +426,22 @@  class bundle10(object):
         yield meta
         yield delta
     def builddeltaheader(self, node, p1n, p2n, basenode, linknode):
         # do nothing with basenode, it is implicitly the previous one in HG10
         return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
+
+def getsubset(repo, outgoing, bundler, source, fastpath=False):
+    repo = repo.unfiltered()
+    commonrevs = outgoing.common
+    csets = outgoing.missing
+    heads = outgoing.missingheads
+    # We go through the fast path if we get told to, or if all (unfiltered
+    # heads have been requested (since we then know there all linkrevs will
+    # be pulled by the client).
+    heads.sort()
+    fastpathlinkrev = fastpath or (
+            repo.filtername is None and heads == sorted(repo.heads()))
+
+    repo.hook('preoutgoing', throw=True, source=source)
+    repo.changegroupinfo(csets, source)
+    gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source)
+    return unbundle10(util.chunkbuffer(gengroup), 'UN')
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -179,14 +179,15 @@  def _pushchangeset(pushop):
     if pushop.revs is None and not (outgoing.excluded
                             or pushop.repo.changelog.filteredrevs):
         # push everything,
         # use the fast path, no race possible on push
         bundler = changegroup.bundle10(pushop.repo, bundlecaps)
-        cg = pushop.repo._changegroupsubset(outgoing,
-                                            bundler,
-                                            'push',
-                                            fastpath=True)
+        cg = changegroup.getsubset(pushop.repo,
+                                           outgoing,
+                                           bundler,
+                                           'push',
+                                           fastpath=True)
     else:
         cg = pushop.repo.getlocalbundle('push', outgoing, bundlecaps)
 
     # apply changegroup to remote
     if unbundle:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1708,21 +1708,21 @@  class localrepository(object):
         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 self._changegroupsubset(outgoing, bundler, source)
+        return changegroup.getsubset(self, outgoing, bundler, source)
 
     def getlocalbundle(self, source, outgoing, bundlecaps=None):
         """Like getbundle, but taking a discovery.outgoing as an argument.
 
         This is only implemented for local repos and reuses potentially
         precomputed sets in outgoing."""
         if not outgoing.missing:
             return None
         bundler = changegroup.bundle10(self, bundlecaps)
-        return self._changegroupsubset(outgoing, bundler, source)
+        return changegroup.getsubset(self, outgoing, bundler, source)
 
     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.
 
@@ -1741,28 +1741,10 @@  class localrepository(object):
             heads = cl.heads()
         return self.getlocalbundle(source,
                                    discovery.outgoing(cl, common, heads),
                                    bundlecaps=bundlecaps)
 
-    @unfilteredmethod
-    def _changegroupsubset(self, outgoing, bundler, source,
-                           fastpath=False):
-        commonrevs = outgoing.common
-        csets = outgoing.missing
-        heads = outgoing.missingheads
-        # We go through the fast path if we get told to, or if all (unfiltered
-        # heads have been requested (since we then know there all linkrevs will
-        # be pulled by the client).
-        heads.sort()
-        fastpathlinkrev = fastpath or (
-                self.filtername is None and heads == sorted(self.heads()))
-
-        self.hook('preoutgoing', throw=True, source=source)
-        self.changegroupinfo(csets, source)
-        gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source)
-        return changegroup.unbundle10(util.chunkbuffer(gengroup), 'UN')
-
     def changegroup(self, basenodes, source):
         # to avoid a race we use changegroupsubset() (issue1320)
         return self.changegroupsubset(basenodes, self.heads(), source)
 
     @unfilteredmethod