mercurial/manifest.py
changeset 24524 63b6031384fc
parent 24502 ecac0dd246a8
child 24525 e118f74d246f
equal deleted inserted replaced
24523:a4b81dbe73c1 24524:63b6031384fc
     9 import mdiff, parsers, error, revlog, util, scmutil
     9 import mdiff, parsers, error, revlog, util, scmutil
    10 import array, struct
    10 import array, struct
    11 
    11 
    12 propertycache = util.propertycache
    12 propertycache = util.propertycache
    13 
    13 
       
    14 def _parse(data):
       
    15     """Generates (path, node, flags) tuples from a manifest text"""
       
    16     # This method does a little bit of excessive-looking
       
    17     # precondition checking. This is so that the behavior of this
       
    18     # class exactly matches its C counterpart to try and help
       
    19     # prevent surprise breakage for anyone that develops against
       
    20     # the pure version.
       
    21     if data and data[-1] != '\n':
       
    22         raise ValueError('Manifest did not end in a newline.')
       
    23     prev = None
       
    24     for l in data.splitlines():
       
    25         if prev is not None and prev > l:
       
    26             raise ValueError('Manifest lines not in sorted order.')
       
    27         prev = l
       
    28         f, n = l.split('\0')
       
    29         if len(n) > 40:
       
    30             yield f, revlog.bin(n[:40]), n[40:]
       
    31         else:
       
    32             yield f, revlog.bin(n), ''
       
    33 
    14 class _lazymanifest(dict):
    34 class _lazymanifest(dict):
    15     """This is the pure implementation of lazymanifest.
    35     """This is the pure implementation of lazymanifest.
    16 
    36 
    17     It has not been optimized *at all* and is not lazy.
    37     It has not been optimized *at all* and is not lazy.
    18     """
    38     """
    19 
    39 
    20     def __init__(self, data):
    40     def __init__(self, data):
    21         # This init method does a little bit of excessive-looking
       
    22         # precondition checking. This is so that the behavior of this
       
    23         # class exactly matches its C counterpart to try and help
       
    24         # prevent surprise breakage for anyone that develops against
       
    25         # the pure version.
       
    26         if data and data[-1] != '\n':
       
    27             raise ValueError('Manifest did not end in a newline.')
       
    28         dict.__init__(self)
    41         dict.__init__(self)
    29         prev = None
    42         for f, n, fl in _parse(data):
    30         for l in data.splitlines():
    43             self[f] = n, fl
    31             if prev is not None and prev > l:
       
    32                 raise ValueError('Manifest lines not in sorted order.')
       
    33             prev = l
       
    34             f, n = l.split('\0')
       
    35             if len(n) > 40:
       
    36                 self[f] = revlog.bin(n[:40]), n[40:]
       
    37             else:
       
    38                 self[f] = revlog.bin(n), ''
       
    39 
    44 
    40     def __setitem__(self, k, v):
    45     def __setitem__(self, k, v):
    41         node, flag = v
    46         node, flag = v
    42         assert node is not None
    47         assert node is not None
    43         if len(node) > 21:
    48         if len(node) > 21:
   340         self._dir = dir
   345         self._dir = dir
   341         self._dirs = {}
   346         self._dirs = {}
   342         # Using _lazymanifest here is a little slower than plain old dicts
   347         # Using _lazymanifest here is a little slower than plain old dicts
   343         self._files = {}
   348         self._files = {}
   344         self._flags = {}
   349         self._flags = {}
   345         lm = _lazymanifest(text)
   350         for f, n, fl in _parse(text):
   346         for f, n, fl in lm.iterentries():
       
   347             self[f] = n
   351             self[f] = n
   348             if fl:
   352             if fl:
   349                 self.setflag(f, fl)
   353                 self.setflag(f, fl)
   350 
   354 
   351     def _subpath(self, path):
   355     def _subpath(self, path):