##// 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 if version != ONDISK_VERSION:
36 if version != ONDISK_VERSION:
37 return None
37 return None
38 offset += S_VERSION.size
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 offset += S_HEADER.size
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 return revlog.opener.tryread(filename)
44 return revlog.opener.tryread(filename)
45
45
46
46
@@ -73,9 +73,9 b' def _persist_nodemap(tr, revlog):'
73 data = revlog.index.nodemap_data_all()
73 data = revlog.index.nodemap_data_all()
74 else:
74 else:
75 data = persistent_data(revlog.index)
75 data = persistent_data(revlog.index)
76 uid = _make_uid()
76 target_docket = NodeMapDocket()
77 datafile = _rawdata_filepath(revlog, uid)
77 datafile = _rawdata_filepath(revlog, target_docket)
78 olds = _other_rawdata_filepath(revlog, uid)
78 olds = _other_rawdata_filepath(revlog, target_docket)
79 if olds:
79 if olds:
80 realvfs = getattr(revlog, '_realopener', revlog.opener)
80 realvfs = getattr(revlog, '_realopener', revlog.opener)
81
81
@@ -92,7 +92,7 b' def _persist_nodemap(tr, revlog):'
92 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
92 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
93 # store vfs
93 # store vfs
94 with revlog.opener(revlog.nodemap_file, b'w', atomictemp=True) as fp:
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 # EXP-TODO: if the transaction abort, we should remove the new data and
96 # EXP-TODO: if the transaction abort, we should remove the new data and
97 # reinstall the old one.
97 # reinstall the old one.
98
98
@@ -135,25 +135,39 b' def _make_uid():'
135 return nodemod.hex(os.urandom(ID_SIZE))
135 return nodemod.hex(os.urandom(ID_SIZE))
136
136
137
137
138 def _serialize_docket(uid):
138 class NodeMapDocket(object):
139 """return serialized bytes for a docket using the passed uid"""
139 """metadata associated with persistent nodemap data
140 data = []
140
141 data.append(S_VERSION.pack(ONDISK_VERSION))
141 The persistent data may come from disk or be on their way to disk.
142 data.append(S_HEADER.pack(len(uid)))
142 """
143 data.append(uid)
143
144 return b''.join(data)
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 """The (vfs relative) nodemap's rawdata file for a given uid"""
162 """The (vfs relative) nodemap's rawdata file for a given uid"""
149 prefix = revlog.nodemap_file[:-2]
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 prefix = revlog.nodemap_file[:-2]
168 prefix = revlog.nodemap_file[:-2]
155 pattern = re.compile(b"(^|/)%s-[0-9a-f]+\.nd$" % prefix)
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 new_file_name = revlog.opener.basename(new_file_path)
171 new_file_name = revlog.opener.basename(new_file_path)
158 dirpath = revlog.opener.dirname(new_file_path)
172 dirpath = revlog.opener.dirname(new_file_path)
159 others = []
173 others = []
General Comments 0
You need to be logged in to leave comments. Login now