##// END OF EJS Templates
nodemap: introduce an explicit class/object for the docket...
marmoute -
r44803:72c15641 default
parent child Browse files
Show More
@@ -36,11 +36,11 b' def persisted_data(revlog):'
36 36 if version != ONDISK_VERSION:
37 37 return None
38 38 offset += S_VERSION.size
39 (uuid_size,) = S_HEADER.unpack(pdata[offset : offset + S_HEADER.size])
39 (uid_size,) = S_HEADER.unpack(pdata[offset : offset + S_HEADER.size])
40 40 offset += S_HEADER.size
41 uid = pdata[offset : offset + uuid_size]
41 docket = NodeMapDocket(pdata[offset : offset + uid_size])
42 42
43 filename = _rawdata_filepath(revlog, uid)
43 filename = _rawdata_filepath(revlog, docket)
44 44 return revlog.opener.tryread(filename)
45 45
46 46
@@ -73,9 +73,9 b' def _persist_nodemap(tr, revlog):'
73 73 data = revlog.index.nodemap_data_all()
74 74 else:
75 75 data = persistent_data(revlog.index)
76 uid = _make_uid()
77 datafile = _rawdata_filepath(revlog, uid)
78 olds = _other_rawdata_filepath(revlog, uid)
76 target_docket = NodeMapDocket()
77 datafile = _rawdata_filepath(revlog, target_docket)
78 olds = _other_rawdata_filepath(revlog, target_docket)
79 79 if olds:
80 80 realvfs = getattr(revlog, '_realopener', revlog.opener)
81 81
@@ -92,7 +92,7 b' def _persist_nodemap(tr, revlog):'
92 92 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
93 93 # store vfs
94 94 with revlog.opener(revlog.nodemap_file, b'w', atomictemp=True) as fp:
95 fp.write(_serialize_docket(uid))
95 fp.write(target_docket.serialize())
96 96 # EXP-TODO: if the transaction abort, we should remove the new data and
97 97 # reinstall the old one.
98 98
@@ -135,25 +135,39 b' def _make_uid():'
135 135 return nodemod.hex(os.urandom(ID_SIZE))
136 136
137 137
138 def _serialize_docket(uid):
139 """return serialized bytes for a docket using the passed uid"""
140 data = []
141 data.append(S_VERSION.pack(ONDISK_VERSION))
142 data.append(S_HEADER.pack(len(uid)))
143 data.append(uid)
144 return b''.join(data)
138 class NodeMapDocket(object):
139 """metadata associated with persistent nodemap data
140
141 The persistent data may come from disk or be on their way to disk.
142 """
143
144 def __init__(self, uid=None):
145 if uid is None:
146 uid = _make_uid()
147 self.uid = uid
148
149 def copy(self):
150 return NodeMapDocket(uid=self.uid)
151
152 def serialize(self):
153 """return serialized bytes for a docket using the passed uid"""
154 data = []
155 data.append(S_VERSION.pack(ONDISK_VERSION))
156 data.append(S_HEADER.pack(len(self.uid)))
157 data.append(self.uid)
158 return b''.join(data)
145 159
146 160
147 def _rawdata_filepath(revlog, uid):
161 def _rawdata_filepath(revlog, docket):
148 162 """The (vfs relative) nodemap's rawdata file for a given uid"""
149 163 prefix = revlog.nodemap_file[:-2]
150 return b"%s-%s.nd" % (prefix, uid)
164 return b"%s-%s.nd" % (prefix, docket.uid)
151 165
152 166
153 def _other_rawdata_filepath(revlog, uid):
167 def _other_rawdata_filepath(revlog, docket):
154 168 prefix = revlog.nodemap_file[:-2]
155 169 pattern = re.compile(b"(^|/)%s-[0-9a-f]+\.nd$" % prefix)
156 new_file_path = _rawdata_filepath(revlog, uid)
170 new_file_path = _rawdata_filepath(revlog, docket)
157 171 new_file_name = revlog.opener.basename(new_file_path)
158 172 dirpath = revlog.opener.dirname(new_file_path)
159 173 others = []
General Comments 0
You need to be logged in to leave comments. Login now