Patchwork [2,of,7,V3] revbranchcache: add a bundle2 handler for a rbc part

login
register
mail settings
Submitter Boris Feld
Date March 15, 2018, 2:30 p.m.
Message ID <c66ccb6f6ec80d539f2b.1521124252@FB>
Download mbox | patch
Permalink /patch/29537/
State Superseded
Headers show

Comments

Boris Feld - March 15, 2018, 2:30 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1519230904 -3600
#      Wed Feb 21 17:35:04 2018 +0100
# Node ID c66ccb6f6ec80d539f2bed0724cca125624d2807
# Parent  ec581b3db32120b39cd7c4b9019955c0b0374d60
# EXP-Topic wire-rbc
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c66ccb6f6ec8
revbranchcache: add a bundle2 handler for a rbc part

We add the necessary bit to process a part containing rev-branch-cache
information. The local rev branch cache is then updated with the received
information.

Computing branch cache can become a significant part of the time spent pulling.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -158,6 +158,7 @@  from .i18n import _
 from . import (
     bookmarks,
     changegroup,
+    encoding,
     error,
     node as nodemod,
     obsolete,
@@ -2129,6 +2130,40 @@  def handlehgtagsfnodes(op, inpart):
     cache.write()
     op.ui.debug('applied %i hgtags fnodes cache entries\n' % count)
 
+rbcstruct = struct.Struct('>III')
+
+@parthandler('cache:rev-branch-cache')
+def handlerbc(op, inpart):
+    """receive a rev-branch-cache payload and update the local cache
+
+    The payload is a series of data related to each branch
+
+    1) branch name length
+    2) number of open heads
+    3) number of closed heads
+    4) open heads nodes
+    5) closed heads nodes
+    """
+    total = 0
+    rawheader = inpart.read(rbcstruct.size)
+    cache = op.repo.revbranchcache()
+    cl = op.repo.unfiltered().changelog
+    while rawheader:
+        header = rbcstruct.unpack(rawheader)
+        total += header[1] + header[2]
+        utf8branch = inpart.read(header[0])
+        branch = encoding.tolocal(utf8branch)
+        for x in xrange(header[1]):
+            node = inpart.read(20)
+            rev = cl.rev(node)
+            cache.setdata(branch, rev, node, False)
+        for x in xrange(header[2]):
+            node = inpart.read(20)
+            rev = cl.rev(node)
+            cache.setdata(branch, rev, node, True)
+        rawheader = inpart.read(rbcstruct.size)
+    cache.write()
+
 @parthandler('pushvars')
 def bundle2getvars(op, part):
     '''unbundle a bundle2 containing shellvars on the server'''