Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlogutils/nodemap.py @ 44351:5962fd0d1045
nodemap: write nodemap data on disk
Let us start writing data on disk (so that we can read it from there later).
This series of changeset is going to focus first on having data on disk and
updating it.
Right now the data is written right next to the revlog data, in the store. We
might move it to cache (with proper cache validation mechanism) later, but for
now revlog have a storevfs instance and it is simpler to us it. The right
location for this data is not the focus of this series.
Differential Revision: https://phab.mercurial-scm.org/D7835
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 15 Jan 2020 15:47:21 +0100 |
parents | c577bb4a04d4 |
children | 6c07480d6659 |
comparison
equal
deleted
inserted
replaced
44350:c577bb4a04d4 | 44351:5962fd0d1045 |
---|---|
18 | 18 |
19 | 19 |
20 class NodeMap(dict): | 20 class NodeMap(dict): |
21 def __missing__(self, x): | 21 def __missing__(self, x): |
22 raise error.RevlogError(b'unknown node: %s' % x) | 22 raise error.RevlogError(b'unknown node: %s' % x) |
23 | |
24 | |
25 def setup_persistent_nodemap(tr, revlog): | |
26 """Install whatever is needed transaction side to persist a nodemap on disk | |
27 | |
28 (only actually persist the nodemap if this is relevant for this revlog) | |
29 """ | |
30 if revlog.nodemap_file is None: | |
31 return # we do not use persistent_nodemap on this revlog | |
32 callback_id = b"revlog-persistent-nodemap-%s" % revlog.nodemap_file | |
33 if tr.hasfinalize(callback_id): | |
34 return # no need to register again | |
35 tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog)) | |
36 | |
37 | |
38 def _persist_nodemap(tr, revlog): | |
39 """Write nodemap data on disk for a given revlog | |
40 """ | |
41 if getattr(revlog, 'filteredrevs', ()): | |
42 raise error.ProgrammingError( | |
43 "cannot persist nodemap of a filtered changelog" | |
44 ) | |
45 if revlog.nodemap_file is None: | |
46 msg = "calling persist nodemap on a revlog without the feature enableb" | |
47 raise error.ProgrammingError(msg) | |
48 data = persistent_data(revlog.index) | |
49 # EXP-TODO: if this is a cache, this should use a cache vfs, not a | |
50 # store vfs | |
51 with revlog.opener(revlog.nodemap_file, b'w') as f: | |
52 f.write(data) | |
53 # EXP-TODO: if the transaction abort, we should remove the new data and | |
54 # reinstall the old one. (This will be simpler when the file format get a | |
55 # bit more advanced) | |
23 | 56 |
24 | 57 |
25 ### Nodemap Trie | 58 ### Nodemap Trie |
26 # | 59 # |
27 # This is a simple reference implementation to compute and persist a nodemap | 60 # This is a simple reference implementation to compute and persist a nodemap |