author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 03 Sep 2024 11:11:17 +0200 | |
changeset 51977 | 42a116f1cdc1 |
parent 51863 | f4733654f144 |
permissions | -rw-r--r-- |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
1 |
# Copyright (C) 2015 - Mike Edgar <adgar@google.com> |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
2 |
# |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
3 |
# This extension enables removal of file content at a given revision, |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
4 |
# rewriting the data/metadata of successive revisions to preserve revision log |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
5 |
# integrity. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
6 |
|
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
7 |
"""erase file content at a given revision |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
8 |
|
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
9 |
The censor command instructs Mercurial to erase all content of a file at a given |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
10 |
revision *without updating the changeset hash.* This allows existing history to |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
11 |
remain valid while preventing future clones/pulls from receiving the erased |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
12 |
data. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
13 |
|
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
14 |
Typical uses for censor are due to security or legal requirements, including:: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
15 |
|
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26587
diff
changeset
|
16 |
* Passwords, private keys, cryptographic material |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
17 |
* Licensed data/code/libraries for which the license has expired |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
18 |
* Personally Identifiable Information or other private data |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
19 |
|
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
20 |
Censored nodes can interrupt mercurial's typical operation whenever the excised |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
21 |
data needs to be materialized. Some commands, like ``hg cat``/``hg revert``, |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
22 |
simply fail when asked to produce censored data. Others, like ``hg verify`` and |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
23 |
``hg update``, must be capable of tolerating censored data to continue to |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
24 |
function in a meaningful way. Such commands only tolerate censored file |
51266
51056bedbe0d
censor: mention that we check the heads in the help
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
25 |
As having a censored version in a checkout is impractical. The current head |
51056bedbe0d
censor: mention that we check the heads in the help
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
26 |
revisions of the repository are checked. If the revision to be censored is in |
51845
cd72a88c5599
censor: document the censor.policy option (issue6909)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51270
diff
changeset
|
27 |
any of them the command will abort. You can configure this behavior using the |
cd72a88c5599
censor: document the censor.policy option (issue6909)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51270
diff
changeset
|
28 |
following option: |
43434
bec734015b70
censor: document that some commands simply ignore censored data
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43077
diff
changeset
|
29 |
|
51845
cd72a88c5599
censor: document the censor.policy option (issue6909)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51270
diff
changeset
|
30 |
`censor.policy` |
cd72a88c5599
censor: document the censor.policy option (issue6909)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51270
diff
changeset
|
31 |
:config-doc:`censor.policy` |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
32 |
""" |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
33 |
|
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51845
diff
changeset
|
34 |
from __future__ import annotations |
28092
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
35 |
|
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
36 |
from mercurial.i18n import _ |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
37 |
from mercurial.node import short |
28092
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
38 |
|
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
39 |
from mercurial import ( |
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
40 |
error, |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32315
diff
changeset
|
41 |
registrar, |
28092
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
42 |
scmutil, |
5166b7a84b72
censor: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27290
diff
changeset
|
43 |
) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
44 |
|
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
45 |
cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32315
diff
changeset
|
46 |
command = registrar.command(cmdtable) |
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
28092
diff
changeset
|
47 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24890
diff
changeset
|
48 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24890
diff
changeset
|
49 |
# be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24890
diff
changeset
|
50 |
# leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 |
testedwith = b'ships-with-hg-core' |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
52 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
53 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
54 |
@command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
55 |
b'censor', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
56 |
[ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 |
( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
58 |
b'r', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 |
b'rev', |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
60 |
[], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 |
_(b'censor file from specified revision'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 |
_(b'REV'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 |
), |
51268
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
64 |
( |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
65 |
b'', |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
66 |
b'check-heads', |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
67 |
True, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
68 |
_(b'check that repository heads are not affected'), |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
69 |
), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 |
(b't', b'tombstone', b'', _(b'replacement tombstone data'), _(b'TEXT')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
71 |
], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 |
_(b'-r REV [-t TEXT] [FILE]'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
73 |
helpcategory=command.CATEGORY_MAINTENANCE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
74 |
) |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
75 |
def censor(ui, repo, path, rev=(), tombstone=b'', check_heads=True, **opts): |
38441
e219e355e088
censor: use context manager for lock management
Matt Harbison <matt_harbison@yahoo.com>
parents:
37442
diff
changeset
|
76 |
with repo.wlock(), repo.lock(): |
51268
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
77 |
return _docensor( |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
78 |
ui, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
79 |
repo, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
80 |
path, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
81 |
rev, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
82 |
tombstone, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
83 |
check_heads=check_heads, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
84 |
**opts, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
85 |
) |
27290
525d9b3f0a31
censor: make censor acquire locks before processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26781
diff
changeset
|
86 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
87 |
|
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
88 |
def _docensor(ui, repo, path, revs=(), tombstone=b'', check_heads=True, **opts): |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
89 |
if not path: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
90 |
raise error.Abort(_(b'must specify file path to censor')) |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
91 |
if not revs: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
92 |
raise error.Abort(_(b'must specify revisions to censor')) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
93 |
|
25806
5e18f6e39006
censor: make various path forms available like other Mercurial commands
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25660
diff
changeset
|
94 |
wctx = repo[None] |
5e18f6e39006
censor: make various path forms available like other Mercurial commands
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25660
diff
changeset
|
95 |
|
5e18f6e39006
censor: make various path forms available like other Mercurial commands
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25660
diff
changeset
|
96 |
m = scmutil.match(wctx, (path,)) |
5e18f6e39006
censor: make various path forms available like other Mercurial commands
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25660
diff
changeset
|
97 |
if m.anypats() or len(m.files()) != 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 |
raise error.Abort(_(b'can only specify an explicit filename')) |
25806
5e18f6e39006
censor: make various path forms available like other Mercurial commands
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25660
diff
changeset
|
99 |
path = m.files()[0] |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
100 |
flog = repo.file(path) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
101 |
if not len(flog): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 |
raise error.Abort(_(b'cannot censor file with no history')) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
103 |
|
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
104 |
revs = scmutil.revrange(repo, revs) |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
105 |
if not revs: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
106 |
raise error.Abort(_(b'no matching revisions')) |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
107 |
file_nodes = set() |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
108 |
for r in revs: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
109 |
try: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
110 |
ctx = repo[r] |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
111 |
file_nodes.add(ctx.filectx(path).filenode()) |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
112 |
except error.LookupError: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
113 |
raise error.Abort(_(b'file does not exist at revision %s') % ctx) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
114 |
|
51268
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
115 |
if check_heads: |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
116 |
heads = [] |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
117 |
repo_heads = repo.heads() |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
118 |
msg = b'checking for the censored content in %d heads\n' |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
119 |
msg %= len(repo_heads) |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
120 |
ui.status(msg) |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
121 |
for headnode in repo_heads: |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
122 |
hc = repo[headnode] |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
123 |
if path in hc and hc.filenode(path) in file_nodes: |
51268
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
124 |
heads.append(hc) |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
125 |
if heads: |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
126 |
headlist = b', '.join([short(c.node()) for c in heads]) |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
127 |
raise error.Abort( |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
128 |
_(b'cannot censor file in heads (%s)') % headlist, |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
129 |
hint=_(b'clean/delete and commit first'), |
622f00b350be
censor: add a command flag to skip the head checks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51267
diff
changeset
|
130 |
) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
131 |
|
51269
db121ddd171e
censor: be more verbose about the other steps too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51268
diff
changeset
|
132 |
msg = b'checking for the censored content in the working directory\n' |
db121ddd171e
censor: be more verbose about the other steps too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51268
diff
changeset
|
133 |
ui.status(msg) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
134 |
wp = wctx.parents() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
135 |
if ctx.node() in [p.node() for p in wp]: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
136 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
137 |
_(b'cannot censor working directory'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
138 |
hint=_(b'clean/delete/update first'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
139 |
) |
24347
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
140 |
|
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
141 |
msg = b'censoring %d file revisions\n' |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
142 |
msg %= len(file_nodes) |
51269
db121ddd171e
censor: be more verbose about the other steps too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51268
diff
changeset
|
143 |
ui.status(msg) |
39778
a6b3c4c1019f
revlog: move censor logic out of censor extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39661
diff
changeset
|
144 |
with repo.transaction(b'censor') as tr: |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51269
diff
changeset
|
145 |
flog.censorrevision(tr, file_nodes, tombstone=tombstone) |