changeset 32222:6068712cbf03

bundle2: move tagsfnodecache generation in a generic function This will help us reusing the logic for `hg bundle`.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 05 May 2017 17:28:52 +0200
parents 9dc36df78403
children d7f93ebbbbdf
files mercurial/bundle2.py mercurial/exchange.py
diffstat 2 files changed, 25 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Fri May 05 17:09:47 2017 +0200
+++ b/mercurial/bundle2.py	Fri May 05 17:28:52 2017 +0200
@@ -1375,6 +1375,30 @@
         part.addparam('nbchanges', str(cg.extras['clcount']),
                       mandatory=False)
 
+def addparttagsfnodescache(repo, bundler, outgoing):
+    # we include the tags fnode cache for the bundle changeset
+    # (as an optional parts)
+    cache = tags.hgtagsfnodescache(repo.unfiltered())
+    chunks = []
+
+    # .hgtags fnodes are only relevant for head changesets. While we could
+    # transfer values for all known nodes, there will likely be little to
+    # no benefit.
+    #
+    # We don't bother using a generator to produce output data because
+    # a) we only have 40 bytes per head and even esoteric numbers of heads
+    # consume little memory (1M heads is 40MB) b) we don't want to send the
+    # part if we don't have entries and knowing if we have entries requires
+    # cache lookups.
+    for node in outgoing.missingheads:
+        # Don't compute missing, as this may slow down serving.
+        fnode = cache.getfnode(node, computemissing=False)
+        if fnode is not None:
+            chunks.extend([node, fnode])
+
+    if chunks:
+        bundler.newpart('hgtagsfnodes', data=''.join(chunks))
+
 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None,
                 compopts=None):
     """Write a bundle file and return its filename.
--- a/mercurial/exchange.py	Fri May 05 17:09:47 2017 +0200
+++ b/mercurial/exchange.py	Fri May 05 17:28:52 2017 +0200
@@ -28,7 +28,6 @@
     scmutil,
     sslutil,
     streamclone,
-    tags,
     url as urlmod,
     util,
 )
@@ -1663,30 +1662,7 @@
         return
 
     outgoing = _computeoutgoing(repo, heads, common)
-
-    if not outgoing.missingheads:
-        return
-
-    cache = tags.hgtagsfnodescache(repo.unfiltered())
-    chunks = []
-
-    # .hgtags fnodes are only relevant for head changesets. While we could
-    # transfer values for all known nodes, there will likely be little to
-    # no benefit.
-    #
-    # We don't bother using a generator to produce output data because
-    # a) we only have 40 bytes per head and even esoteric numbers of heads
-    # consume little memory (1M heads is 40MB) b) we don't want to send the
-    # part if we don't have entries and knowing if we have entries requires
-    # cache lookups.
-    for node in outgoing.missingheads:
-        # Don't compute missing, as this may slow down serving.
-        fnode = cache.getfnode(node, computemissing=False)
-        if fnode is not None:
-            chunks.extend([node, fnode])
-
-    if chunks:
-        bundler.newpart('hgtagsfnodes', data=''.join(chunks))
+    bundle2.addparttagsfnodescache(repo, bundler, outgoing)
 
 def _getbookmarks(repo, **kwargs):
     """Returns bookmark to node mapping.