Patchwork [2,of,4] localrepo: move the changegroup method in changegroup module

login
register
mail settings
Submitter Pierre-Yves David
Date April 3, 2014, 5:45 p.m.
Message ID <77914531a39fa05a5a2c.1396547113@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4208/
State Accepted
Commit de60ca3a390e5aa8d5e6bced6dca4807b681401b
Headers show

Comments

Pierre-Yves David - April 3, 2014, 5:45 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396390107 25200
#      Tue Apr 01 15:08:27 2014 -0700
# Node ID 77914531a39fa05a5a2c2f9917dfe4ab1ca40261
# Parent  2e3ec879cd5b9e62daaf3cc9182bf2967db3cf60
localrepo: move the changegroup 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 stay unchanged.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -509,5 +509,9 @@  def getbundle(repo, source, heads=None, 
     if not heads:
         heads = cl.heads()
     outgoing = discovery.outgoing(cl, common, heads)
     return getlocalbundle(repo, source, outgoing, bundlecaps=bundlecaps)
 
+def changegroup(repo, basenodes, source):
+    # to avoid a race we use changegroupsubset() (issue1320)
+    return changegroupsubset(repo, basenodes, repo.heads(), source)
+
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -138,11 +138,11 @@  class locallegacypeer(localpeer):
 
     def between(self, pairs):
         return self._repo.between(pairs)
 
     def changegroup(self, basenodes, source):
-        return self._repo.changegroup(basenodes, source)
+        return changegroup.changegroup(self._repo, basenodes, source)
 
     def changegroupsubset(self, bases, heads, source):
         return changegroup.changegroupsubset(self._repo, bases, heads, source)
 
 class localrepository(object):
@@ -1681,15 +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 changegroup(self, basenodes, source):
-        # to avoid a race we use changegroupsubset() (issue1320)
-        return changegroup.changegroupsubset(self, basenodes, self.heads(),
-                                             source)
-
     @unfilteredmethod
     def addchangegroup(self, source, srctype, url, emptyok=False):
         """Add the changegroup returned by source.read() to this repo.
         srctype is a string like 'push', 'pull', or 'unbundle'.  url is
         the URL of the repo where this changegroup is coming from.
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -449,11 +449,11 @@  def _capabilities(repo, proto):
 def capabilities(repo, proto):
     return ' '.join(_capabilities(repo, proto))
 
 def changegroup(repo, proto, roots):
     nodes = decodelist(roots)
-    cg = repo.changegroup(nodes, 'serve')
+    cg = changegroupmod.changegroup(repo, nodes, 'serve')
     return streamres(proto.groupchunks(cg))
 
 def changegroupsubset(repo, proto, bases, heads):
     bases = decodelist(bases)
     heads = decodelist(heads)