Show More
@@ -32,7 +32,6 b' from mercurial.node import short' | |||||
32 |
|
32 | |||
33 | from mercurial import ( |
|
33 | from mercurial import ( | |
34 | error, |
|
34 | error, | |
35 | filelog, |
|
|||
36 | lock as lockmod, |
|
35 | lock as lockmod, | |
37 | registrar, |
|
36 | registrar, | |
38 | revlog, |
|
37 | revlog, | |
@@ -106,7 +105,7 b" def _docensor(ui, repo, path, rev='', to" | |||||
106 | raise error.Abort( |
|
105 | raise error.Abort( | |
107 | _('censor does not support revlog version %d') % (flogv,)) |
|
106 | _('censor does not support revlog version %d') % (flogv,)) | |
108 |
|
107 | |||
109 |
tombstone = |
|
108 | tombstone = revlog.packmeta({"censored": tombstone}, "") | |
110 |
|
109 | |||
111 | crev = fctx.filerev() |
|
110 | crev = fctx.filerev() | |
112 |
|
111 |
@@ -14,7 +14,6 b' from mercurial.node import bin, hex, nul' | |||||
14 |
|
14 | |||
15 | from mercurial import ( |
|
15 | from mercurial import ( | |
16 | error, |
|
16 | error, | |
17 | filelog, |
|
|||
18 | revlog, |
|
17 | revlog, | |
19 | util, |
|
18 | util, | |
20 | ) |
|
19 | ) | |
@@ -69,13 +68,13 b' def readfromstore(self, text):' | |||||
69 | name = k[len('x-hg-'):] |
|
68 | name = k[len('x-hg-'):] | |
70 | hgmeta[name] = p[k] |
|
69 | hgmeta[name] = p[k] | |
71 | if hgmeta or text.startswith('\1\n'): |
|
70 | if hgmeta or text.startswith('\1\n'): | |
72 |
text = |
|
71 | text = revlog.packmeta(hgmeta, text) | |
73 |
|
72 | |||
74 | return (text, True) |
|
73 | return (text, True) | |
75 |
|
74 | |||
76 | def writetostore(self, text): |
|
75 | def writetostore(self, text): | |
77 | # hg filelog metadata (includes rename, etc) |
|
76 | # hg filelog metadata (includes rename, etc) | |
78 |
hgmeta, offset = |
|
77 | hgmeta, offset = revlog.parsemeta(text) | |
79 | if offset and offset > 0: |
|
78 | if offset and offset > 0: | |
80 | # lfs blob does not contain hg filelog metadata |
|
79 | # lfs blob does not contain hg filelog metadata | |
81 | text = text[offset:] |
|
80 | text = text[offset:] | |
@@ -121,7 +120,7 b' def filelogaddrevision(orig, self, text,' | |||||
121 | flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds): |
|
120 | flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds): | |
122 | textlen = len(text) |
|
121 | textlen = len(text) | |
123 | # exclude hg rename meta from file size |
|
122 | # exclude hg rename meta from file size | |
124 |
meta, offset = |
|
123 | meta, offset = revlog.parsemeta(text) | |
125 | if offset: |
|
124 | if offset: | |
126 | textlen -= offset |
|
125 | textlen -= offset | |
127 |
|
126 |
@@ -7,7 +7,6 b'' | |||||
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import re |
|
|||
11 | import struct |
|
10 | import struct | |
12 |
|
11 | |||
13 | from .thirdparty.zope import ( |
|
12 | from .thirdparty.zope import ( | |
@@ -20,27 +19,8 b' from . import (' | |||||
20 | revlog, |
|
19 | revlog, | |
21 | ) |
|
20 | ) | |
22 |
|
21 | |||
23 | _mdre = re.compile('\1\n') |
|
|||
24 | def parsemeta(text): |
|
|||
25 | """return (metadatadict, metadatasize)""" |
|
|||
26 | # text can be buffer, so we can't use .startswith or .index |
|
|||
27 | if text[:2] != '\1\n': |
|
|||
28 | return None, None |
|
|||
29 | s = _mdre.search(text, 2).start() |
|
|||
30 | mtext = text[2:s] |
|
|||
31 | meta = {} |
|
|||
32 | for l in mtext.splitlines(): |
|
|||
33 | k, v = l.split(": ", 1) |
|
|||
34 | meta[k] = v |
|
|||
35 | return meta, (s + 2) |
|
|||
36 |
|
||||
37 | def packmeta(meta, text): |
|
|||
38 | keys = sorted(meta) |
|
|||
39 | metatext = "".join("%s: %s\n" % (k, meta[k]) for k in keys) |
|
|||
40 | return "\1\n%s\1\n%s" % (metatext, text) |
|
|||
41 |
|
||||
42 | def _censoredtext(text): |
|
22 | def _censoredtext(text): | |
43 | m, offs = parsemeta(text) |
|
23 | m, offs = revlog.parsemeta(text) | |
44 | return m and "censored" in m |
|
24 | return m and "censored" in m | |
45 |
|
25 | |||
46 | @zi.implementer(repository.ifilestorage) |
|
26 | @zi.implementer(repository.ifilestorage) | |
@@ -60,14 +40,14 b' class filelog(revlog.revlog):' | |||||
60 |
|
40 | |||
61 | def add(self, text, meta, transaction, link, p1=None, p2=None): |
|
41 | def add(self, text, meta, transaction, link, p1=None, p2=None): | |
62 | if meta or text.startswith('\1\n'): |
|
42 | if meta or text.startswith('\1\n'): | |
63 | text = packmeta(meta, text) |
|
43 | text = revlog.packmeta(meta, text) | |
64 | return self.addrevision(text, transaction, link, p1, p2) |
|
44 | return self.addrevision(text, transaction, link, p1, p2) | |
65 |
|
45 | |||
66 | def renamed(self, node): |
|
46 | def renamed(self, node): | |
67 | if self.parents(node)[0] != revlog.nullid: |
|
47 | if self.parents(node)[0] != revlog.nullid: | |
68 | return False |
|
48 | return False | |
69 | t = self.revision(node) |
|
49 | t = self.revision(node) | |
70 | m = parsemeta(t)[0] |
|
50 | m = revlog.parsemeta(t)[0] | |
71 | if m and "copy" in m: |
|
51 | if m and "copy" in m: | |
72 | return (m["copy"], revlog.bin(m["copyrev"])) |
|
52 | return (m["copy"], revlog.bin(m["copyrev"])) | |
73 | return False |
|
53 | return False |
@@ -19,6 +19,7 b' import errno' | |||||
19 | import hashlib |
|
19 | import hashlib | |
20 | import heapq |
|
20 | import heapq | |
21 | import os |
|
21 | import os | |
|
22 | import re | |||
22 | import struct |
|
23 | import struct | |
23 | import zlib |
|
24 | import zlib | |
24 |
|
25 | |||
@@ -97,6 +98,25 b' ProgrammingError = error.ProgrammingErro' | |||||
97 | REVIDX_ISCENSORED: None, |
|
98 | REVIDX_ISCENSORED: None, | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
|
101 | _mdre = re.compile('\1\n') | |||
|
102 | def parsemeta(text): | |||
|
103 | """return (metadatadict, metadatasize)""" | |||
|
104 | # text can be buffer, so we can't use .startswith or .index | |||
|
105 | if text[:2] != '\1\n': | |||
|
106 | return None, None | |||
|
107 | s = _mdre.search(text, 2).start() | |||
|
108 | mtext = text[2:s] | |||
|
109 | meta = {} | |||
|
110 | for l in mtext.splitlines(): | |||
|
111 | k, v = l.split(": ", 1) | |||
|
112 | meta[k] = v | |||
|
113 | return meta, (s + 2) | |||
|
114 | ||||
|
115 | def packmeta(meta, text): | |||
|
116 | keys = sorted(meta) | |||
|
117 | metatext = "".join("%s: %s\n" % (k, meta[k]) for k in keys) | |||
|
118 | return "\1\n%s\1\n%s" % (metatext, text) | |||
|
119 | ||||
100 | def addflagprocessor(flag, processor): |
|
120 | def addflagprocessor(flag, processor): | |
101 | """Register a flag processor on a revision data flag. |
|
121 | """Register a flag processor on a revision data flag. | |
102 |
|
122 |
@@ -32,7 +32,6 b' from mercurial import (' | |||||
32 | bundlerepo, |
|
32 | bundlerepo, | |
33 | error, |
|
33 | error, | |
34 | extensions, |
|
34 | extensions, | |
35 | filelog, |
|
|||
36 | localrepo, |
|
35 | localrepo, | |
37 | mdiff, |
|
36 | mdiff, | |
38 | pycompat, |
|
37 | pycompat, | |
@@ -326,7 +325,7 b' class filestorage(object):' | |||||
326 | return False |
|
325 | return False | |
327 |
|
326 | |||
328 | fulltext = self.revision(node) |
|
327 | fulltext = self.revision(node) | |
329 |
m = |
|
328 | m = revlog.parsemeta(fulltext)[0] | |
330 |
|
329 | |||
331 | if m and 'copy' in m: |
|
330 | if m and 'copy' in m: | |
332 | return m['copy'], bin(m['copyrev']) |
|
331 | return m['copy'], bin(m['copyrev']) | |
@@ -415,7 +414,7 b' class filestorage(object):' | |||||
415 |
|
414 | |||
416 | def add(self, text, meta, transaction, linkrev, p1, p2): |
|
415 | def add(self, text, meta, transaction, linkrev, p1, p2): | |
417 | if meta or text.startswith(b'\1\n'): |
|
416 | if meta or text.startswith(b'\1\n'): | |
418 |
text = |
|
417 | text = revlog.packmeta(meta, text) | |
419 |
|
418 | |||
420 | return self.addrevision(text, transaction, linkrev, p1, p2) |
|
419 | return self.addrevision(text, transaction, linkrev, p1, p2) | |
421 |
|
420 |
General Comments 0
You need to be logged in to leave comments.
Login now