mercurial/bundle2.py
changeset 20949 571f2903ff1e
parent 20948 329cd74b52bd
child 20950 c7ceae0faf69
equal deleted inserted replaced
20948:329cd74b52bd 20949:571f2903ff1e
   181         assert lparttype not in parthandlermapping
   181         assert lparttype not in parthandlermapping
   182         parthandlermapping[lparttype] = func
   182         parthandlermapping[lparttype] = func
   183         return func
   183         return func
   184     return _decorator
   184     return _decorator
   185 
   185 
       
   186 class unbundlerecords(object):
       
   187     """keep record of what happens during and unbundle
       
   188 
       
   189     New records are added using `records.add('cat', obj)`. Where 'cat' is a
       
   190     category of record and obj is an arbitraty object.
       
   191 
       
   192     `records['cat']` will return all entries of this category 'cat'.
       
   193 
       
   194     Iterating on the object itself will yield `('category', obj)` tuples
       
   195     for all entries.
       
   196 
       
   197     All iterations happens in chronological order.
       
   198     """
       
   199 
       
   200     def __init__(self):
       
   201         self._categories = {}
       
   202         self._sequences = []
       
   203 
       
   204     def add(self, category, entry):
       
   205         """add a new record of a given category.
       
   206 
       
   207         The entry can then be retrieved in the list returned by
       
   208         self['category']."""
       
   209         self._categories.setdefault(category, []).append(entry)
       
   210         self._sequences.append((category, entry))
       
   211 
       
   212     def __getitem__(self, cat):
       
   213         return tuple(self._categories.get(cat, ()))
       
   214 
       
   215     def __iter__(self):
       
   216         return iter(self._sequences)
       
   217 
       
   218     def __len__(self):
       
   219         return len(self._sequences)
       
   220 
       
   221     def __nonzero__(self):
       
   222         return bool(self._sequences)
       
   223 
   186 class bundleoperation(object):
   224 class bundleoperation(object):
   187     """an object that represents a single bundling process
   225     """an object that represents a single bundling process
   188 
   226 
   189     Its purpose is to carry unbundle-related objects and states.
   227     Its purpose is to carry unbundle-related objects and states.
   190 
   228 
   200     """
   238     """
   201 
   239 
   202     def __init__(self, repo):
   240     def __init__(self, repo):
   203         self.repo = repo
   241         self.repo = repo
   204         self.ui = repo.ui
   242         self.ui = repo.ui
       
   243         self.records = unbundlerecords()
   205 
   244 
   206 def processbundle(repo, unbundler):
   245 def processbundle(repo, unbundler):
   207     """This function process a bundle, apply effect to/from a repo
   246     """This function process a bundle, apply effect to/from a repo
   208 
   247 
   209     It iterates over each part then searches for and uses the proper handling
   248     It iterates over each part then searches for and uses the proper handling
   240             handler(op, part)
   279             handler(op, part)
   241     except Exception:
   280     except Exception:
   242         for part in iterparts:
   281         for part in iterparts:
   243             pass # consume the bundle content
   282             pass # consume the bundle content
   244         raise
   283         raise
       
   284     return op
   245 
   285 
   246 class bundle20(object):
   286 class bundle20(object):
   247     """represent an outgoing bundle2 container
   287     """represent an outgoing bundle2 container
   248 
   288 
   249     Use the `addparam` method to add stream level parameter. and `addpart` to
   289     Use the `addparam` method to add stream level parameter. and `addpart` to