mercurial/state.py
changeset 38104 36a5a1239a15
parent 38103 a2f83661f721
child 38105 18c6d8b565bf
equal deleted inserted replaced
38103:a2f83661f721 38104:36a5a1239a15
    44         fname is the file name in which data should be stored in .hg directory
    44         fname is the file name in which data should be stored in .hg directory
    45         opts is a dictionary of data of the statefile
    45         opts is a dictionary of data of the statefile
    46         """
    46         """
    47         self._repo = repo
    47         self._repo = repo
    48         self.fname = fname
    48         self.fname = fname
    49         if not opts:
       
    50             self.opts = {}
       
    51         else:
       
    52             self.opts = opts
       
    53 
    49 
    54     def __nonzero__(self):
    50     def read(self):
    55         return self.exists()
    51         """read the existing state file and return a dict of data stored"""
       
    52         return self._read()
    56 
    53 
    57     def __getitem__(self, key):
    54     def save(self, data):
    58         return self.opts[key]
       
    59 
       
    60     def __setitem__(self, key, value):
       
    61         updates = {key: value}
       
    62         self.opts.update(updates)
       
    63 
       
    64     def load(self):
       
    65         """load the existing state file into the class object"""
       
    66         op = self._read()
       
    67         self.opts.update(op)
       
    68 
       
    69     def addopts(self, opts):
       
    70         """add more key-value pairs to the data stored by the object"""
       
    71         self.opts.update(opts)
       
    72 
       
    73     def save(self):
       
    74         """write all the state data stored to .hg/<filename> file
    55         """write all the state data stored to .hg/<filename> file
    75 
    56 
    76         we use third-party library cbor to serialize data to write in the file.
    57         we use third-party library cbor to serialize data to write in the file.
    77         """
    58         """
    78         with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
    59         with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp: