Mercurial > public > mercurial-scm > hg
annotate mercurial/revlogutils/rewrite.py @ 52163:7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
The performance of this has been looked at for quite some time, and some
workflows are actually quite a bit faster than with the Python + C code.
However, we are still (up to 20%) slower in some crucial places like cloning
certain repos, log, cat, which makes this an incomplete rewrite. This is
mostly due to the high amount of overhead in Python <-> Rust FFI, especially
around the VFS code. A future patch series will rewrite the VFS code in
pure Rust, which should hopefully get us up to par with current perfomance,
if not better in all important cases.
This is a "save state" of sorts, as this is a ton of code, and I don't want
to pile up even more things in a single review.
Continuing to try to match the current performance will take an extremely
long time, if it's not impossible, without the aforementioned VFS work.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 19 Jun 2024 19:10:49 +0200 |
parents | 6223892833db |
children | f066fc0bdc7a |
rev | line source |
---|---|
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
1 # censor code related to censoring revision |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
2 # coding: utf8 |
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
3 # |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
4 # Copyright 2021 Pierre-Yves David <pierre-yves.david@octobus.net> |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
5 # Copyright 2015 Google, Inc <martinvonz@google.com> |
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
6 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
10263 | 8 # GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
9 |
51860
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
10 from __future__ import annotations |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51699
diff
changeset
|
11 |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
12 import binascii |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
13 import contextlib |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
14 import os |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
15 import struct |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
16 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
17 from ..node import ( |
27361
29f50344fa83
revlog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27251
diff
changeset
|
18 nullrev, |
39767
db088e133e91
revlog: define ellipsis flag processors in core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39333
diff
changeset
|
19 ) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
20 from .constants import ( |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
21 COMP_MODE_PLAIN, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
22 ENTRY_DATA_COMPRESSED_LENGTH, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
23 ENTRY_DATA_COMPRESSION_MODE, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
24 ENTRY_DATA_OFFSET, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
25 ENTRY_DATA_UNCOMPRESSED_LENGTH, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
26 ENTRY_DELTA_BASE, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
27 ENTRY_LINK_REV, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
28 ENTRY_NODE_ID, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
29 ENTRY_PARENT_1, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
30 ENTRY_PARENT_2, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
31 ENTRY_SIDEDATA_COMPRESSED_LENGTH, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
32 ENTRY_SIDEDATA_COMPRESSION_MODE, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
33 ENTRY_SIDEDATA_OFFSET, |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
34 REVIDX_ISCENSORED, |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
35 REVLOGV0, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
36 REVLOGV1, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
37 ) |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
38 from ..i18n import _ |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
39 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
40 from .. import ( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
41 error, |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
42 mdiff, |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
43 pycompat, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
44 revlogutils, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
45 util, |
46310
fc2d5c0aed7f
persistent-nodemap: add a "warn" option to the slow-path config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
46 ) |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
47 from ..utils import ( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
48 storageutil, |
47386
0d0fb091c49f
revlog: simplify "partial read" error message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47385
diff
changeset
|
49 ) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
50 from . import ( |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
51 constants, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
52 deltas, |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
53 ) |
47246
02a4463565ea
revlog: improve documentation of the entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47245
diff
changeset
|
54 |
02a4463565ea
revlog: improve documentation of the entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47245
diff
changeset
|
55 |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
56 def v1_censor(rl, tr, censor_nodes, tombstone=b''): |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
57 """censors a revision in a "version 1" revlog""" |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
58 assert rl._format_version == constants.REVLOGV1, rl._format_version |
47151
24be247a13b4
revlog: stop usage of `_indexfile` to computing nodemap path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47150
diff
changeset
|
59 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
60 # avoid cycle |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
61 from .. import revlog |
47144
b6e1fe7ac24b
revlog: split the option initialisation in its own method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47143
diff
changeset
|
62 |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
63 censor_revs = set(rl.rev(node) for node in censor_nodes) |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
64 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
30154
5e72129d75ed
revlog: add instance variable controlling delta chain use
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30012
diff
changeset
|
65 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
66 # Rewriting the revlog in place is hard. Our strategy for censoring is |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
67 # to create a new revlog, copy all revisions to it, then replace the |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
68 # revlogs on transaction close. |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
69 # |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
70 # This is a bit dangerous. We could easily have a mismatch of state. |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
71 newrl = revlog.revlog( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
72 rl.opener, |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
73 target=rl.target, |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
74 radix=rl.radix, |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
75 postfix=b'tmpcensored', |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
76 censorable=True, |
51156
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
77 data_config=rl.data_config, |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
78 delta_config=rl.delta_config, |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
79 feature_config=rl.feature_config, |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
80 may_inline=rl._inline, |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
81 ) |
51156
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
82 # inline splitting will prepare some transaction work that will get |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
83 # confused by the final file move. So if there is a risk of not being |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
84 # inline at the end, we prevent the new revlog to be inline in the first |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
85 # place. |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
86 assert not (newrl._inline and not rl._inline) |
23337
3a8a763f4197
revlog: add a method to get missing revs incrementally
Siddharth Agarwal <sid0@fb.com>
parents:
23328
diff
changeset
|
87 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
88 for rev in rl.revs(): |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
89 node = rl.node(rev) |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
90 p1, p2 = rl.parents(node) |
1457
518da3c3b6ce
This implements the nodesbetween method, and it removes the newer method
Eric Hopper <hopper@omnifarious.org>
parents:
1351
diff
changeset
|
91 |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
92 if rev in censor_revs: |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
93 newrl.addrawrevision( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
94 tombstone, |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
95 tr, |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
96 rl.linkrev(rev), |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
97 p1, |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
98 p2, |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
99 node, |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
100 constants.REVIDX_ISCENSORED, |
47294
93a0abe098e7
revlog: avoid raising no-arg RevlogError for internal flow control
Martin von Zweigbergk <martinvonz@google.com>
parents:
47285
diff
changeset
|
101 ) |
16665
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16533
diff
changeset
|
102 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
103 if newrl.deltaparent(rev) != nullrev: |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
104 m = _(b'censored revision stored as delta; cannot censor') |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
105 h = _( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
106 b'censoring of revlogs is not fully implemented;' |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
107 b' please report this bug' |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
108 ) |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
109 raise error.Abort(m, hint=h) |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
110 continue |
42980
0d1272783f24
revlog: introduce a `sidedata` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42879
diff
changeset
|
111 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
112 if rl.iscensored(rev): |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
113 if rl.deltaparent(rev) != nullrev: |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
114 m = _( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
115 b'cannot censor due to censored ' |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
116 b'revision having delta stored' |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
117 ) |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
118 raise error.Abort(m) |
51089
9c8df10ea6e0
revlog: move the `_chunk` method on the inner object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51084
diff
changeset
|
119 rawtext = rl._inner._chunk(rev) |
42879
4a3efe0febb5
revlog: stop using `_processflags` directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42876
diff
changeset
|
120 else: |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
121 rawtext = rl.rawdata(rev) |
8315
c8493310ad9b
revlog: use index to find index size
Matt Mackall <mpm@selenic.com>
parents:
8314
diff
changeset
|
122 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
123 newrl.addrawrevision( |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
124 rawtext, tr, rl.linkrev(rev), p1, p2, node, rl.flags(rev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43039
diff
changeset
|
125 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43039
diff
changeset
|
126 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
127 tr.addbackup(rl._indexfile, location=b'store') |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
128 if not rl._inline: |
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
129 tr.addbackup(rl._datafile, location=b'store') |
1667
daff3ef0de8d
verify: notice extra data in indices
Matt Mackall <mpm@selenic.com>
parents:
1660
diff
changeset
|
130 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
131 rl.opener.rename(newrl._indexfile, rl._indexfile) |
51156
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
132 if newrl._inline: |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
133 assert rl._inline |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
134 else: |
3e2a878fb96f
censor: fix things around inlining
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51089
diff
changeset
|
135 assert not rl._inline |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
136 rl.opener.rename(newrl._datafile, rl._datafile) |
39778
a6b3c4c1019f
revlog: move censor logic out of censor extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39775
diff
changeset
|
137 |
47391
33d626910374
revlog: move censoring code in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47389
diff
changeset
|
138 rl.clearcaches() |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
139 index, chunk_cache = rl._loadindex() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
140 rl._load_inner(index, chunk_cache) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
141 |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
142 |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
143 def v2_censor(revlog, tr, censor_nodes, tombstone=b''): |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
144 """censors a revision in a "version 2" revlog""" |
47473
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
145 assert revlog._format_version != REVLOGV0, revlog._format_version |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
146 assert revlog._format_version != REVLOGV1, revlog._format_version |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
147 |
51267
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51156
diff
changeset
|
148 censor_revs = {revlog.rev(node) for node in censor_nodes} |
47473
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
149 _rewrite_v2(revlog, tr, censor_revs, tombstone) |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
150 |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
151 |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
152 def _rewrite_v2(revlog, tr, censor_revs, tombstone=b''): |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
153 """rewrite a revlog to censor some of its content |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
154 |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
155 General principle |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
156 |
47473
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
157 We create new revlog files (index/data/sidedata) to copy the content of |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
158 the existing data without the censored data. |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
159 |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
160 We need to recompute new delta for any revision that used the censored |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
161 revision as delta base. As the cumulative size of the new delta may be |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
162 large, we store them in a temporary file until they are stored in their |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
163 final destination. |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
164 |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
165 All data before the censored data can be blindly copied. The rest needs |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
166 to be copied as we go and the associated index entry needs adjustement. |
5045ba2a3afd
censor: split the core of the logic into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47472
diff
changeset
|
167 """ |
47471
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
168 assert revlog._format_version != REVLOGV0, revlog._format_version |
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
169 assert revlog._format_version != REVLOGV1, revlog._format_version |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
170 |
47471
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
171 old_index = revlog.index |
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
172 docket = revlog._docket |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
173 |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
174 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
175 |
47472
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
176 first_excl_rev = min(censor_revs) |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
177 |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
178 first_excl_entry = revlog.index[first_excl_rev] |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
179 index_cutoff = revlog.index.entry_size * first_excl_rev |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
180 data_cutoff = first_excl_entry[ENTRY_DATA_OFFSET] >> 16 |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
181 sidedata_cutoff = revlog.sidedata_cut_off(first_excl_rev) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
182 |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
183 with pycompat.unnamedtempfile(mode=b"w+b") as tmp_storage: |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
184 # rev → (new_base, data_start, data_end, compression_mode) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
185 rewritten_entries = _precompute_rewritten_delta( |
47471
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
186 revlog, |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
187 old_index, |
47472
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
188 censor_revs, |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
189 tmp_storage, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
190 ) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
191 |
47470
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
192 all_files = _setup_new_files( |
47471
aab064416f0c
censor: rename `rl` to `revlog` in the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47470
diff
changeset
|
193 revlog, |
47470
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
194 index_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
195 data_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
196 sidedata_cutoff, |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
197 ) |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
198 |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
199 # we dont need to open the old index file since its content already |
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
200 # exist in a usable form in `old_index`. |
47466
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
201 with all_files() as open_files: |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
202 ( |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
203 old_data_file, |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
204 old_sidedata_file, |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
205 new_index_file, |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
206 new_data_file, |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
207 new_sidedata_file, |
f7a94e2d4470
censor: put the tuple of open files in an explicit variable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47465
diff
changeset
|
208 ) = open_files |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
209 |
47467
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
210 # writing the censored revision |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
211 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
212 # Writing all subsequent revisions |
47472
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
213 for rev in range(first_excl_rev, len(old_index)): |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
214 if rev in censor_revs: |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
215 _rewrite_censor( |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
216 revlog, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
217 old_index, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
218 open_files, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
219 rev, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
220 tombstone, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
221 ) |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
222 else: |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
223 _rewrite_simple( |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
224 revlog, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
225 old_index, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
226 open_files, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
227 rev, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
228 rewritten_entries, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
229 tmp_storage, |
c81a5297f185
censor: migrate the logic to a set of `censor_revs`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47471
diff
changeset
|
230 ) |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
231 docket.write(transaction=None, stripping=True) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
232 |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
233 |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
234 def _precompute_rewritten_delta( |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
235 revlog, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
236 old_index, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
237 excluded_revs, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
238 tmp_storage, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
239 ): |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
240 """Compute new delta for revisions whose delta is based on revision that |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
241 will not survive as is. |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
242 |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
243 Return a mapping: {rev → (new_base, data_start, data_end, compression_mode)} |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
244 """ |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
245 dc = deltas.deltacomputer(revlog) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
246 rewritten_entries = {} |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
247 first_excl_rev = min(excluded_revs) |
51017
509f0f7fc89e
delta-computer: stop explicitly taking file handle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51016
diff
changeset
|
248 with revlog.reading(): |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
249 for rev in range(first_excl_rev, len(old_index)): |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
250 if rev in excluded_revs: |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
251 # this revision will be preserved as is, so we don't need to |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
252 # consider recomputing a delta. |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
253 continue |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
254 entry = old_index[rev] |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
255 if entry[ENTRY_DELTA_BASE] not in excluded_revs: |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
256 continue |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
257 # This is a revision that use the censored revision as the base |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
258 # for its delta. We need a need new deltas |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
259 if entry[ENTRY_DATA_UNCOMPRESSED_LENGTH] == 0: |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
260 # this revision is empty, we can delta against nullrev |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
261 rewritten_entries[rev] = (nullrev, 0, 0, COMP_MODE_PLAIN) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
262 else: |
51016
66c139d33cfe
censors: simply use `revlog.reading` to keep things open dring rewrite
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50501
diff
changeset
|
263 text = revlog.rawdata(rev) |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
264 info = revlogutils.revisioninfo( |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
265 node=entry[ENTRY_NODE_ID], |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
266 p1=revlog.node(entry[ENTRY_PARENT_1]), |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
267 p2=revlog.node(entry[ENTRY_PARENT_2]), |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
268 btext=[text], |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
269 textlen=len(text), |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
270 cachedelta=None, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
271 flags=entry[ENTRY_DATA_OFFSET] & 0xFFFF, |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
272 ) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
273 d = dc.finddeltainfo( |
51017
509f0f7fc89e
delta-computer: stop explicitly taking file handle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51016
diff
changeset
|
274 info, excluded_bases=excluded_revs, target_rev=rev |
47469
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
275 ) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
276 default_comp = revlog._docket.default_compression_header |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
277 comp_mode, d = deltas.delta_compression(default_comp, d) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
278 # using `tell` is a bit lazy, but we are not here for speed |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
279 start = tmp_storage.tell() |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
280 tmp_storage.write(d.data[1]) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
281 end = tmp_storage.tell() |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
282 rewritten_entries[rev] = (d.base, start, end, comp_mode) |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
283 return rewritten_entries |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
284 |
60c48458ee6c
censor: extract the part about recomputing delta in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47468
diff
changeset
|
285 |
47470
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
286 def _setup_new_files( |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
287 revlog, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
288 index_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
289 data_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
290 sidedata_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
291 ): |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
292 """ |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
293 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
294 return a context manager to open all the relevant files: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
295 - old_data_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
296 - old_sidedata_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
297 - new_index_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
298 - new_data_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
299 - new_sidedata_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
300 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
301 The old_index_file is not here because it is accessed through the |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
302 `old_index` object if the caller function. |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
303 """ |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
304 docket = revlog._docket |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
305 old_index_filepath = revlog.opener.join(docket.index_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
306 old_data_filepath = revlog.opener.join(docket.data_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
307 old_sidedata_filepath = revlog.opener.join(docket.sidedata_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
308 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
309 new_index_filepath = revlog.opener.join(docket.new_index_file()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
310 new_data_filepath = revlog.opener.join(docket.new_data_file()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
311 new_sidedata_filepath = revlog.opener.join(docket.new_sidedata_file()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
312 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
313 util.copyfile(old_index_filepath, new_index_filepath, nb_bytes=index_cutoff) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
314 util.copyfile(old_data_filepath, new_data_filepath, nb_bytes=data_cutoff) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
315 util.copyfile( |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
316 old_sidedata_filepath, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
317 new_sidedata_filepath, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
318 nb_bytes=sidedata_cutoff, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
319 ) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
320 revlog.opener.register_file(docket.index_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
321 revlog.opener.register_file(docket.data_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
322 revlog.opener.register_file(docket.sidedata_filepath()) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
323 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
324 docket.index_end = index_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
325 docket.data_end = data_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
326 docket.sidedata_end = sidedata_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
327 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
328 # reload the revlog internal information |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
329 revlog.clearcaches() |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
330 index, chunk_cache = revlog._loadindex(docket=docket) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
331 revlog._load_inner(index, chunk_cache) |
47470
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
332 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
333 @contextlib.contextmanager |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
334 def all_files_opener(): |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
335 # hide opening in an helper function to please check-code, black |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
336 # and various python version at the same time |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
337 with open(old_data_filepath, 'rb') as old_data_file: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
338 with open(old_sidedata_filepath, 'rb') as old_sidedata_file: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
339 with open(new_index_filepath, 'r+b') as new_index_file: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
340 with open(new_data_filepath, 'r+b') as new_data_file: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
341 with open( |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
342 new_sidedata_filepath, 'r+b' |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
343 ) as new_sidedata_file: |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
344 new_index_file.seek(0, os.SEEK_END) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
345 assert new_index_file.tell() == index_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
346 new_data_file.seek(0, os.SEEK_END) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
347 assert new_data_file.tell() == data_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
348 new_sidedata_file.seek(0, os.SEEK_END) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
349 assert new_sidedata_file.tell() == sidedata_cutoff |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
350 yield ( |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
351 old_data_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
352 old_sidedata_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
353 new_index_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
354 new_data_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
355 new_sidedata_file, |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
356 ) |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
357 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
358 return all_files_opener |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
359 |
d6afe1478a2a
censor: extract the part about creating and opening new files in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47469
diff
changeset
|
360 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
361 def _rewrite_simple( |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
362 revlog, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
363 old_index, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
364 all_files, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
365 rev, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
366 rewritten_entries, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
367 tmp_storage, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
368 ): |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
369 """append a normal revision to the index after the rewritten one(s)""" |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
370 ( |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
371 old_data_file, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
372 old_sidedata_file, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
373 new_index_file, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
374 new_data_file, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
375 new_sidedata_file, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
376 ) = all_files |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
377 entry = old_index[rev] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
378 flags = entry[ENTRY_DATA_OFFSET] & 0xFFFF |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
379 old_data_offset = entry[ENTRY_DATA_OFFSET] >> 16 |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
380 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
381 if rev not in rewritten_entries: |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
382 old_data_file.seek(old_data_offset) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
383 new_data_size = entry[ENTRY_DATA_COMPRESSED_LENGTH] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
384 new_data = old_data_file.read(new_data_size) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
385 data_delta_base = entry[ENTRY_DELTA_BASE] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
386 d_comp_mode = entry[ENTRY_DATA_COMPRESSION_MODE] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
387 else: |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
388 ( |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
389 data_delta_base, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
390 start, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
391 end, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
392 d_comp_mode, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
393 ) = rewritten_entries[rev] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
394 new_data_size = end - start |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
395 tmp_storage.seek(start) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
396 new_data = tmp_storage.read(new_data_size) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
397 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
398 # It might be faster to group continuous read/write operation, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
399 # however, this is censor, an operation that is not focussed |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
400 # around stellar performance. So I have not written this |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
401 # optimisation yet. |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
402 new_data_offset = new_data_file.tell() |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
403 new_data_file.write(new_data) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
404 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
405 sidedata_size = entry[ENTRY_SIDEDATA_COMPRESSED_LENGTH] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
406 new_sidedata_offset = new_sidedata_file.tell() |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
407 if 0 < sidedata_size: |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
408 old_sidedata_offset = entry[ENTRY_SIDEDATA_OFFSET] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
409 old_sidedata_file.seek(old_sidedata_offset) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
410 new_sidedata = old_sidedata_file.read(sidedata_size) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
411 new_sidedata_file.write(new_sidedata) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
412 |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
413 data_uncompressed_length = entry[ENTRY_DATA_UNCOMPRESSED_LENGTH] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
414 sd_com_mode = entry[ENTRY_SIDEDATA_COMPRESSION_MODE] |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
415 assert data_delta_base <= rev, (data_delta_base, rev) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
416 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
417 new_entry = revlogutils.entry( |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
418 flags=flags, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
419 data_offset=new_data_offset, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
420 data_compressed_length=new_data_size, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
421 data_uncompressed_length=data_uncompressed_length, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
422 data_delta_base=data_delta_base, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
423 link_rev=entry[ENTRY_LINK_REV], |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
424 parent_rev_1=entry[ENTRY_PARENT_1], |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
425 parent_rev_2=entry[ENTRY_PARENT_2], |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
426 node_id=entry[ENTRY_NODE_ID], |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
427 sidedata_offset=new_sidedata_offset, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
428 sidedata_compressed_length=sidedata_size, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
429 data_compression_mode=d_comp_mode, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
430 sidedata_compression_mode=sd_com_mode, |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
431 ) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
432 revlog.index.append(new_entry) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
433 entry_bin = revlog.index.entry_binary(rev) |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
434 new_index_file.write(entry_bin) |
47457
f8330a3fc39f
censor: implement censoring for revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47392
diff
changeset
|
435 |
47468
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
436 revlog._docket.index_end = new_index_file.tell() |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
437 revlog._docket.data_end = new_data_file.tell() |
9b70aa7bcbab
censor: extract the part about writing the other revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47467
diff
changeset
|
438 revlog._docket.sidedata_end = new_sidedata_file.tell() |
47467
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
439 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
440 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
441 def _rewrite_censor( |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
442 revlog, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
443 old_index, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
444 all_files, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
445 rev, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
446 tombstone, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
447 ): |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
448 """rewrite and append a censored revision""" |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
449 ( |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
450 old_data_file, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
451 old_sidedata_file, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
452 new_index_file, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
453 new_data_file, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
454 new_sidedata_file, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
455 ) = all_files |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
456 entry = old_index[rev] |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
457 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
458 # XXX consider trying the default compression too |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
459 new_data_size = len(tombstone) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
460 new_data_offset = new_data_file.tell() |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
461 new_data_file.write(tombstone) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
462 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
463 # we are not adding any sidedata as they might leak info about the censored version |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
464 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
465 link_rev = entry[ENTRY_LINK_REV] |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
466 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
467 p1 = entry[ENTRY_PARENT_1] |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
468 p2 = entry[ENTRY_PARENT_2] |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
469 |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
470 new_entry = revlogutils.entry( |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
471 flags=constants.REVIDX_ISCENSORED, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
472 data_offset=new_data_offset, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
473 data_compressed_length=new_data_size, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
474 data_uncompressed_length=new_data_size, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
475 data_delta_base=rev, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
476 link_rev=link_rev, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
477 parent_rev_1=p1, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
478 parent_rev_2=p2, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
479 node_id=entry[ENTRY_NODE_ID], |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
480 sidedata_offset=0, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
481 sidedata_compressed_length=0, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
482 data_compression_mode=COMP_MODE_PLAIN, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
483 sidedata_compression_mode=COMP_MODE_PLAIN, |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
484 ) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
485 revlog.index.append(new_entry) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
486 entry_bin = revlog.index.entry_binary(rev) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
487 new_index_file.write(entry_bin) |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
488 revlog._docket.index_end = new_index_file.tell() |
3ab267f0cbe4
censor: extract the part about writing the censored revision in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47466
diff
changeset
|
489 revlog._docket.data_end = new_data_file.tell() |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
490 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
491 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
492 def _get_filename_from_filelog_index(path): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
493 # Drop the extension and the `data/` prefix |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
494 path_part = path.rsplit(b'.', 1)[0].split(b'/', 1) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
495 if len(path_part) < 2: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
496 msg = _(b"cannot recognize filelog from filename: '%s'") |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
497 msg %= path |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
498 raise error.Abort(msg) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
499 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
500 return path_part[1] |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
501 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
502 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
503 def _filelog_from_filename(repo, path): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
504 """Returns the filelog for the given `path`. Stolen from `engine.py`""" |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
505 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
506 from .. import filelog # avoid cycle |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
507 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
508 fl = filelog.filelog(repo.svfs, path) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
509 return fl |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
510 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
511 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
512 def _write_swapped_parents(repo, rl, rev, offset, fp): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
513 """Swaps p1 and p2 and overwrites the revlog entry for `rev` in `fp`""" |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
514 from ..pure import parsers # avoid cycle |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
515 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
516 if repo._currentlock(repo._lockref) is None: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
517 # Let's be paranoid about it |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
518 msg = "repo needs to be locked to rewrite parents" |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
519 raise error.ProgrammingError(msg) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
520 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
521 index_format = parsers.IndexObject.index_format |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
522 entry = rl.index[rev] |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
523 new_entry = list(entry) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
524 new_entry[5], new_entry[6] = entry[6], entry[5] |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
525 packed = index_format.pack(*new_entry[:8]) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
526 fp.seek(offset) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
527 fp.write(packed) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
528 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
529 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
530 def _reorder_filelog_parents(repo, fl, to_fix): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
531 """ |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
532 Swaps p1 and p2 for all `to_fix` revisions of filelog `fl` and writes the |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
533 new version to disk, overwriting the old one with a rename. |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
534 """ |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
535 from ..pure import parsers # avoid cycle |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
536 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
537 ui = repo.ui |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
538 assert len(to_fix) > 0 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
539 rl = fl._revlog |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
540 if rl._format_version != constants.REVLOGV1: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
541 msg = "expected version 1 revlog, got version '%d'" % rl._format_version |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
542 raise error.ProgrammingError(msg) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
543 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
544 index_file = rl._indexfile |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
545 new_file_path = index_file + b'.tmp-parents-fix' |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
546 repaired_msg = _(b"repaired revision %d of 'filelog %s'\n") |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
547 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
548 with ui.uninterruptible(): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
549 try: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
550 util.copyfile( |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
551 rl.opener.join(index_file), |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
552 rl.opener.join(new_file_path), |
51045
59c6f99723b1
revlog: remove legacy usage of `_checkambig`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51043
diff
changeset
|
553 checkambig=rl.data_config.check_ambig, |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
554 ) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
555 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
556 with rl.opener(new_file_path, mode=b"r+") as fp: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
557 if rl._inline: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
558 index = parsers.InlinedIndexObject(fp.read()) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
559 for rev in fl.revs(): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
560 if rev in to_fix: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
561 offset = index._calculate_index(rev) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
562 _write_swapped_parents(repo, rl, rev, offset, fp) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
563 ui.write(repaired_msg % (rev, index_file)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
564 else: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
565 index_format = parsers.IndexObject.index_format |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
566 for rev in to_fix: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
567 offset = rev * index_format.size |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
568 _write_swapped_parents(repo, rl, rev, offset, fp) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
569 ui.write(repaired_msg % (rev, index_file)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
570 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
571 rl.opener.rename(new_file_path, index_file) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
572 rl.clearcaches() |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
573 index, chunk_cache = rl._loadindex() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51911
diff
changeset
|
574 rl._load_inner(index, chunk_cache) |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
575 finally: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
576 util.tryunlink(new_file_path) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
577 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
578 |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
579 def _is_revision_affected(fl, filerev, metadata_cache=None): |
47818
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
580 full_text = lambda: fl._revlog.rawdata(filerev) |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
581 parent_revs = lambda: fl._revlog.parentrevs(filerev) |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
582 return _is_revision_affected_inner( |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
583 full_text, parent_revs, filerev, metadata_cache |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
584 ) |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
585 |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
586 |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
587 def _is_revision_affected_inner( |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
588 full_text, |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
589 parents_revs, |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
590 filerev, |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
591 metadata_cache=None, |
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
592 ): |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
593 """Mercurial currently (5.9rc0) uses `p1 == nullrev and p2 != nullrev` as a |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
594 special meaning compared to the reverse in the context of filelog-based |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
595 copytracing. issue6528 exists because new code assumed that parent ordering |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
596 didn't matter, so this detects if the revision contains metadata (since |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
597 it's only used for filelog-based copytracing) and its parents are in the |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
598 "wrong" order.""" |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
599 try: |
47818
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
600 raw_text = full_text() |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
601 except error.CensoredNodeError: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
602 # We don't care about censored nodes as they never carry metadata |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
603 return False |
48245
531d26b1390a
rewrite: fix issue6599
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47821
diff
changeset
|
604 |
531d26b1390a
rewrite: fix issue6599
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47821
diff
changeset
|
605 # raw text can be a `memoryview`, which doesn't implement `startswith` |
531d26b1390a
rewrite: fix issue6599
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47821
diff
changeset
|
606 has_meta = bytes(raw_text[:2]) == b'\x01\n' |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
607 if metadata_cache is not None: |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
608 metadata_cache[filerev] = has_meta |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
609 if has_meta: |
47818
5b046c2e3000
issue6528: implement _is_revision_affected using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47817
diff
changeset
|
610 (p1, p2) = parents_revs() |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
611 if p1 != nullrev and p2 == nullrev: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
612 return True |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
613 return False |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
614 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
615 |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
616 def _is_revision_affected_fast(repo, fl, filerev, metadata_cache): |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
617 rl = fl._revlog |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
618 is_censored = lambda: rl.iscensored(filerev) |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
619 delta_base = lambda: rl.deltaparent(filerev) |
51907
767f47fc9d42
revlogutils: fix _chunk() reference
Joerg Sonnenberger <joerg@bec.de>
parents:
51860
diff
changeset
|
620 delta = lambda: rl._inner._chunk(filerev) |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
621 full_text = lambda: rl.rawdata(filerev) |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
622 parent_revs = lambda: rl.parentrevs(filerev) |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
623 # This function is used by repair_issue6528, but not by |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
624 # filter_delta_issue6528. As such, we do not want to trust |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
625 # parent revisions of the delta base to decide whether |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
626 # the delta base has metadata. |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
627 return _is_revision_affected_fast_inner( |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
628 is_censored, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
629 delta_base, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
630 delta, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
631 full_text, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
632 parent_revs, |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
633 None, # don't trust the parent revisions |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
634 filerev, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
635 metadata_cache, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
636 ) |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
637 |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
638 |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
639 def _is_revision_affected_fast_inner( |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
640 is_censored, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
641 delta_base, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
642 delta, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
643 full_text, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
644 parent_revs, |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
645 deltabase_parentrevs, |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
646 filerev, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
647 metadata_cache, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
648 ): |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
649 """Optimization fast-path for `_is_revision_affected`. |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
650 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
651 `metadata_cache` is a dict of `{rev: has_metadata}` which allows any |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
652 revision to check if its base has metadata, saving computation of the full |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
653 text, instead looking at the current delta. |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
654 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
655 This optimization only works if the revisions are looked at in order.""" |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
656 |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
657 if is_censored(): |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
658 # Censored revisions don't contain metadata, so they cannot be affected |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
659 metadata_cache[filerev] = False |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
660 return False |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
661 |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
662 p1, p2 = parent_revs() |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
663 if p1 == nullrev or p2 != nullrev: |
51910
3dbbb7d913a9
revlogutils: remember known metadata parents for issue6528
Joerg Sonnenberger <joerg@bec.de>
parents:
51909
diff
changeset
|
664 metadata_cache[filerev] = True |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
665 return False |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
666 |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
667 delta_parent = delta_base() |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
668 parent_has_metadata = metadata_cache.get(delta_parent) |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
669 if parent_has_metadata is None: |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
670 if deltabase_parentrevs is not None: |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
671 deltabase_parentrevs = deltabase_parentrevs() |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
672 if deltabase_parentrevs == (nullrev, nullrev): |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
673 # Need to check the content itself as there is no flag. |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
674 parent_has_metadata = None |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
675 elif deltabase_parentrevs[0] == nullrev: |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
676 # Second parent is !null, assume repository is correct |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
677 # and has flagged this file revision as having metadata. |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
678 parent_has_metadata = True |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
679 elif deltabase_parentrevs[1] == nullrev: |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
680 # First parent is !null, so assume it has no metadata. |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
681 parent_has_metadata = False |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
682 if parent_has_metadata is None: |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
683 return _is_revision_affected_inner( |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
684 full_text, |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
685 parent_revs, |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
686 filerev, |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
687 metadata_cache, |
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
688 ) |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
689 |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
690 chunk = delta() |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
691 if not len(chunk): |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
692 # No diff for this revision |
51908
82a94a956c54
revlogutils: for issue6528 fix, cache results for null changes
Joerg Sonnenberger <joerg@bec.de>
parents:
51907
diff
changeset
|
693 metadata_cache[filerev] = parent_has_metadata |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
694 return parent_has_metadata |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
695 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
696 header_length = 12 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
697 if len(chunk) < header_length: |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
698 raise error.Abort(_(b"patch cannot be decoded")) |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
699 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
700 start, _end, _length = struct.unpack(b">lll", chunk[:header_length]) |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
701 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
702 if start < 2: # len(b'\x01\n') == 2 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
703 # This delta does *something* to the metadata marker (if any). |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
704 # Check it the slow way |
47819
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
705 is_affected = _is_revision_affected_inner( |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
706 full_text, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
707 parent_revs, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
708 filerev, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
709 metadata_cache, |
c02ce6def30c
issue6528: implement _is_revision_affected_fast using callback
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47818
diff
changeset
|
710 ) |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
711 return is_affected |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
712 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
713 # The diff did not remove or add the metadata header, it's then in the same |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
714 # situation as its parent |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
715 metadata_cache[filerev] = parent_has_metadata |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
716 return parent_has_metadata |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
717 |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
718 |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
719 def _from_report(ui, repo, context, from_report, dry_run): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
720 """ |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
721 Fix the revisions given in the `from_report` file, but still checks if the |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
722 revisions are indeed affected to prevent an unfortunate cyclic situation |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
723 where we'd swap well-ordered parents again. |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
724 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
725 See the doc for `debug_fix_issue6528` for the format documentation. |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
726 """ |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
727 ui.write(_(b"loading report file '%s'\n") % from_report) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
728 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
729 with context(), open(from_report, mode='rb') as f: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
730 for line in f.read().split(b'\n'): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
731 if not line: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
732 continue |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
733 filenodes, filename = line.split(b' ', 1) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
734 fl = _filelog_from_filename(repo, filename) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
735 to_fix = set( |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
736 fl.rev(binascii.unhexlify(n)) for n in filenodes.split(b',') |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
737 ) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
738 excluded = set() |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
739 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
740 for filerev in to_fix: |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
741 if _is_revision_affected(fl, filerev): |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
742 msg = b"found affected revision %d for filelog '%s'\n" |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
743 ui.warn(msg % (filerev, filename)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
744 else: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
745 msg = _(b"revision %s of file '%s' is not affected\n") |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
746 msg %= (binascii.hexlify(fl.node(filerev)), filename) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
747 ui.warn(msg) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
748 excluded.add(filerev) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
749 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
750 to_fix = to_fix - excluded |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
751 if not to_fix: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
752 msg = _(b"no affected revisions were found for '%s'\n") |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
753 ui.write(msg % filename) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
754 continue |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
755 if not dry_run: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
756 _reorder_filelog_parents(repo, fl, sorted(to_fix)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
757 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
758 |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
759 def filter_delta_issue6528(revlog, deltas_iter): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
760 """filter incomind deltas to repaire issue 6528 on the fly""" |
51909
576876a518e1
revlogutils: for issue6528 fix, pre-cache nullrev as metadata-free
Joerg Sonnenberger <joerg@bec.de>
parents:
51908
diff
changeset
|
761 metadata_cache = {nullrev: False} |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
762 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
763 deltacomputer = deltas.deltacomputer(revlog) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
764 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
765 for rev, d in enumerate(deltas_iter, len(revlog)): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
766 ( |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
767 node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
768 p1_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
769 p2_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
770 linknode, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
771 deltabase, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
772 delta, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
773 flags, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
774 sidedata, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
775 ) = d |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
776 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
777 if not revlog.index.has_node(deltabase): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
778 raise error.LookupError( |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
779 deltabase, revlog.radix, _(b'unknown parent') |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
780 ) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
781 base_rev = revlog.rev(deltabase) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
782 if not revlog.index.has_node(p1_node): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
783 raise error.LookupError(p1_node, revlog.radix, _(b'unknown parent')) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
784 p1_rev = revlog.rev(p1_node) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
785 if not revlog.index.has_node(p2_node): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
786 raise error.LookupError(p2_node, revlog.radix, _(b'unknown parent')) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
787 p2_rev = revlog.rev(p2_node) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
788 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
789 is_censored = lambda: bool(flags & REVIDX_ISCENSORED) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
790 delta_base = lambda: base_rev |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
791 parent_revs = lambda: (p1_rev, p2_rev) |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
792 deltabase_parentrevs = lambda: revlog.parentrevs(base_rev) |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
793 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
794 def full_text(): |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
795 # note: being able to reuse the full text computation in the |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
796 # underlying addrevision would be useful however this is a bit too |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
797 # intrusive the for the "quick" issue6528 we are writing before the |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
798 # 5.8 release |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
799 textlen = mdiff.patchedsize(revlog.size(base_rev), delta) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
800 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
801 revinfo = revlogutils.revisioninfo( |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
802 node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
803 p1_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
804 p2_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
805 [None], |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
806 textlen, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
807 (base_rev, delta), |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
808 flags, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
809 ) |
51017
509f0f7fc89e
delta-computer: stop explicitly taking file handle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51016
diff
changeset
|
810 return deltacomputer.buildtext(revinfo) |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
811 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
812 is_affected = _is_revision_affected_fast_inner( |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
813 is_censored, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
814 delta_base, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
815 lambda: delta, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
816 full_text, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
817 parent_revs, |
51911
6223892833db
revlogutils: teach issue6528 filtering about grandparents
Joerg Sonnenberger <joerg@bec.de>
parents:
51910
diff
changeset
|
818 deltabase_parentrevs, |
47821
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
819 rev, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
820 metadata_cache, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
821 ) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
822 if is_affected: |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
823 d = ( |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
824 node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
825 p2_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
826 p1_node, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
827 linknode, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
828 deltabase, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
829 delta, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
830 flags, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
831 sidedata, |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
832 ) |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
833 yield d |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
834 |
c30ca163b45e
issue6528: also filter delta on the fly when applying a changegroup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47819
diff
changeset
|
835 |
47817
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
836 def repair_issue6528( |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
837 ui, repo, dry_run=False, to_report=None, from_report=None, paranoid=False |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
838 ): |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
839 @contextlib.contextmanager |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
840 def context(): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
841 if dry_run or to_report: # No need for locking |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
842 yield |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
843 else: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
844 with repo.wlock(), repo.lock(): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
845 yield |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
846 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
847 if from_report: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
848 return _from_report(ui, repo, context, from_report, dry_run) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
849 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
850 report_entries = [] |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
851 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
852 with context(): |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
853 files = list( |
50468
521fec115dad
store: use a StoreEntry object instead of tuple for store files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50461
diff
changeset
|
854 entry |
50501
862e3a13da44
store: rename `datafiles` to `data_entries`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50497
diff
changeset
|
855 for entry in repo.store.data_entries() |
50497
0bd214f83216
store: use the boolean property in `repair_issue6528`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50493
diff
changeset
|
856 if entry.is_revlog and entry.is_filelog |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
857 ) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
858 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
859 progress = ui.makeprogress( |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
860 _(b"looking for affected revisions"), |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
861 unit=_(b"filelogs"), |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
862 total=len(files), |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
863 ) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
864 found_nothing = True |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
865 |
50468
521fec115dad
store: use a StoreEntry object instead of tuple for store files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50461
diff
changeset
|
866 for entry in files: |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
867 progress.increment() |
50483
85c5b4b507af
store: use StoreEntry API instead of parsing filename when fixing issue6528
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50468
diff
changeset
|
868 filename = entry.target_id |
85c5b4b507af
store: use StoreEntry API instead of parsing filename when fixing issue6528
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50468
diff
changeset
|
869 fl = _filelog_from_filename(repo, entry.target_id) |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
870 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
871 # Set of filerevs (or hex filenodes if `to_report`) that need fixing |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
872 to_fix = set() |
51909
576876a518e1
revlogutils: for issue6528 fix, pre-cache nullrev as metadata-free
Joerg Sonnenberger <joerg@bec.de>
parents:
51908
diff
changeset
|
873 metadata_cache = {nullrev: False} |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
874 for filerev in fl.revs(): |
47816
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
875 affected = _is_revision_affected_fast( |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
876 repo, fl, filerev, metadata_cache |
32e21ac3adb1
repair: improve performance of detection of revisions affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47815
diff
changeset
|
877 ) |
47817
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
878 if paranoid: |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
879 slow = _is_revision_affected(fl, filerev) |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
880 if slow != affected: |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
881 msg = _(b"paranoid check failed for '%s' at node %s") |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
882 node = binascii.hexlify(fl.node(filerev)) |
855463b5fe49
debugcommands: add a `--paranoid` option to `debug-repair-issue-6528`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47816
diff
changeset
|
883 raise error.Abort(msg % (filename, node)) |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
884 if affected: |
50483
85c5b4b507af
store: use StoreEntry API instead of parsing filename when fixing issue6528
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50468
diff
changeset
|
885 msg = b"found affected revision %d for file '%s'\n" |
85c5b4b507af
store: use StoreEntry API instead of parsing filename when fixing issue6528
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50468
diff
changeset
|
886 ui.warn(msg % (filerev, filename)) |
47815
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
887 found_nothing = False |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
888 if not dry_run: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
889 if to_report: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
890 to_fix.add(binascii.hexlify(fl.node(filerev))) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
891 else: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
892 to_fix.add(filerev) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
893 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
894 if to_fix: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
895 to_fix = sorted(to_fix) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
896 if to_report: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
897 report_entries.append((filename, to_fix)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
898 else: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
899 _reorder_filelog_parents(repo, fl, to_fix) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
900 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
901 if found_nothing: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
902 ui.write(_(b"no affected revisions were found\n")) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
903 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
904 if to_report and report_entries: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
905 with open(to_report, mode="wb") as f: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
906 for path, to_fix in report_entries: |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
907 f.write(b"%s %s\n" % (b",".join(to_fix), path)) |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
908 |
b30a53ffbf9b
debugcommands: introduce a debug command to repair repos affected by issue6528
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47473
diff
changeset
|
909 progress.complete() |