comparison mercurial/bundle2.py @ 20996:ed3c5e18a047

bundle2: add reply awareness to unbundlerecords We need an efficient way to handle bundle replies. The unbundle records class is extended to carry such data.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 11 Apr 2014 08:24:59 -0700
parents e995d104c87f
children d7df4b7378ae
comparison
equal deleted inserted replaced
20995:e995d104c87f 20996:ed3c5e18a047
203 """ 203 """
204 204
205 def __init__(self): 205 def __init__(self):
206 self._categories = {} 206 self._categories = {}
207 self._sequences = [] 207 self._sequences = []
208 208 self._replies = {}
209 def add(self, category, entry): 209
210 def add(self, category, entry, inreplyto=None):
210 """add a new record of a given category. 211 """add a new record of a given category.
211 212
212 The entry can then be retrieved in the list returned by 213 The entry can then be retrieved in the list returned by
213 self['category'].""" 214 self['category']."""
214 self._categories.setdefault(category, []).append(entry) 215 self._categories.setdefault(category, []).append(entry)
215 self._sequences.append((category, entry)) 216 self._sequences.append((category, entry))
217 if inreplyto is not None:
218 self.getreplies(inreplyto).add(category, entry)
219
220 def getreplies(self, partid):
221 """get the subrecords that replies to a specific part"""
222 return self._replies.setdefault(partid, unbundlerecords())
216 223
217 def __getitem__(self, cat): 224 def __getitem__(self, cat):
218 return tuple(self._categories.get(cat, ())) 225 return tuple(self._categories.get(cat, ()))
219 226
220 def __iter__(self): 227 def __iter__(self):