Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/rewrite.py @ 47473:5045ba2a3afd
censor: split the core of the logic into its own function
We now have a "generic" rewrite function (only able to do censoring for now)
and a thin wrapper that implement the `censor` API with it.
We are now ready to start incorporating strip specific changes.
Differential Revision: https://phab.mercurial-scm.org/D10904
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 22 Jun 2021 22:52:08 +0200 |
parents | c81a5297f185 |
children | b30a53ffbf9b |
comparison
equal
deleted
inserted
replaced
47472:c81a5297f185 | 47473:5045ba2a3afd |
---|---|
125 rl._loadindex() | 125 rl._loadindex() |
126 | 126 |
127 | 127 |
128 def v2_censor(revlog, tr, censornode, tombstone=b''): | 128 def v2_censor(revlog, tr, censornode, tombstone=b''): |
129 """censors a revision in a "version 2" revlog""" | 129 """censors a revision in a "version 2" revlog""" |
130 # General principle | |
131 # | |
132 # We create new revlog files (index/data/sidedata) to copy the content of | |
133 # the existing data without the censored data. | |
134 # | |
135 # We need to recompute new delta for any revision that used the censored | |
136 # revision as delta base. As the cumulative size of the new delta may be | |
137 # large, we store them in a temporary file until they are stored in their | |
138 # final destination. | |
139 # | |
140 # All data before the censored data can be blindly copied. The rest needs | |
141 # to be copied as we go and the associated index entry needs adjustement. | |
142 | |
143 assert revlog._format_version != REVLOGV0, revlog._format_version | 130 assert revlog._format_version != REVLOGV0, revlog._format_version |
144 assert revlog._format_version != REVLOGV1, revlog._format_version | 131 assert revlog._format_version != REVLOGV1, revlog._format_version |
145 | 132 |
133 censor_revs = {revlog.rev(censornode)} | |
134 _rewrite_v2(revlog, tr, censor_revs, tombstone) | |
135 | |
136 | |
137 def _rewrite_v2(revlog, tr, censor_revs, tombstone=b''): | |
138 """rewrite a revlog to censor some of its content | |
139 | |
140 General principle | |
141 | |
142 We create new revlog files (index/data/sidedata) to copy the content of | |
143 the existing data without the censored data. | |
144 | |
145 We need to recompute new delta for any revision that used the censored | |
146 revision as delta base. As the cumulative size of the new delta may be | |
147 large, we store them in a temporary file until they are stored in their | |
148 final destination. | |
149 | |
150 All data before the censored data can be blindly copied. The rest needs | |
151 to be copied as we go and the associated index entry needs adjustement. | |
152 """ | |
153 assert revlog._format_version != REVLOGV0, revlog._format_version | |
154 assert revlog._format_version != REVLOGV1, revlog._format_version | |
155 | |
146 old_index = revlog.index | 156 old_index = revlog.index |
147 docket = revlog._docket | 157 docket = revlog._docket |
148 | 158 |
149 censor_revs = {revlog.rev(censornode)} | |
150 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') | 159 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
151 | 160 |
152 first_excl_rev = min(censor_revs) | 161 first_excl_rev = min(censor_revs) |
153 | 162 |
154 first_excl_entry = revlog.index[first_excl_rev] | 163 first_excl_entry = revlog.index[first_excl_rev] |