Mercurial > hg
comparison mercurial/revlogutils/nodemap.py @ 46468:83f037acf71a
nodemap: make `_persist_nodemap` a public function
I will like to have a utility function using which we can directly write out
nodemap for a repository without going through the recloning process. This
function seems like the one containing important pieces for that. Let's make it
public.
Differential Revision: https://phab.mercurial-scm.org/D9932
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sun, 31 Jan 2021 23:34:59 +0530 |
parents | d32e7ed81f4f |
children | 835aafb2543f |
comparison
equal
deleted
inserted
replaced
46467:45c3a263d5d1 | 46468:83f037acf71a |
---|---|
79 # we need to happen after the changelog finalization, in that use "cl-" | 79 # we need to happen after the changelog finalization, in that use "cl-" |
80 callback_id = b"nm-revlog-persistent-nodemap-%s" % revlog.nodemap_file | 80 callback_id = b"nm-revlog-persistent-nodemap-%s" % revlog.nodemap_file |
81 if tr.hasfinalize(callback_id): | 81 if tr.hasfinalize(callback_id): |
82 return # no need to register again | 82 return # no need to register again |
83 tr.addpending( | 83 tr.addpending( |
84 callback_id, lambda tr: _persist_nodemap(tr, revlog, pending=True) | 84 callback_id, lambda tr: persist_nodemap(tr, revlog, pending=True) |
85 ) | 85 ) |
86 tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog)) | 86 tr.addfinalize(callback_id, lambda tr: persist_nodemap(tr, revlog)) |
87 | 87 |
88 | 88 |
89 class _NoTransaction(object): | 89 class _NoTransaction(object): |
90 """transaction like object to update the nodemap outside a transaction""" | 90 """transaction like object to update the nodemap outside a transaction""" |
91 | 91 |
121 return # inlined revlog are too small for this to be relevant | 121 return # inlined revlog are too small for this to be relevant |
122 if revlog.nodemap_file is None: | 122 if revlog.nodemap_file is None: |
123 return # we do not use persistent_nodemap on this revlog | 123 return # we do not use persistent_nodemap on this revlog |
124 | 124 |
125 notr = _NoTransaction() | 125 notr = _NoTransaction() |
126 _persist_nodemap(notr, revlog) | 126 persist_nodemap(notr, revlog) |
127 for k in sorted(notr._postclose): | 127 for k in sorted(notr._postclose): |
128 notr._postclose[k](None) | 128 notr._postclose[k](None) |
129 | 129 |
130 | 130 |
131 def _persist_nodemap(tr, revlog, pending=False): | 131 def persist_nodemap(tr, revlog, pending=False): |
132 """Write nodemap data on disk for a given revlog""" | 132 """Write nodemap data on disk for a given revlog""" |
133 if getattr(revlog, 'filteredrevs', ()): | 133 if getattr(revlog, 'filteredrevs', ()): |
134 raise error.ProgrammingError( | 134 raise error.ProgrammingError( |
135 "cannot persist nodemap of a filtered changelog" | 135 "cannot persist nodemap of a filtered changelog" |
136 ) | 136 ) |