Patchwork [3,of,7,V4] rev-branch-cache: add a function to generate a part

login
register
mail settings
Submitter Boris Feld
Date March 16, 2018, 11:29 a.m.
Message ID <fa45b38924bec627efbd.1521199775@FB>
Download mbox | patch
Permalink /patch/29557/
State Accepted
Headers show

Comments

Boris Feld - March 16, 2018, 11:29 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1519230382 -3600
#      Wed Feb 21 17:26:22 2018 +0100
# Node ID fa45b38924bec627efbd1ff270e68943211a9c8d
# Parent  1eb0f8075f0d33fe0aebf7243eaf50db2b33496d
# EXP-Topic wire-rbc
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fa45b38924be
rev-branch-cache: add a function to generate a part

The function is able to produce a rbc part consumed by the function introduced
into previous changesets. More details on usage and impact in the next
changesets.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -147,6 +147,7 @@  preserve.
 
 from __future__ import absolute_import, division
 
+import collections
 import errno
 import os
 import re
@@ -1624,6 +1625,28 @@  def addparttagsfnodescache(repo, bundler
     if chunks:
         bundler.newpart('hgtagsfnodes', data=''.join(chunks))
 
+def addpartrevbranchcache(repo, bundler, outgoing):
+    # we include the rev branch cache for the bundle changeset
+    # (as an optional parts)
+    cache = repo.revbranchcache()
+    cl = repo.unfiltered().changelog
+    branchesdata = collections.defaultdict(lambda: (set(), set()))
+    for node in outgoing.missing:
+        branch, close = cache.branchinfo(cl.rev(node))
+        branchesdata[branch][close].add(node)
+
+    def generate():
+        for branch, (nodes, closed) in sorted(branchesdata.items()):
+            utf8branch = encoding.fromlocal(branch)
+            yield rbcstruct.pack(len(utf8branch), len(nodes), len(closed))
+            yield utf8branch
+            for n in sorted(nodes):
+                yield n
+            for n in sorted(closed):
+                yield n
+
+    bundler.newpart('cache:rev-branch-cache', data=generate())
+
 def buildobsmarkerspart(bundler, markers):
     """add an obsmarker part to the bundler with <markers>