changeset 20930:4a987060d97e

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 01 Apr 2014 14:40:35 -0700
parents afe0b48ef2d7
children de60ca3a390e
files mercurial/changegroup.py mercurial/commands.py mercurial/localrepo.py mercurial/wireproto.py
diffstat 4 files changed, 26 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Thu Apr 03 12:59:12 2014 -0500
+++ b/mercurial/changegroup.py	Tue Apr 01 14:40:35 2014 -0700
@@ -490,3 +490,23 @@
     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)
+
--- a/mercurial/commands.py	Thu Apr 03 12:59:12 2014 -0500
+++ b/mercurial/commands.py	Tue Apr 01 14:40:35 2014 -0700
@@ -1129,8 +1129,8 @@
                                "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')
--- a/mercurial/localrepo.py	Thu Apr 03 12:59:12 2014 -0500
+++ b/mercurial/localrepo.py	Tue Apr 01 14:40:35 2014 -0700
@@ -6,7 +6,7 @@
 # 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
@@ -104,8 +104,8 @@
         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.
@@ -1683,27 +1683,6 @@
     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(),
--- a/mercurial/wireproto.py	Thu Apr 03 12:59:12 2014 -0500
+++ b/mercurial/wireproto.py	Tue Apr 01 14:40:35 2014 -0700
@@ -602,7 +602,7 @@
             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))
 
 @wireprotocommand('heads')