annotate mercurial/changelog.py @ 51846:243e805e8a2d

ci: add the option to test more Python versions It seems like a good idea to be able to test the lowest version we support. And there have been enougth issue with 3.12 that we need to be able to make sur we do not break it. We should probably get a matrix setup for more version and flavor, but that is a simple and efficient start.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 28 Aug 2024 16:35:43 +0200
parents 278af66e6595
children f4733654f144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1095
0a18374c0769 changelog: adjust imports, comment
mpm@selenic.com
parents: 1094 1089
diff changeset
1 # changelog.py - changelog class for mercurial
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46780
diff changeset
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9677
diff changeset
6 # 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
7
25922
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
8
51729
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
9 import typing
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
10
25922
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
11 from .i18n import _
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
12 from .node import (
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
13 bin,
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
14 hex,
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
15 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
16 from .thirdparty import attr
25922
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
17
51729
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
18 # Force pytype to use the non-vendored package
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
19 if typing.TYPE_CHECKING:
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
20 # noinspection PyPackageRequirements
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
21 import attr
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51642
diff changeset
22
25922
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
23 from . import (
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
24 encoding,
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
25 error,
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44792
diff changeset
26 metadata,
36228
ddeb7653b31c py3: use pycompat.bytestr to convert str to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35974
diff changeset
27 pycompat,
25922
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
28 revlog,
85f442747153 changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25814
diff changeset
29 )
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
30 from .utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
31 dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
32 stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
33 )
47072
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
34 from .revlogutils import (
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
35 constants as revlog_constants,
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
36 flagutil,
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
37 )
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
38
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
39 _defaultextra = {b'branch': b'default'}
16267
aa6821a7b52f changelog: micro-optimizations to changelog.read()
Matt Mackall <mpm@selenic.com>
parents: 15661
diff changeset
40
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
41
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
42 def _string_escape(text):
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
43 """
34133
708b5530a273 doctest: replace chr() with pycompat.bytechr()
Yuya Nishihara <yuya@tcha.org>
parents: 34132
diff changeset
44 >>> from .pycompat import bytechr as chr
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34028
diff changeset
45 >>> d = {b'nl': chr(10), b'bs': chr(92), b'cr': chr(13), b'nul': chr(0)}
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
46 >>> s = b"ab%(nl)scd%(bs)s%(bs)sn%(nul)s12ab%(cr)scd%(bs)s%(nl)s" % d
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
47 >>> s
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
48 'ab\\ncd\\\\\\\\n\\x0012ab\\rcd\\\\\\n'
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
49 >>> res = _string_escape(s)
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
50 >>> s == _string_unescape(res)
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
51 True
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
52 """
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
53 # subset of the string_escape codec
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
54 text = (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
55 text.replace(b'\\', b'\\\\')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
56 .replace(b'\n', b'\\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
57 .replace(b'\r', b'\\r')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
58 )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
59 return text.replace(b'\0', b'\\0')
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3077
diff changeset
60
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
61
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
62 def _string_unescape(text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
63 if b'\\0' in text:
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
64 # fix up \0 without getting into trouble with \\0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
65 text = text.replace(b'\\\\', b'\\\\\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
66 text = text.replace(b'\\0', b'\0')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
67 text = text.replace(b'\n', b'')
42116
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
68 return stringutil.unescapestr(text)
caa067ee21dc changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41831
diff changeset
69
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
70
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
71 def decodeextra(text):
15661
20ae902c43ec changelog: handle decoding of NULs in extra more carefully (issue3156)
Matt Mackall <mpm@selenic.com>
parents: 14643
diff changeset
72 """
34133
708b5530a273 doctest: replace chr() with pycompat.bytechr()
Yuya Nishihara <yuya@tcha.org>
parents: 34132
diff changeset
73 >>> from .pycompat import bytechr as chr
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34028
diff changeset
74 >>> sorted(decodeextra(encodeextra({b'foo': b'bar', b'baz': chr(0) + b'2'})
34132
264872544362 doctest: replace .iteritems() with .items()
Yuya Nishihara <yuya@tcha.org>
parents: 34131
diff changeset
75 ... ).items())
18379
e0c4f4ba624c tests: fix doctest stability over Python versions
Mads Kiilerich <madski@unity3d.com>
parents: 18378
diff changeset
76 [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')]
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34028
diff changeset
77 >>> sorted(decodeextra(encodeextra({b'foo': b'bar',
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34028
diff changeset
78 ... b'baz': chr(92) + chr(0) + b'2'})
34132
264872544362 doctest: replace .iteritems() with .items()
Yuya Nishihara <yuya@tcha.org>
parents: 34131
diff changeset
79 ... ).items())
18379
e0c4f4ba624c tests: fix doctest stability over Python versions
Mads Kiilerich <madski@unity3d.com>
parents: 18378
diff changeset
80 [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')]
15661
20ae902c43ec changelog: handle decoding of NULs in extra more carefully (issue3156)
Matt Mackall <mpm@selenic.com>
parents: 14643
diff changeset
81 """
16267
aa6821a7b52f changelog: micro-optimizations to changelog.read()
Matt Mackall <mpm@selenic.com>
parents: 15661
diff changeset
82 extra = _defaultextra.copy()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
83 for l in text.split(b'\0'):
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
84 if l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
85 k, v = _string_unescape(l).split(b':', 1)
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
86 extra[k] = v
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
87 return extra
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
88
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
89
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
90 def encodeextra(d):
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
91 # keys must be sorted to produce a deterministic changelog entry
44604
2141427533d2 py3: require values in changelog extras to be bytes
Martin von Zweigbergk <martinvonz@google.com>
parents: 44055
diff changeset
92 items = [_string_escape(b'%s:%s' % (k, d[k])) for k in sorted(d)]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
93 return b"\0".join(items)
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
94
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
95
17810
2894d180afa1 changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17677
diff changeset
96 def stripdesc(desc):
2894d180afa1 changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17677
diff changeset
97 """strip trailing whitespace and leading and trailing empty lines"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
98 return b'\n'.join([l.rstrip() for l in desc.splitlines()]).strip(b'\n')
17810
2894d180afa1 changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17677
diff changeset
99
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
100
34398
e51c8ffa1ffa changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents: 34296
diff changeset
101 @attr.s
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
102 class _changelogrevision:
34398
e51c8ffa1ffa changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents: 34296
diff changeset
103 # Extensions might modify _defaultextra, so let the constructor below pass
e51c8ffa1ffa changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents: 34296
diff changeset
104 # it in
e51c8ffa1ffa changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents: 34296
diff changeset
105 extra = attr.ib()
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46714
diff changeset
106 manifest = attr.ib()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
107 user = attr.ib(default=b'')
34398
e51c8ffa1ffa changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents: 34296
diff changeset
108 date = attr.ib(default=(0, 0))
34441
50474f0b3f1b changelog: use a Factory for default value for files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34398
diff changeset
109 files = attr.ib(default=attr.Factory(list))
42407
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
110 filesadded = attr.ib(default=None)
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
111 filesremoved = attr.ib(default=None)
42301
2a7109cc5a28 changelog: define changelogrevision.p[12]copies for null revision
Martin von Zweigbergk <martinvonz@google.com>
parents: 42300
diff changeset
112 p1copies = attr.ib(default=None)
2a7109cc5a28 changelog: define changelogrevision.p[12]copies for null revision
Martin von Zweigbergk <martinvonz@google.com>
parents: 42300
diff changeset
113 p2copies = attr.ib(default=None)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
114 description = attr.ib(default=b'')
46370
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
115 branchinfo = attr.ib(default=(_defaultextra[b'branch'], False))
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
116
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
117
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
118 class changelogrevision:
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
119 """Holds results of a parsed changelog revision.
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
120
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
121 Changelog revisions consist of multiple pieces of data, including
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
122 the manifest node, user, and date. This object exposes a view into
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
123 the parsed object.
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
124 """
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
125
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
126 __slots__ = (
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43453
diff changeset
127 '_offsets',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43453
diff changeset
128 '_text',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43453
diff changeset
129 '_sidedata',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43453
diff changeset
130 '_cpsd',
45570
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
131 '_changes',
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
132 )
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
133
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46714
diff changeset
134 def __new__(cls, cl, text, sidedata, cpsd):
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
135 if not text:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
136 return _changelogrevision(extra=_defaultextra, manifest=cl.nullid)
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
137
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
138 self = super(changelogrevision, cls).__new__(cls)
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
139 # We could return here and implement the following as an __init__.
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
140 # But doing it here is equivalent and saves an extra function call.
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
141
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
142 # format used:
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
143 # nodeid\n : manifest node in ascii
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
144 # user\n : user, no \n or \r allowed
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
145 # time tz extra\n : date (time is int or float, timezone is int)
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
146 # : extra is metadata, encoded and separated by '\0'
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
147 # : older versions ignore it
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
148 # files\n\n : files modified by the cset, no \n or \r allowed
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
149 # (.*) : comment (free text, ideally utf-8)
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
150 #
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
151 # changelog v0 doesn't use extra
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
152
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
153 nl1 = text.index(b'\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
154 nl2 = text.index(b'\n', nl1 + 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
155 nl3 = text.index(b'\n', nl2 + 1)
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
156
28493
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
157 # The list of files may be empty. Which means nl3 is the first of the
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
158 # double newline that precedes the description.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
159 if text[nl3 + 1 : nl3 + 2] == b'\n':
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
160 doublenl = nl3
28493
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
161 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
162 doublenl = text.index(b'\n\n', nl3 + 1)
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
163
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
164 self._offsets = (nl1, nl2, nl3, doublenl)
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
165 self._text = text
43143
037a8759eda1 sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43142
diff changeset
166 self._sidedata = sidedata
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
167 self._cpsd = cpsd
45570
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
168 self._changes = None
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
169
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
170 return self
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
171
28489
8939a95064f1 changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28487
diff changeset
172 @property
28490
959eadae589a changelog: lazily parse manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28489
diff changeset
173 def manifest(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
174 return bin(self._text[0 : self._offsets[0]])
28490
959eadae589a changelog: lazily parse manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28489
diff changeset
175
959eadae589a changelog: lazily parse manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28489
diff changeset
176 @property
28491
f57f7500a095 changelog: lazily parse user
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28490
diff changeset
177 def user(self):
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
178 off = self._offsets
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
179 return encoding.tolocal(self._text[off[0] + 1 : off[1]])
28491
f57f7500a095 changelog: lazily parse user
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28490
diff changeset
180
f57f7500a095 changelog: lazily parse user
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28490
diff changeset
181 @property
28492
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
182 def _rawdate(self):
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
183 off = self._offsets
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
184 dateextra = self._text[off[1] + 1 : off[2]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
185 return dateextra.split(b' ', 2)[0:2]
28492
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
186
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
187 @property
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
188 def _rawextra(self):
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
189 off = self._offsets
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
190 dateextra = self._text[off[1] + 1 : off[2]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
191 fields = dateextra.split(b' ', 2)
28492
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
192 if len(fields) != 3:
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
193 return None
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
194
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
195 return fields[2]
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
196
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
197 @property
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
198 def date(self):
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
199 raw = self._rawdate
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
200 time = float(raw[0])
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
201 # Various tools did silly things with the timezone.
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
202 try:
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
203 timezone = int(raw[1])
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
204 except ValueError:
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
205 timezone = 0
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
206
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
207 return time, timezone
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
208
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
209 @property
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
210 def extra(self):
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
211 raw = self._rawextra
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
212 if raw is None:
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
213 return _defaultextra
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
214
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
215 return decodeextra(raw)
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
216
837f1c437d58 changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28491
diff changeset
217 @property
45570
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
218 def changes(self):
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
219 if self._changes is not None:
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
220 return self._changes
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
221 if self._cpsd:
45635
9003e6524f78 changing-files: drop the now useless changelogrevision argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45575
diff changeset
222 changes = metadata.decode_files_sidedata(self._sidedata)
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
223 else:
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
224 changes = metadata.ChangingFiles(
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
225 touched=self.files or (),
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
226 added=self.filesadded or (),
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
227 removed=self.filesremoved or (),
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
228 p1_copies=self.p1copies or {},
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
229 p2_copies=self.p2copies or {},
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45570
diff changeset
230 )
45570
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
231 self._changes = changes
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
232 return changes
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
233
9a3563b46f52 changelog: add a `changes` property on `changelogrevision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
234 @property
28493
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
235 def files(self):
45636
053c9014fd39 changing-files: retrieve changelogrevision.files from the sidedata block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
236 if self._cpsd:
053c9014fd39 changing-files: retrieve changelogrevision.files from the sidedata block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
237 return sorted(self.changes.touched)
28495
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
238 off = self._offsets
70c2f8a98276 changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28494
diff changeset
239 if off[2] == off[3]:
28493
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
240 return []
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
241
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
242 return self._text[off[2] + 1 : off[3]].split(b'\n')
28493
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
243
7796473c11b3 changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28492
diff changeset
244 @property
42407
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
245 def filesadded(self):
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
246 if self._cpsd:
45572
48c93a0b2acb sidedata: simply read added files from the `ChangingFiles` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
247 return self.changes.added
43146
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
248 else:
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
249 rawindices = self.extra.get(b'filesadded')
43145
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
250 if rawindices is None:
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
251 return None
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44792
diff changeset
252 return metadata.decodefileindices(self.files, rawindices)
42407
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
253
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
254 @property
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
255 def filesremoved(self):
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
256 if self._cpsd:
45573
f9a67afcc33b sidedata: simply read removed files from the `ChangingFiles` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45572
diff changeset
257 return self.changes.removed
43146
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
258 else:
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
259 rawindices = self.extra.get(b'filesremoved')
43145
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
260 if rawindices is None:
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
261 return None
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44792
diff changeset
262 return metadata.decodefileindices(self.files, rawindices)
42407
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
263
602469a91550 context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 42406
diff changeset
264 @property
42142
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
265 def p1copies(self):
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
266 if self._cpsd:
45574
4e2238ba51a4 sidedata: simply read p1copies files from the `ChangingFiles` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45573
diff changeset
267 return self.changes.copied_from_p1
43146
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
268 else:
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
269 rawcopies = self.extra.get(b'p1copies')
43145
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
270 if rawcopies is None:
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
271 return None
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44792
diff changeset
272 return metadata.decodecopies(self.files, rawcopies)
42142
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
273
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
274 @property
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
275 def p2copies(self):
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
276 if self._cpsd:
45575
147fb889278b sidedata: simply read p2copies files from the `ChangingFiles` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45574
diff changeset
277 return self.changes.copied_from_p2
43146
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
278 else:
0171483b082f sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43145
diff changeset
279 rawcopies = self.extra.get(b'p2copies')
43145
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
280 if rawcopies is None:
4296cc3c4ae1 changelog: make copies related function return None or a valid value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43143
diff changeset
281 return None
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44792
diff changeset
282 return metadata.decodecopies(self.files, rawcopies)
42142
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
283
5382d8f8530b changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents: 42141
diff changeset
284 @property
28489
8939a95064f1 changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28487
diff changeset
285 def description(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
286 return encoding.tolocal(self._text[self._offsets[3] + 2 :])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
287
46370
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
288 @property
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
289 def branchinfo(self):
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
290 extra = self.extra
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
291 return encoding.tolocal(extra.get(b"branch")), b'close' in extra
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
292
28489
8939a95064f1 changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28487
diff changeset
293
7634
14a4337a9b9b revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
294 class changelog(revlog.revlog):
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents: 46509
diff changeset
295 def __init__(self, opener, trypending=False, concurrencychecker=None):
32292
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
296 """Load a changelog revlog using an opener.
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
297
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
298 If ``trypending`` is true, we attempt to load the index from a
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
299 ``00changelog.i.a`` file instead of the default ``00changelog.i``.
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
300 The ``00changelog.i.a`` file contains index (and possibly inline
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
301 revision) data for a transaction that hasn't been finalized yet.
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
302 It exists in a separate file to facilitate readers (such as
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
303 hooks processes) accessing data before a transaction is finalized.
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents: 46509
diff changeset
304
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents: 46509
diff changeset
305 ``concurrencychecker`` will be passed to the revlog init function, see
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents: 46509
diff changeset
306 the documentation there.
32292
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
307 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
308 revlog.revlog.__init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
309 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
310 opener,
47072
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
311 target=(revlog_constants.KIND_CHANGELOG, None),
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
312 radix=b'00changelog',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
313 checkambig=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
314 mmaplargeindex=True,
44792
5e3c718692bb nodemap: drop the 'exp-' prefix for internal opener option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44661
diff changeset
315 persistentnodemap=opener.options.get(b'persistent-nodemap', False),
46607
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents: 46509
diff changeset
316 concurrencychecker=concurrencychecker,
47240
4f38ada3fc26 revlog: move the `trypending` logic from the `changelog` to the `revlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47239
diff changeset
317 trypending=trypending,
51181
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
318 may_inline=False,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
319 )
32292
0ad0d26ff703 changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32262
diff changeset
320
47139
f58a13c52726 revlog: split the `version` attribute into its two components
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
321 if self._initempty and (self._format_version == revlog.REVLOGV1):
41202
e7a2cc84dbc0 revlog: always enable generaldelta on version 2 revlogs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39887
diff changeset
322 # changelogs don't benefit from generaldelta.
e7a2cc84dbc0 revlog: always enable generaldelta on version 2 revlogs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39887
diff changeset
323
47139
f58a13c52726 revlog: split the `version` attribute into its two components
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
324 self._format_flags &= ~revlog.FLAG_GENERALDELTA
51029
498afb627f78 revlog: move configuration attribute into dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51010
diff changeset
325 self.delta_config.general_delta = False
30155
b7a966ce89ed changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30000
diff changeset
326
b7a966ce89ed changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30000
diff changeset
327 # Delta chains for changelogs tend to be very small because entries
b7a966ce89ed changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30000
diff changeset
328 # tend to be small and don't delta well with each. So disable delta
b7a966ce89ed changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30000
diff changeset
329 # chains.
39232
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39201
diff changeset
330 self._storedeltachains = False
30155
b7a966ce89ed changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30000
diff changeset
331
51106
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
332 self._v2_delayed = False
45515
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
333 self._filteredrevs = frozenset()
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
334 self._filteredrevs_hashcache = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
335 self._copiesstorage = opener.options.get(b'copies-storage')
17677
5c89e7fa5bc2 clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17424
diff changeset
336
51458
ec8c1d0f6d48 repoview: fix changelog.__contains__ method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
337 def __contains__(self, rev):
ec8c1d0f6d48 repoview: fix changelog.__contains__ method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
338 return (0 <= rev < len(self)) and rev not in self._filteredrevs
ec8c1d0f6d48 repoview: fix changelog.__contains__ method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
339
45515
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
340 @property
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
341 def filteredrevs(self):
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
342 return self._filteredrevs
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
343
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
344 @filteredrevs.setter
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
345 def filteredrevs(self, val):
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
346 # Ensure all updates go through this function
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
347 assert isinstance(val, frozenset)
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
348 self._filteredrevs = val
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
349 self._filteredrevs_hashcache = {}
89f0d9f87701 branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents: 45325
diff changeset
350
47239
682f09857d69 revlogv2: delay the update of the changelog docket to transaction end
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
351 def _write_docket(self, tr):
51106
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
352 if not self._v2_delayed:
47239
682f09857d69 revlogv2: delay the update of the changelog docket to transaction end
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
353 super(changelog, self)._write_docket(tr)
682f09857d69 revlogv2: delay the update of the changelog docket to transaction end
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
354
23203
3872d563e01a changelog: handle writepending in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23201
diff changeset
355 def delayupdate(self, tr):
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
356 """delay visibility of index updates to other readers"""
51102
594f912818ab changelog-delay: adds some check around delaying and diverting write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51086
diff changeset
357 assert not self._inner.is_open
51181
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
358 assert not self._may_inline
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
359 # enforce that older changelog that are still inline are split at the
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
360 # first opportunity.
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
361 if self._inline:
dcaa2df1f688 changelog: never inline changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51106
diff changeset
362 self._enforceinlinesize(tr)
51106
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
363 if self._docket is not None:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
364 self._v2_delayed = True
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
365 else:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
366 new_index = self._inner.delay()
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
367 if new_index is not None:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
368 self._indexfile = new_index
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
369 tr.registertmp(new_index)
51637
3cf9e52f5e27 inline-changelog: fix a critical bug in write_pending that delete data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
370 # use "000" as prefix to make sure we run before the spliting of legacy
3cf9e52f5e27 inline-changelog: fix a critical bug in write_pending that delete data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
371 # inline changelog..
3cf9e52f5e27 inline-changelog: fix a critical bug in write_pending that delete data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
372 tr.addpending(b'000-cl-%i' % id(self), self._writepending)
3cf9e52f5e27 inline-changelog: fix a critical bug in write_pending that delete data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51317
diff changeset
373 tr.addfinalize(b'000-cl-%i' % id(self), self._finalize)
4261
cd7b36b7869c restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents: 4258
diff changeset
374
23205
2d54aa5397cd changelog: rely on transaction for finalization
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23203
diff changeset
375 def _finalize(self, tr):
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
376 """finalize index updates"""
51102
594f912818ab changelog-delay: adds some check around delaying and diverting write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51086
diff changeset
377 assert not self._inner.is_open
47239
682f09857d69 revlogv2: delay the update of the changelog docket to transaction end
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
378 if self._docket is not None:
51106
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
379 self._docket.write(tr)
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
380 self._v2_delayed = False
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
381 else:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
382 new_index_file = self._inner.finalize_pending()
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
383 self._indexfile = new_index_file
51316
178e50edb4f8 changelog: stop useless enforcing split at the end of transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51181
diff changeset
384 if self._inline:
178e50edb4f8 changelog: stop useless enforcing split at the end of transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51181
diff changeset
385 msg = 'changelog should not be inline at that point'
178e50edb4f8 changelog: stop useless enforcing split at the end of transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51181
diff changeset
386 raise error.ProgrammingError(msg)
4261
cd7b36b7869c restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents: 4258
diff changeset
387
23280
b01c491af0cf transaction: pass the transaction to 'pending' callback
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23205
diff changeset
388 def _writepending(self, tr):
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
389 """create a file containing the unfinalized state for
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
390 pretxnchangegroup"""
51102
594f912818ab changelog-delay: adds some check around delaying and diverting write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51086
diff changeset
391 assert not self._inner.is_open
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47240
diff changeset
392 if self._docket:
51106
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
393 any_pending = self._docket.write(tr, pending=True)
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
394 self._v2_delayed = False
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
395 else:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
396 new_index, any_pending = self._inner.write_pending()
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
397 if new_index is not None:
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
398 self._indexfile = new_index
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
399 tr.registertmp(new_index)
d83d788590a8 changelog-delay: move the delay/divert logic inside the (inner) revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51104
diff changeset
400 return any_pending
7787
b8d750daadde Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents: 7634
diff changeset
401
51317
5b3b6db49bbb changelog: drop the side_write argument to revlog splitting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51316
diff changeset
402 def _enforceinlinesize(self, tr):
51104
1c0f3994d733 changelog-delay: move "delayed" check to a more official API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51103
diff changeset
403 if not self.is_delaying:
51317
5b3b6db49bbb changelog: drop the side_write argument to revlog splitting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51316
diff changeset
404 revlog.revlog._enforceinlinesize(self, tr)
4261
cd7b36b7869c restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents: 4258
diff changeset
405
46631
230f73019e49 changelog: rename parameters to reflect semantics
Joerg Sonnenberger <joerg@bec.de>
parents: 46607
diff changeset
406 def read(self, nodeorrev):
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
407 """Obtain data from a parsed changelog revision.
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
408
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
409 Returns a 6-tuple of:
3233
2f35961854fb [extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3232
diff changeset
410
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
411 - manifest node in binary
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
412 - author/user as a localstr
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
413 - date as a 2-tuple of (time, timezone)
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
414 - list of files
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
415 - commit message as a localstr
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
416 - dict of extra metadata
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
417
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
418 Unless you need to access all fields, consider calling
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
419 ``changelogrevision`` instead, as it is faster for partial object
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
420 access.
3077
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
421 """
47385
9d9eb22b9b69 revlog: no longer return sidedata from `_revisiondata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47383
diff changeset
422 d = self._revisiondata(nodeorrev)
47383
659a452ee263 revlog: use `self.sidedata` directly to construct changelogrevision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
423 sidedata = self.sidedata(nodeorrev)
659a452ee263 revlog: use `self.sidedata` directly to construct changelogrevision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
424 copy_sd = self._copiesstorage == b'changeset-sidedata'
659a452ee263 revlog: use `self.sidedata` directly to construct changelogrevision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
425 c = changelogrevision(self, d, sidedata, copy_sd)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
426 return (c.manifest, c.user, c.date, c.files, c.description, c.extra)
3233
2f35961854fb [extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3232
diff changeset
427
28487
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
428 def changelogrevision(self, nodeorrev):
98d98a645e9d changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28315
diff changeset
429 """Obtain a ``changelogrevision`` for a node or revision."""
47385
9d9eb22b9b69 revlog: no longer return sidedata from `_revisiondata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47383
diff changeset
430 text = self._revisiondata(nodeorrev)
47383
659a452ee263 revlog: use `self.sidedata` directly to construct changelogrevision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
431 sidedata = self.sidedata(nodeorrev)
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
432 return changelogrevision(
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46714
diff changeset
433 self, text, sidedata, self._copiesstorage == b'changeset-sidedata'
43230
e51f5d06a99c sidedatacopies: only read from copies when in this mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43147
diff changeset
434 )
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
435
46631
230f73019e49 changelog: rename parameters to reflect semantics
Joerg Sonnenberger <joerg@bec.de>
parents: 46607
diff changeset
436 def readfiles(self, nodeorrev):
27439
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
437 """
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
438 short version of read that only returns the files modified by the cset
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
439 """
46631
230f73019e49 changelog: rename parameters to reflect semantics
Joerg Sonnenberger <joerg@bec.de>
parents: 46607
diff changeset
440 text = self.revision(nodeorrev)
27439
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
441 if not text:
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
442 return []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
443 last = text.index(b"\n\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
444 l = text[:last].split(b'\n')
27439
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
445 return l[3:]
ed003859f1d8 changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents: 26094
diff changeset
446
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
447 def add(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
448 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
449 manifest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
450 files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
451 desc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
452 transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
453 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
454 p2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
455 user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
456 date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
457 extra=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
458 ):
14379
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 10420
diff changeset
459 # Convert to UTF-8 encoded bytestrings as the very first
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 10420
diff changeset
460 # thing: calling any method on a localstr object will turn it
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 10420
diff changeset
461 # into a str object and the cached UTF-8 string is thus lost.
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 10420
diff changeset
462 user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 10420
diff changeset
463
7035
9d023ef7b467 forbid username with '\n' at the changelog level
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6259
diff changeset
464 user = user.strip()
8424
c5b3d3e30de7 changelog: refuse to add revisions with empty usernames
Martin Geisler <mg@lazybytes.net>
parents: 7807
diff changeset
465 # An empty username or a username with a "\n" will make the
c5b3d3e30de7 changelog: refuse to add revisions with empty usernames
Martin Geisler <mg@lazybytes.net>
parents: 7807
diff changeset
466 # revision text contain two "\n\n" sequences -> corrupt
c5b3d3e30de7 changelog: refuse to add revisions with empty usernames
Martin Geisler <mg@lazybytes.net>
parents: 7807
diff changeset
467 # repository since read cannot unpack the revision.
c5b3d3e30de7 changelog: refuse to add revisions with empty usernames
Martin Geisler <mg@lazybytes.net>
parents: 7807
diff changeset
468 if not user:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
469 raise error.StorageError(_(b"empty username"))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
470 if b"\n" in user:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
471 raise error.StorageError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
472 _(b"username %r contains a newline") % pycompat.bytestr(user)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
473 )
8499
fb9b83df45f3 commit: move description trimming into changelog
Matt Mackall <mpm@selenic.com>
parents: 8443
diff changeset
474
17810
2894d180afa1 changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17677
diff changeset
475 desc = stripdesc(desc)
8499
fb9b83df45f3 commit: move description trimming into changelog
Matt Mackall <mpm@selenic.com>
parents: 8443
diff changeset
476
1195
f92af8d53330 Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1095
diff changeset
477 if date:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
478 parseddate = b"%d %d" % dateutil.parsedate(date)
1195
f92af8d53330 Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1095
diff changeset
479 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
480 parseddate = b"%d %d" % dateutil.makedate()
10417
58e040c51231 branch: avoid using reserved tag names
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 10263
diff changeset
481 if extra:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
482 branch = extra.get(b"branch")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
483 if branch in (b"default", b""):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
484 del extra[b"branch"]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
485 elif branch in (b".", b"null", b"tip"):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
486 raise error.StorageError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
487 _(b'the name \'%s\' is reserved') % branch
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43027
diff changeset
488 )
45324
6c56277317c2 commitctx: directly pass a ChangingFiles object to changelog.add
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45249
diff changeset
489 sortedfiles = sorted(files.touched)
45671
2d6aea053153 copies: add a HASCOPIESINFO flag to highlight rev with useful data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45636
diff changeset
490 flags = 0
43142
beed7ce61681 sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
491 sidedata = None
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
492 if self._copiesstorage == b'changeset-sidedata':
45728
232c88dd89e3 changing-files: add a shorthand property to check for copy relevant info
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45672
diff changeset
493 if files.has_copies_info:
45671
2d6aea053153 copies: add a HASCOPIESINFO flag to highlight rev with useful data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45636
diff changeset
494 flags |= flagutil.REVIDX_HASCOPIESINFO
45569
64d18e9e8508 sidedata: rename `encode_copies_sidedata` to `encode_files_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45515
diff changeset
495 sidedata = metadata.encode_files_sidedata(files)
42141
0e41f40b01cc copies: add config option for writing copy metadata to file and/or changset
Martin von Zweigbergk <martinvonz@google.com>
parents: 42116
diff changeset
496
3233
2f35961854fb [extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3232
diff changeset
497 if extra:
8443
53ff4a5af284 changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents: 8442
diff changeset
498 extra = encodeextra(extra)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
499 parseddate = b"%s %s" % (parseddate, extra)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
500 l = [hex(manifest), user, parseddate] + sortedfiles + [b"", desc]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
501 text = b"\n".join(l)
46508
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46370
diff changeset
502 rev = self.addrevision(
45672
f877b3628015 copies: return None instead of ChangingFiles when relevant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45671
diff changeset
503 text, transaction, len(self), p1, p2, sidedata=sidedata, flags=flags
43142
beed7ce61681 sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
504 )
46508
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46370
diff changeset
505 return self.node(rev)
18306
06185554e7e3 changelog: add a `branch` method, bypassing changectx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18231
diff changeset
506
20185
7d4219512823 branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents: 19899
diff changeset
507 def branchinfo(self, rev):
7d4219512823 branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents: 19899
diff changeset
508 """return the branch name and open/close state of a revision
18306
06185554e7e3 changelog: add a `branch` method, bypassing changectx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18231
diff changeset
509
18308
4e27b06a0fd9 changelog: please check-code and remove tabs
Mads Kiilerich <mads@kiilerich.com>
parents: 18306
diff changeset
510 This function exists because creating a changectx object
4e27b06a0fd9 changelog: please check-code and remove tabs
Mads Kiilerich <mads@kiilerich.com>
parents: 18306
diff changeset
511 just to access this is costly."""
46370
cad17d50736c changelog: move branchinfo to changelogrevision
Joerg Sonnenberger <joerg@bec.de>
parents: 46197
diff changeset
512 return self.changelogrevision(rev).branchinfo
39887
a3095bc47217 changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents: 39777
diff changeset
513
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 46508
diff changeset
514 def _nodeduplicatecallback(self, transaction, rev):
39887
a3095bc47217 changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents: 39777
diff changeset
515 # keep track of revisions that got "re-added", eg: unbunde of know rev.
a3095bc47217 changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents: 39777
diff changeset
516 #
a3095bc47217 changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents: 39777
diff changeset
517 # We track them in a list to preserve their order from the source bundle
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
518 duplicates = transaction.changes.setdefault(b'revduplicates', [])
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 46508
diff changeset
519 duplicates.append(rev)