Mercurial > hg-stable
annotate hgext/censor.py @ 24880:5e111acc1170 stable
censor: remove meaningless explanation about .hgcensored
There is no code path handling ".hgcensored" in Mercurial source tree.
This meaningless explanation may make users misunderstand about
censor.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Thu, 30 Apr 2015 03:39:39 +0900 |
parents | 1bcfecbbf569 |
children | cba84b06b702 |
rev | line source |
---|---|
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 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
16 * Passwords, private keys, crytographic material |
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 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
25 revisions if they are allowed by the policy specified by the "censor.allow" |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
26 config option. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
27 """ |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
28 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
29 from mercurial.node import short |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
30 from mercurial import cmdutil, error, filelog, revlog, scmutil, util |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
31 from mercurial.i18n import _ |
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 cmdtable = {} |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
34 command = cmdutil.command(cmdtable) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
35 testedwith = 'internal' |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
36 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
37 @command('censor', |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
38 [('r', 'rev', '', _('censor file from specified revision'), _('REV')), |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
39 ('t', 'tombstone', '', _('replacement tombstone data'), _('TEXT'))], |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
40 _('-r REV [-t TEXT] [FILE]')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
41 def censor(ui, repo, path, rev='', tombstone='', **opts): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
42 if not path: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
43 raise util.Abort(_('must specify file path to censor')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
44 if not rev: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
45 raise util.Abort(_('must specify revision to censor')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
46 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
47 flog = repo.file(path) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
48 if not len(flog): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
49 raise util.Abort(_('cannot censor file with no history')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
50 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
51 rev = scmutil.revsingle(repo, rev, rev).rev() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
52 try: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
53 ctx = repo[rev] |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
54 except KeyError: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
55 raise util.Abort(_('invalid revision identifier %s') % rev) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
56 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
57 try: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
58 fctx = ctx.filectx(path) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
59 except error.LookupError: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
60 raise util.Abort(_('file does not exist at revision %s') % rev) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
61 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
62 fnode = fctx.filenode() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
63 headctxs = [repo[c] for c in repo.heads()] |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
64 heads = [c for c in headctxs if path in c and c.filenode(path) == fnode] |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
65 if heads: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
66 headlist = ', '.join([short(c.node()) for c in heads]) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
67 raise util.Abort(_('cannot censor file in heads (%s)') % headlist, |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
68 hint=_('clean/delete and commit first')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
69 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
70 wctx = repo[None] |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
71 wp = wctx.parents() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
72 if ctx.node() in [p.node() for p in wp]: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
73 raise util.Abort(_('cannot censor working directory'), |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
74 hint=_('clean/delete/update first')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
75 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
76 flogv = flog.version & 0xFFFF |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
77 if flogv != revlog.REVLOGNG: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
78 raise util.Abort( |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
79 _('censor does not support revlog version %d') % (flogv,)) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
80 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
81 tombstone = filelog.packmeta({"censored": tombstone}, "") |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
82 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
83 crev = fctx.filerev() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
84 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
85 if len(tombstone) > flog.rawsize(crev): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
86 raise util.Abort(_( |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
87 'censor tombstone must be no longer than censored data')) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
88 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
89 # Using two files instead of one makes it easy to rewrite entry-by-entry |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
90 idxread = repo.svfs(flog.indexfile, 'r') |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
91 idxwrite = repo.svfs(flog.indexfile, 'wb', atomictemp=True) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
92 if flog.version & revlog.REVLOGNGINLINEDATA: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
93 dataread, datawrite = idxread, idxwrite |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
94 else: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
95 dataread = repo.svfs(flog.datafile, 'r') |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
96 datawrite = repo.svfs(flog.datafile, 'wb', atomictemp=True) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
97 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
98 # Copy all revlog data up to the entry to be censored. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
99 rio = revlog.revlogio() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
100 offset = flog.start(crev) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
101 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
102 for chunk in util.filechunkiter(idxread, limit=crev * rio.size): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
103 idxwrite.write(chunk) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
104 for chunk in util.filechunkiter(dataread, limit=offset): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
105 datawrite.write(chunk) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
106 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
107 def rewriteindex(r, newoffs, newdata=None): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
108 """Rewrite the index entry with a new data offset and optional new data. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
109 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
110 The newdata argument, if given, is a tuple of three positive integers: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
111 (new compressed, new uncompressed, added flag bits). |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
112 """ |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
113 offlags, comp, uncomp, base, link, p1, p2, nodeid = flog.index[r] |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
114 flags = revlog.gettype(offlags) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
115 if newdata: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
116 comp, uncomp, nflags = newdata |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
117 flags |= nflags |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
118 offlags = revlog.offset_type(newoffs, flags) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
119 e = (offlags, comp, uncomp, r, link, p1, p2, nodeid) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
120 idxwrite.write(rio.packentry(e, None, flog.version, r)) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
121 idxread.seek(rio.size, 1) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
122 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
123 def rewrite(r, offs, data, nflags=revlog.REVIDX_DEFAULT_FLAGS): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
124 """Write the given full text to the filelog with the given data offset. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
125 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
126 Returns: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
127 The integer number of data bytes written, for tracking data offsets. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
128 """ |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
129 flag, compdata = flog.compress(data) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
130 newcomp = len(flag) + len(compdata) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
131 rewriteindex(r, offs, (newcomp, len(data), nflags)) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
132 datawrite.write(flag) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
133 datawrite.write(compdata) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
134 dataread.seek(flog.length(r), 1) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
135 return newcomp |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
136 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
137 # Rewrite censored revlog entry with (padded) tombstone data. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
138 pad = ' ' * (flog.rawsize(crev) - len(tombstone)) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
139 offset += rewrite(crev, offset, tombstone + pad, revlog.REVIDX_ISCENSORED) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
140 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
141 # Rewrite all following filelog revisions fixing up offsets and deltas. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
142 for srev in xrange(crev + 1, len(flog)): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
143 if crev in flog.parentrevs(srev): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
144 # Immediate children of censored node must be re-added as fulltext. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
145 try: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
146 revdata = flog.revision(srev) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
147 except error.CensoredNodeError, e: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
148 revdata = e.tombstone |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
149 dlen = rewrite(srev, offset, revdata) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
150 else: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
151 # Copy any other revision data verbatim after fixing up the offset. |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
152 rewriteindex(srev, offset) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
153 dlen = flog.length(srev) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
154 for chunk in util.filechunkiter(dataread, limit=dlen): |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
155 datawrite.write(chunk) |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
156 offset += dlen |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
157 |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
158 idxread.close() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
159 idxwrite.close() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
160 if dataread is not idxread: |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
161 dataread.close() |
1bcfecbbf569
censor: add censor command to hgext with basic client-side tests
Mike Edgar <adgar@google.com>
parents:
diff
changeset
|
162 datawrite.close() |