comparison mercurial/state.py @ 38104:36a5a1239a15

state: don't have a dict like interface for cmdstate class This patch changes the cmdstate class to stop having a dict like interface and delete the __nonzero__ function. After this patch, the save fuction takes a dict to store the data and read function returns a dict of the data stored. Differential Revision: https://phab.mercurial-scm.org/D3572
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 28 Mar 2018 16:31:16 +0530
parents a2f83661f721
children 18c6d8b565bf
comparison
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: