diff mercurial/bundle2.py @ 25401:d29201352af7

bundle2: part handler for processing .hgtags fnodes mappings .hgtags fnodes cache entries can be expensive to compute, especially if there are hundreds of even thousands of them. This patch implements support for receiving a bundle2 part that contains a mapping of changeset to .hgtags fnodes. An upcoming patch will teach the server to send this part, allowing clients to bypass having to redundantly compute these values. A number of tests changed due to the client advertising the "hgtagsfnodes" capability.
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 01 Jun 2015 20:23:22 -0700
parents 7c60a42265fb
children 6de96cb31176
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Jun 02 19:58:06 2015 -0700
+++ b/mercurial/bundle2.py	Mon Jun 01 20:23:22 2015 -0700
@@ -156,7 +156,7 @@
 import url
 import re
 
-import changegroup, error
+import changegroup, error, tags
 from i18n import _
 
 _pack = struct.pack
@@ -1110,6 +1110,7 @@
                 'pushkey': (),
                 'digests': tuple(sorted(util.DIGESTS.keys())),
                 'remote-changegroup': ('http', 'https'),
+                'hgtagsfnodes': (),
                }
 
 def getrepocaps(repo, allowpushback=False):
@@ -1360,3 +1361,24 @@
     ret = int(inpart.params['new'])
     partid = int(inpart.params['in-reply-to'])
     op.records.add('obsmarkers', {'new': ret}, partid)
+
+@parthandler('hgtagsfnodes')
+def handlehgtagsfnodes(op, inpart):
+    """Applies .hgtags fnodes cache entries to the local repo.
+
+    Payload is pairs of 20 byte changeset nodes and filenodes.
+    """
+    cache = tags.hgtagsfnodescache(op.repo.unfiltered())
+
+    count = 0
+    while True:
+        node = inpart.read(20)
+        fnode = inpart.read(20)
+        if len(node) < 20 or len(fnode) < 20:
+            op.ui.debug('received incomplete .hgtags fnodes data, ignoring\n')
+            break
+        cache.setfnode(node, fnode)
+        count += 1
+
+    cache.write()
+    op.ui.debug('applied %i hgtags fnodes cache entries\n' % count)