Patchwork [2,of,8] bundle2: add replies awareness to unbundlerecords

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2014, 10:05 p.m.
Message ID <45371a6d56d2fe379693.1397253959@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4285/
State Accepted
Headers show

Comments

Pierre-Yves David - April 11, 2014, 10:05 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1397229899 25200
#      Fri Apr 11 08:24:59 2014 -0700
# Node ID 45371a6d56d2fe379693c898d0f5374cd7a00f2b
# Parent  e5ac0c58e81ac8fc28a8a69ae0bc96b33acde5f4
bundle2: add replies awareness to unbundlerecords

We need an efficient was to handle bundle replies. The unbundle records class is
extended to carry such data.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -203,18 +203,25 @@  class unbundlerecords(object):
     """
 
     def __init__(self):
         self._categories = {}
         self._sequences = []
+        self._replies = {}
 
-    def add(self, category, entry):
+    def add(self, category, entry, inreplyto=None):
         """add a new record of a given category.
 
         The entry can then be retrieved in the list returned by
         self['category']."""
         self._categories.setdefault(category, []).append(entry)
         self._sequences.append((category, entry))
+        if inreplyto is not None:
+            self.getreplies(inreplyto).add(category, entry)
+
+    def getreplies(self, partid):
+        """get the subrecords that replies to a specific part"""
+        return self._replies.setdefault(partid, unbundlerecords())
 
     def __getitem__(self, cat):
         return tuple(self._categories.get(cat, ()))
 
     def __iter__(self):