comparison mercurial/revlogutils/nodemap.py @ 47164:04f2f94836a5

revlog: rename `nodemap_file` to `_nodemap_file` Same reasoning as for `indexfile and datafile`, lets hide these implementation details. Differential Revision: https://phab.mercurial-scm.org/D10590
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:25:01 +0200
parents 09338a2d5c14
children 4f38ada3fc26
comparison
equal deleted inserted replaced
47163:6bc7c467a7d1 47164:04f2f94836a5
26 raise error.RevlogError(b'unknown node: %s' % x) 26 raise error.RevlogError(b'unknown node: %s' % x)
27 27
28 28
29 def persisted_data(revlog): 29 def persisted_data(revlog):
30 """read the nodemap for a revlog from disk""" 30 """read the nodemap for a revlog from disk"""
31 if revlog.nodemap_file is None: 31 if revlog._nodemap_file is None:
32 return None 32 return None
33 pdata = revlog.opener.tryread(revlog.nodemap_file) 33 pdata = revlog.opener.tryread(revlog._nodemap_file)
34 if not pdata: 34 if not pdata:
35 return None 35 return None
36 offset = 0 36 offset = 0
37 (version,) = S_VERSION.unpack(pdata[offset : offset + S_VERSION.size]) 37 (version,) = S_VERSION.unpack(pdata[offset : offset + S_VERSION.size])
38 if version != ONDISK_VERSION: 38 if version != ONDISK_VERSION:
75 75
76 (only actually persist the nodemap if this is relevant for this revlog) 76 (only actually persist the nodemap if this is relevant for this revlog)
77 """ 77 """
78 if revlog._inline: 78 if revlog._inline:
79 return # inlined revlog are too small for this to be relevant 79 return # inlined revlog are too small for this to be relevant
80 if revlog.nodemap_file is None: 80 if revlog._nodemap_file is None:
81 return # we do not use persistent_nodemap on this revlog 81 return # we do not use persistent_nodemap on this revlog
82 82
83 # we need to happen after the changelog finalization, in that use "cl-" 83 # we need to happen after the changelog finalization, in that use "cl-"
84 callback_id = b"nm-revlog-persistent-nodemap-%s" % revlog.nodemap_file 84 callback_id = b"nm-revlog-persistent-nodemap-%s" % revlog._nodemap_file
85 if tr.hasfinalize(callback_id): 85 if tr.hasfinalize(callback_id):
86 return # no need to register again 86 return # no need to register again
87 tr.addpending( 87 tr.addpending(
88 callback_id, lambda tr: persist_nodemap(tr, revlog, pending=True) 88 callback_id, lambda tr: persist_nodemap(tr, revlog, pending=True)
89 ) 89 )
121 To be used for updating the nodemap on disk outside of a normal transaction 121 To be used for updating the nodemap on disk outside of a normal transaction
122 setup (eg, `debugupdatecache`). 122 setup (eg, `debugupdatecache`).
123 """ 123 """
124 if revlog._inline: 124 if revlog._inline:
125 return # inlined revlog are too small for this to be relevant 125 return # inlined revlog are too small for this to be relevant
126 if revlog.nodemap_file is None: 126 if revlog._nodemap_file is None:
127 return # we do not use persistent_nodemap on this revlog 127 return # we do not use persistent_nodemap on this revlog
128 128
129 notr = _NoTransaction() 129 notr = _NoTransaction()
130 persist_nodemap(notr, revlog) 130 persist_nodemap(notr, revlog)
131 for k in sorted(notr._postclose): 131 for k in sorted(notr._postclose):
132 notr._postclose[k](None) 132 notr._postclose[k](None)
133 133
134 134
135 def delete_nodemap(tr, repo, revlog): 135 def delete_nodemap(tr, repo, revlog):
136 """Delete nodemap data on disk for a given revlog""" 136 """ Delete nodemap data on disk for a given revlog"""
137 if revlog.nodemap_file is None: 137 if revlog._nodemap_file is None:
138 msg = "calling persist nodemap on a revlog without the feature enabled" 138 msg = "calling persist nodemap on a revlog without the feature enabled"
139 raise error.ProgrammingError(msg) 139 raise error.ProgrammingError(msg)
140 repo.svfs.unlink(revlog.nodemap_file) 140 repo.svfs.unlink(revlog._nodemap_file)
141 141
142 142
143 def persist_nodemap(tr, revlog, pending=False, force=False): 143 def persist_nodemap(tr, revlog, pending=False, force=False):
144 """Write nodemap data on disk for a given revlog""" 144 """Write nodemap data on disk for a given revlog"""
145 if getattr(revlog, 'filteredrevs', ()): 145 if getattr(revlog, 'filteredrevs', ()):
146 raise error.ProgrammingError( 146 raise error.ProgrammingError(
147 "cannot persist nodemap of a filtered changelog" 147 "cannot persist nodemap of a filtered changelog"
148 ) 148 )
149 if revlog.nodemap_file is None: 149 if revlog._nodemap_file is None:
150 if force: 150 if force:
151 revlog.nodemap_file = get_nodemap_file(revlog) 151 revlog._nodemap_file = get_nodemap_file(revlog)
152 else: 152 else:
153 msg = "calling persist nodemap on a revlog without the feature enabled" 153 msg = "calling persist nodemap on a revlog without the feature enabled"
154 raise error.ProgrammingError(msg) 154 raise error.ProgrammingError(msg)
155 155
156 can_incremental = util.safehasattr(revlog.index, "nodemap_data_incremental") 156 can_incremental = util.safehasattr(revlog.index, "nodemap_data_incremental")
223 target_docket.data_length = len(data) 223 target_docket.data_length = len(data)
224 target_docket.tip_rev = revlog.tiprev() 224 target_docket.tip_rev = revlog.tiprev()
225 target_docket.tip_node = revlog.node(target_docket.tip_rev) 225 target_docket.tip_node = revlog.node(target_docket.tip_rev)
226 # EXP-TODO: if this is a cache, this should use a cache vfs, not a 226 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
227 # store vfs 227 # store vfs
228 file_path = revlog.nodemap_file 228 file_path = revlog._nodemap_file
229 if pending: 229 if pending:
230 file_path += b'.a' 230 file_path += b'.a'
231 tr.registertmp(file_path) 231 tr.registertmp(file_path)
232 else: 232 else:
233 tr.addbackup(file_path) 233 tr.addbackup(file_path)
246 246
247 def cleanup(tr): 247 def cleanup(tr):
248 for oldfile in olds: 248 for oldfile in olds:
249 realvfs.tryunlink(oldfile) 249 realvfs.tryunlink(oldfile)
250 250
251 callback_id = b"revlog-cleanup-nodemap-%s" % revlog.nodemap_file 251 callback_id = b"revlog-cleanup-nodemap-%s" % revlog._nodemap_file
252 tr.addpostclose(callback_id, cleanup) 252 tr.addpostclose(callback_id, cleanup)
253 253
254 254
255 ### Nodemap docket file 255 ### Nodemap docket file
256 # 256 #