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.
Alphare |
hg-reviewers |
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.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
rl.opener.rename(newrl._datafile, rl._datafile) | rl.opener.rename(newrl._datafile, rl._datafile) | ||||
rl.clearcaches() | rl.clearcaches() | ||||
rl._loadindex() | rl._loadindex() | ||||
def v2_censor(revlog, tr, censornode, tombstone=b''): | def v2_censor(revlog, tr, censornode, tombstone=b''): | ||||
"""censors a revision in a "version 2" revlog""" | """censors a revision in a "version 2" revlog""" | ||||
# General principle | assert revlog._format_version != REVLOGV0, revlog._format_version | ||||
# | assert revlog._format_version != REVLOGV1, revlog._format_version | ||||
# We create new revlog files (index/data/sidedata) to copy the content of | |||||
# the existing data without the censored data. | censor_revs = {revlog.rev(censornode)} | ||||
# | _rewrite_v2(revlog, tr, censor_revs, tombstone) | ||||
# We need to recompute new delta for any revision that used the censored | |||||
# revision as delta base. As the cumulative size of the new delta may be | |||||
# large, we store them in a temporary file until they are stored in their | |||||
# final destination. | |||||
# | |||||
# All data before the censored data can be blindly copied. The rest needs | |||||
# to be copied as we go and the associated index entry needs adjustement. | |||||
def _rewrite_v2(revlog, tr, censor_revs, tombstone=b''): | |||||
"""rewrite a revlog to censor some of its content | |||||
General principle | |||||
We create new revlog files (index/data/sidedata) to copy the content of | |||||
the existing data without the censored data. | |||||
We need to recompute new delta for any revision that used the censored | |||||
revision as delta base. As the cumulative size of the new delta may be | |||||
large, we store them in a temporary file until they are stored in their | |||||
final destination. | |||||
All data before the censored data can be blindly copied. The rest needs | |||||
to be copied as we go and the associated index entry needs adjustement. | |||||
""" | |||||
assert revlog._format_version != REVLOGV0, revlog._format_version | assert revlog._format_version != REVLOGV0, revlog._format_version | ||||
assert revlog._format_version != REVLOGV1, revlog._format_version | assert revlog._format_version != REVLOGV1, revlog._format_version | ||||
old_index = revlog.index | old_index = revlog.index | ||||
docket = revlog._docket | docket = revlog._docket | ||||
censor_revs = {revlog.rev(censornode)} | |||||
tombstone = storageutil.packmeta({b'censored': tombstone}, b'') | tombstone = storageutil.packmeta({b'censored': tombstone}, b'') | ||||
first_excl_rev = min(censor_revs) | first_excl_rev = min(censor_revs) | ||||
first_excl_entry = revlog.index[first_excl_rev] | first_excl_entry = revlog.index[first_excl_rev] | ||||
index_cutoff = revlog.index.entry_size * first_excl_rev | index_cutoff = revlog.index.entry_size * first_excl_rev | ||||
data_cutoff = first_excl_entry[ENTRY_DATA_OFFSET] >> 16 | data_cutoff = first_excl_entry[ENTRY_DATA_OFFSET] >> 16 | ||||
sidedata_cutoff = revlog.sidedata_cut_off(first_excl_rev) | sidedata_cutoff = revlog.sidedata_cut_off(first_excl_rev) |