Mercurial > hg
annotate mercurial/changelog.py @ 43212:9bbe08abaf48
rust-cpython: bump cpython crates to 0.3
Unblocks py_capsule_fn!().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 13 Oct 2019 17:05:09 +0900 |
parents | 54e943b28101 |
children | e51f5d06a99c |
rev | line source |
---|---|
1095 | 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 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4269
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@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 | 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 from __future__ import absolute_import |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
9 |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
10 from .i18n import _ |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
11 from .node import ( |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
12 bin, |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
13 hex, |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
14 nullid, |
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 |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
18 from . import ( |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
19 copies, |
25922
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
20 encoding, |
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
21 error, |
36228
ddeb7653b31c
py3: use pycompat.bytestr to convert str to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35974
diff
changeset
|
22 pycompat, |
25922
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
23 revlog, |
41763
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
24 util, |
25922
85f442747153
changelog: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25814
diff
changeset
|
25 ) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
26 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
27 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
28 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
29 ) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
30 |
43142
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
31 from .revlogutils import sidedata as sidedatamod |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
32 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
33 _defaultextra = {b'branch': b'default'} |
16267
aa6821a7b52f
changelog: micro-optimizations to changelog.read()
Matt Mackall <mpm@selenic.com>
parents:
15661
diff
changeset
|
34 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
35 |
3232
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
36 def _string_escape(text): |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
37 """ |
34133
708b5530a273
doctest: replace chr() with pycompat.bytechr()
Yuya Nishihara <yuya@tcha.org>
parents:
34132
diff
changeset
|
38 >>> 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
|
39 >>> 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
|
40 >>> 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
|
41 >>> s |
42116
caa067ee21dc
changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41831
diff
changeset
|
42 'ab\\ncd\\\\\\\\n\\x0012ab\\rcd\\\\\\n' |
3232
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
43 >>> 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
|
44 >>> s == _string_unescape(res) |
3232
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
45 True |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
46 """ |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
47 # 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
|
48 text = ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 text.replace(b'\\', b'\\\\') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
50 .replace(b'\n', b'\\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 .replace(b'\r', b'\\r') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
53 return text.replace(b'\0', b'\\0') |
3232
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3077
diff
changeset
|
54 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
55 |
42116
caa067ee21dc
changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41831
diff
changeset
|
56 def _string_unescape(text): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 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
|
58 # 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
|
59 text = text.replace(b'\\\\', b'\\\\\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 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
|
61 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
|
62 return stringutil.unescapestr(text) |
caa067ee21dc
changelog: extract a _string_unescape() to mirror _string_escape()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41831
diff
changeset
|
63 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
64 |
8443
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
65 def decodeextra(text): |
15661
20ae902c43ec
changelog: handle decoding of NULs in extra more carefully (issue3156)
Matt Mackall <mpm@selenic.com>
parents:
14643
diff
changeset
|
66 """ |
34133
708b5530a273
doctest: replace chr() with pycompat.bytechr()
Yuya Nishihara <yuya@tcha.org>
parents:
34132
diff
changeset
|
67 >>> 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
|
68 >>> 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
|
69 ... ).items()) |
18379
e0c4f4ba624c
tests: fix doctest stability over Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
18378
diff
changeset
|
70 [('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
|
71 >>> 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
|
72 ... b'baz': chr(92) + chr(0) + b'2'}) |
34132
264872544362
doctest: replace .iteritems() with .items()
Yuya Nishihara <yuya@tcha.org>
parents:
34131
diff
changeset
|
73 ... ).items()) |
18379
e0c4f4ba624c
tests: fix doctest stability over Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
18378
diff
changeset
|
74 [('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
|
75 """ |
16267
aa6821a7b52f
changelog: micro-optimizations to changelog.read()
Matt Mackall <mpm@selenic.com>
parents:
15661
diff
changeset
|
76 extra = _defaultextra.copy() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
77 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
|
78 if l: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 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
|
80 extra[k] = v |
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
81 return extra |
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
82 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
83 |
8443
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
84 def encodeextra(d): |
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
85 # keys must be sorted to produce a deterministic changelog entry |
41574
b436059c1cca
py3: use pycompat.bytestr() on extra values because it can be int
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41275
diff
changeset
|
86 items = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
87 _string_escape(b'%s:%s' % (k, pycompat.bytestr(d[k]))) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
88 for k in sorted(d) |
41574
b436059c1cca
py3: use pycompat.bytestr() on extra values because it can be int
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41275
diff
changeset
|
89 ] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
90 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
|
91 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
92 |
17810
2894d180afa1
changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17677
diff
changeset
|
93 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
|
94 """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
|
95 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
|
96 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
97 |
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8644
diff
changeset
|
98 class appender(object): |
7807
bd8f44638847
help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents:
7787
diff
changeset
|
99 '''the changelog index must be updated last on disk, so we use this class |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
100 to delay writes to it''' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
101 |
19899
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19898
diff
changeset
|
102 def __init__(self, vfs, name, mode, buf): |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
103 self.data = buf |
19899
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19898
diff
changeset
|
104 fp = vfs(name, mode) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
105 self.fp = fp |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
106 self.offset = fp.tell() |
19899
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19898
diff
changeset
|
107 self.size = vfs.fstat(fp).st_size |
30596
be520fe3a3e9
changelog: keep track of file end in appender (issue5444)
Durham Goode <durham@fb.com>
parents:
30210
diff
changeset
|
108 self._end = self.size |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
109 |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
110 def end(self): |
30596
be520fe3a3e9
changelog: keep track of file end in appender (issue5444)
Durham Goode <durham@fb.com>
parents:
30210
diff
changeset
|
111 return self._end |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
112 |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
113 def tell(self): |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
114 return self.offset |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
115 |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
116 def flush(self): |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
117 pass |
35963
69aaad59dc02
changelog: add the missing 'closed' property on 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35962
diff
changeset
|
118 |
69aaad59dc02
changelog: add the missing 'closed' property on 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35962
diff
changeset
|
119 @property |
69aaad59dc02
changelog: add the missing 'closed' property on 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35962
diff
changeset
|
120 def closed(self): |
69aaad59dc02
changelog: add the missing 'closed' property on 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35962
diff
changeset
|
121 return self.fp.closed |
69aaad59dc02
changelog: add the missing 'closed' property on 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35962
diff
changeset
|
122 |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
123 def close(self): |
4961
3fdd09ad6cce
fix bogus close spotted by pychecker (no close() in global scope)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4635
diff
changeset
|
124 self.fp.close() |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
125 |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
126 def seek(self, offset, whence=0): |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
127 '''virtual file offset spans real file and data''' |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
128 if whence == 0: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
129 self.offset = offset |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
130 elif whence == 1: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
131 self.offset += offset |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
132 elif whence == 2: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
133 self.offset = self.end() + offset |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
134 if self.offset < self.size: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
135 self.fp.seek(self.offset) |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
136 |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
137 def read(self, count=-1): |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
138 '''only trick here is reads that span real file and data''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 ret = b"" |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
140 if self.offset < self.size: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
141 s = self.fp.read(count) |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
142 ret = s |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
143 self.offset += len(s) |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
144 if count > 0: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
145 count -= len(s) |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
146 if count != 0: |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
147 doff = self.offset - self.size |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 self.data.insert(0, b"".join(self.data)) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
149 del self.data[1:] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
150 s = self.data[0][doff : doff + count] |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
151 self.offset += len(s) |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
152 ret += s |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
153 return ret |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
154 |
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
155 def write(self, s): |
31642
addc392cc3d3
py3: use bytes() to cast to immutable bytes in changelog.appender.write()
Yuya Nishihara <yuya@tcha.org>
parents:
31484
diff
changeset
|
156 self.data.append(bytes(s)) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
157 self.offset += len(s) |
30596
be520fe3a3e9
changelog: keep track of file end in appender (issue5444)
Durham Goode <durham@fb.com>
parents:
30210
diff
changeset
|
158 self._end += len(s) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
159 |
35962
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
160 def __enter__(self): |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
161 self.fp.__enter__() |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
162 return self |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
163 |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
164 def __exit__(self, *args): |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
165 return self.fp.__exit__(*args) |
fa15a70f88de
changelog: implement context manager method for 'appender' object
Boris Feld <boris.feld@octobus.net>
parents:
35672
diff
changeset
|
166 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
167 |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
168 def _divertopener(opener, target): |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
169 """build an opener that writes in 'target.a' instead of 'target'""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
170 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
171 def _divert(name, mode=b'r', checkambig=False): |
9166
e6162b854ed5
changelog: move delayopener outside of class to eliminate reference cycle
Matt Mackall <mpm@selenic.com>
parents:
9165
diff
changeset
|
172 if name != target: |
e6162b854ed5
changelog: move delayopener outside of class to eliminate reference cycle
Matt Mackall <mpm@selenic.com>
parents:
9165
diff
changeset
|
173 return opener(name, mode) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 return opener(name + b".a", mode) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
175 |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
176 return _divert |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
177 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
178 |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
179 def _delayopener(opener, target, buf): |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
180 """build an opener that stores chunks in 'buf' instead of 'target'""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
181 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
182 def _delay(name, mode=b'r', checkambig=False): |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
183 if name != target: |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
184 return opener(name, mode) |
19899
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19898
diff
changeset
|
185 return appender(opener, name, mode, buf) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
186 |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
187 return _delay |
9166
e6162b854ed5
changelog: move delayopener outside of class to eliminate reference cycle
Matt Mackall <mpm@selenic.com>
parents:
9165
diff
changeset
|
188 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
189 |
34398
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
190 @attr.s |
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
191 class _changelogrevision(object): |
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
192 # 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
|
193 # it in |
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
194 extra = attr.ib() |
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
195 manifest = attr.ib(default=nullid) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
196 user = attr.ib(default=b'') |
34398
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 p2copies = attr.ib(default=None) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 description = attr.ib(default=b'') |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
204 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
205 |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
206 class changelogrevision(object): |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
207 """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
|
208 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
209 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
|
210 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
|
211 the parsed object. |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
212 """ |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
213 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
214 __slots__ = ( |
41831
ae189674bdad
global: use raw strings for __slots__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41763
diff
changeset
|
215 r'_offsets', |
ae189674bdad
global: use raw strings for __slots__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41763
diff
changeset
|
216 r'_text', |
43143
037a8759eda1
sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43142
diff
changeset
|
217 r'_sidedata', |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
218 ) |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
219 |
43143
037a8759eda1
sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43142
diff
changeset
|
220 def __new__(cls, text, sidedata): |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
221 if not text: |
34398
e51c8ffa1ffa
changelog: use attrs instead of namedtuple
Siddharth Agarwal <sid0@fb.com>
parents:
34296
diff
changeset
|
222 return _changelogrevision(extra=_defaultextra) |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
223 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
224 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
|
225 # 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
|
226 # 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
|
227 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
228 # format used: |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
229 # 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
|
230 # 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
|
231 # 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
|
232 # : 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
|
233 # : older versions ignore it |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
234 # 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
|
235 # (.*) : 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
|
236 # |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
237 # 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
|
238 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
239 nl1 = text.index(b'\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
240 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
|
241 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
|
242 |
28493
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
243 # 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
|
244 # 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
|
245 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
|
246 doublenl = nl3 |
28493
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
247 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
248 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
|
249 |
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
250 self._offsets = (nl1, nl2, nl3, doublenl) |
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
251 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
|
252 self._sidedata = sidedata |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
253 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
254 return self |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
255 |
28489
8939a95064f1
changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28487
diff
changeset
|
256 @property |
28490
959eadae589a
changelog: lazily parse manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28489
diff
changeset
|
257 def manifest(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
258 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
|
259 |
959eadae589a
changelog: lazily parse manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28489
diff
changeset
|
260 @property |
28491
f57f7500a095
changelog: lazily parse user
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28490
diff
changeset
|
261 def user(self): |
28495
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
262 off = self._offsets |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
263 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
|
264 |
f57f7500a095
changelog: lazily parse user
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28490
diff
changeset
|
265 @property |
28492
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
266 def _rawdate(self): |
28495
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
267 off = self._offsets |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
268 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
|
269 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
|
270 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
271 @property |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
272 def _rawextra(self): |
28495
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
273 off = self._offsets |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
274 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
|
275 fields = dateextra.split(b' ', 2) |
28492
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
276 if len(fields) != 3: |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
277 return None |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
278 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
279 return fields[2] |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
280 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
281 @property |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
282 def date(self): |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
283 raw = self._rawdate |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
284 time = float(raw[0]) |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
285 # 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
|
286 try: |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
287 timezone = int(raw[1]) |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
288 except ValueError: |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
289 timezone = 0 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
290 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
291 return time, timezone |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
292 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
293 @property |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
294 def extra(self): |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
295 raw = self._rawextra |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
296 if raw is None: |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
297 return _defaultextra |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
298 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
299 return decodeextra(raw) |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
300 |
837f1c437d58
changelog: lazily parse date/extra field
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28491
diff
changeset
|
301 @property |
28493
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
302 def files(self): |
28495
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
303 off = self._offsets |
70c2f8a98276
changelog: avoid slicing raw data until needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28494
diff
changeset
|
304 if off[2] == off[3]: |
28493
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
305 return [] |
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
306 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 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
|
308 |
7796473c11b3
changelog: lazily parse files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28492
diff
changeset
|
309 @property |
42407
602469a91550
context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
42406
diff
changeset
|
310 def filesadded(self): |
43146
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
311 if sidedatamod.SD_FILESADDED in self._sidedata: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
312 rawindices = self._sidedata.get(sidedatamod.SD_FILESADDED) |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
313 else: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
314 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
|
315 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
|
316 return None |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
317 return copies.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
|
318 |
602469a91550
context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
42406
diff
changeset
|
319 @property |
602469a91550
context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
42406
diff
changeset
|
320 def filesremoved(self): |
43146
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
321 if sidedatamod.SD_FILESREMOVED in self._sidedata: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
322 rawindices = self._sidedata.get(sidedatamod.SD_FILESREMOVED) |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
323 else: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
324 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
|
325 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
|
326 return None |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
327 return copies.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
|
328 |
602469a91550
context: get filesadded() and filesremoved() from changeset if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
42406
diff
changeset
|
329 @property |
42142
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
330 def p1copies(self): |
43146
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
331 if sidedatamod.SD_P1COPIES in self._sidedata: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
332 rawcopies = self._sidedata.get(sidedatamod.SD_P1COPIES) |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
333 else: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
334 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
|
335 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
|
336 return None |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
337 return copies.decodecopies(self.files, rawcopies) |
42142
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
338 |
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
339 @property |
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
340 def p2copies(self): |
43146
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
341 if sidedatamod.SD_P2COPIES in self._sidedata: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
342 rawcopies = self._sidedata.get(sidedatamod.SD_P2COPIES) |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
343 else: |
0171483b082f
sidedatacopies: read rename information from sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43145
diff
changeset
|
344 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
|
345 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
|
346 return None |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
347 return copies.decodecopies(self.files, rawcopies) |
42142
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
348 |
5382d8f8530b
changelog: parse copy metadata if available in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
42141
diff
changeset
|
349 @property |
28489
8939a95064f1
changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28487
diff
changeset
|
350 def description(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
351 return encoding.tolocal(self._text[self._offsets[3] + 2 :]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
352 |
28489
8939a95064f1
changelog: lazily parse description
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28487
diff
changeset
|
353 |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
354 class changelog(revlog.revlog): |
32292
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
355 def __init__(self, opener, trypending=False): |
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
356 """Load a changelog revlog using an opener. |
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
357 |
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
358 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
|
359 ``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
|
360 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
|
361 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
|
362 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
|
363 hooks processes) accessing data before a transaction is finalized. |
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
364 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
365 if trypending and opener.exists(b'00changelog.i.a'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
366 indexfile = b'00changelog.i.a' |
32292
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
367 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 indexfile = b'00changelog.i' |
32292
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
369 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 datafile = b'00changelog.d' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
371 revlog.revlog.__init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
372 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
373 opener, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
374 indexfile, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
375 datafile=datafile, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
376 checkambig=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
377 mmaplargeindex=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
378 ) |
32292
0ad0d26ff703
changelog: load pending file directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32262
diff
changeset
|
379 |
41202
e7a2cc84dbc0
revlog: always enable generaldelta on version 2 revlogs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39887
diff
changeset
|
380 if self._initempty and (self.version & 0xFFFF == revlog.REVLOGV1): |
e7a2cc84dbc0
revlog: always enable generaldelta on version 2 revlogs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39887
diff
changeset
|
381 # 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
|
382 |
32315
67026d65a4fc
revlog: rename constants (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32307
diff
changeset
|
383 self.version &= ~revlog.FLAG_GENERALDELTA |
14334
85c82ebc96a3
changelog: don't use generaldelta
Sune Foldager <cryo@cyanite.org>
parents:
14207
diff
changeset
|
384 self._generaldelta = False |
30155
b7a966ce89ed
changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30000
diff
changeset
|
385 |
b7a966ce89ed
changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30000
diff
changeset
|
386 # 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
|
387 # 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
|
388 # chains. |
39232
0a5b20c107a6
repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39201
diff
changeset
|
389 self._storedeltachains = False |
30155
b7a966ce89ed
changelog: disable delta chains
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30000
diff
changeset
|
390 |
8644
c2ef478b2efa
changelog: make delayopener less intrusive
Matt Mackall <mpm@selenic.com>
parents:
8499
diff
changeset
|
391 self._realopener = opener |
c2ef478b2efa
changelog: make delayopener less intrusive
Matt Mackall <mpm@selenic.com>
parents:
8499
diff
changeset
|
392 self._delayed = False |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
393 self._delaybuf = None |
9163
f193b643d1b1
changelog: _delaycount -> _divert
Matt Mackall <mpm@selenic.com>
parents:
8778
diff
changeset
|
394 self._divert = False |
18231
c0c943ef4e55
clfilter: use empty frozenset intead of empty tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17951
diff
changeset
|
395 self.filteredrevs = frozenset() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
396 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
|
397 |
35671
8810f0643fa1
changelog: introduce a 'tiprev' method
Boris Feld <boris.feld@octobus.net>
parents:
35308
diff
changeset
|
398 def tiprev(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
399 for i in pycompat.xrange(len(self) - 1, -2, -1): |
35671
8810f0643fa1
changelog: introduce a 'tiprev' method
Boris Feld <boris.feld@octobus.net>
parents:
35308
diff
changeset
|
400 if i not in self.filteredrevs: |
8810f0643fa1
changelog: introduce a 'tiprev' method
Boris Feld <boris.feld@octobus.net>
parents:
35308
diff
changeset
|
401 return i |
8810f0643fa1
changelog: introduce a 'tiprev' method
Boris Feld <boris.feld@octobus.net>
parents:
35308
diff
changeset
|
402 |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
403 def tip(self): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
404 """filtered version of revlog.tip""" |
35672
5a6e0eee7781
changelog: use 'tiprev()' in 'tip()'
Boris Feld <boris.feld@octobus.net>
parents:
35671
diff
changeset
|
405 return self.node(self.tiprev()) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
406 |
24030
828dc8db5515
revlog: add __contains__ for fast membership test
Yuya Nishihara <yuya@tcha.org>
parents:
23292
diff
changeset
|
407 def __contains__(self, rev): |
828dc8db5515
revlog: add __contains__ for fast membership test
Yuya Nishihara <yuya@tcha.org>
parents:
23292
diff
changeset
|
408 """filtered version of revlog.__contains__""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
409 return 0 <= rev < len(self) and rev not in self.filteredrevs |
24030
828dc8db5515
revlog: add __contains__ for fast membership test
Yuya Nishihara <yuya@tcha.org>
parents:
23292
diff
changeset
|
410 |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
411 def __iter__(self): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
412 """filtered version of revlog.__iter__""" |
17951
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
413 if len(self.filteredrevs) == 0: |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
414 return revlog.revlog.__iter__(self) |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
415 |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
416 def filterediter(): |
38783
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37084
diff
changeset
|
417 for i in pycompat.xrange(len(self)): |
17951
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
418 if i not in self.filteredrevs: |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
419 yield i |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
420 |
6f79c32c0bdf
commit: increase perf by avoiding unnecessary filteredrevs check
Durham Goode <durham@fb.com>
parents:
17810
diff
changeset
|
421 return filterediter() |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
422 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
423 def revs(self, start=0, stop=None): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
424 """filtered version of revlog.revs""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
425 for i in super(changelog, self).revs(start, stop): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
426 if i not in self.filteredrevs: |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
427 yield i |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
428 |
41763
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
429 def _checknofilteredinrevs(self, revs): |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
430 """raise the appropriate error if 'revs' contains a filtered revision |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
431 |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
432 This returns a version of 'revs' to be used thereafter by the caller. |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
433 In particular, if revs is an iterator, it is converted into a set. |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
434 """ |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
435 safehasattr = util.safehasattr |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
436 if safehasattr(revs, '__next__'): |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
437 # Note that inspect.isgenerator() is not true for iterators, |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
438 revs = set(revs) |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
439 |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
440 filteredrevs = self.filteredrevs |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
441 if safehasattr(revs, 'first'): # smartset |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
442 offenders = revs & filteredrevs |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
443 else: |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
444 offenders = filteredrevs.intersection(revs) |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
445 |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
446 for rev in offenders: |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
447 raise error.FilteredIndexError(rev) |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
448 return revs |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
449 |
41275
1421d0487a61
revlog: accept a revs argument in `headrevs`
Boris Feld <boris.feld@octobus.net>
parents:
41202
diff
changeset
|
450 def headrevs(self, revs=None): |
1421d0487a61
revlog: accept a revs argument in `headrevs`
Boris Feld <boris.feld@octobus.net>
parents:
41202
diff
changeset
|
451 if revs is None and self.filteredrevs: |
22484
2b5940f64750
obsolete: use C code for headrevs calculation
Durham Goode <durham@fb.com>
parents:
21544
diff
changeset
|
452 try: |
23088
fe5f044b753d
changelog: use headrevsfiltered
Mads Kiilerich <madski@unity3d.com>
parents:
23015
diff
changeset
|
453 return self.index.headrevsfiltered(self.filteredrevs) |
fe5f044b753d
changelog: use headrevsfiltered
Mads Kiilerich <madski@unity3d.com>
parents:
23015
diff
changeset
|
454 # AttributeError covers non-c-extension environments and |
fe5f044b753d
changelog: use headrevsfiltered
Mads Kiilerich <madski@unity3d.com>
parents:
23015
diff
changeset
|
455 # old c extensions without filter handling. |
fe5f044b753d
changelog: use headrevsfiltered
Mads Kiilerich <madski@unity3d.com>
parents:
23015
diff
changeset
|
456 except AttributeError: |
22484
2b5940f64750
obsolete: use C code for headrevs calculation
Durham Goode <durham@fb.com>
parents:
21544
diff
changeset
|
457 return self._headrevs() |
2b5940f64750
obsolete: use C code for headrevs calculation
Durham Goode <durham@fb.com>
parents:
21544
diff
changeset
|
458 |
41763
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
459 if self.filteredrevs: |
6843379bf99e
changelog: prefilter in headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41574
diff
changeset
|
460 revs = self._checknofilteredinrevs(revs) |
41275
1421d0487a61
revlog: accept a revs argument in `headrevs`
Boris Feld <boris.feld@octobus.net>
parents:
41202
diff
changeset
|
461 return super(changelog, self).headrevs(revs) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
462 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
463 def strip(self, *args, **kwargs): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
464 # XXX make something better than assert |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
465 # We can't expect proper strip behavior if we are filtered. |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
466 assert not self.filteredrevs |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
467 super(changelog, self).strip(*args, **kwargs) |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
468 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
469 def rev(self, node): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
470 """filtered version of revlog.rev""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
471 r = super(changelog, self).rev(node) |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
472 if r in self.filteredrevs: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
473 raise error.FilteredLookupError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
474 hex(node), self.indexfile, _(b'filtered node') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
475 ) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
476 return r |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
477 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
478 def node(self, rev): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
479 """filtered version of revlog.node""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
480 if rev in self.filteredrevs: |
23014
f00813325c5a
repoview: add a FilteredIndexError class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22484
diff
changeset
|
481 raise error.FilteredIndexError(rev) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
482 return super(changelog, self).node(rev) |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
483 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
484 def linkrev(self, rev): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
485 """filtered version of revlog.linkrev""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
486 if rev in self.filteredrevs: |
23014
f00813325c5a
repoview: add a FilteredIndexError class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22484
diff
changeset
|
487 raise error.FilteredIndexError(rev) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
488 return super(changelog, self).linkrev(rev) |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
489 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
490 def parentrevs(self, rev): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
491 """filtered version of revlog.parentrevs""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
492 if rev in self.filteredrevs: |
23014
f00813325c5a
repoview: add a FilteredIndexError class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22484
diff
changeset
|
493 raise error.FilteredIndexError(rev) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
494 return super(changelog, self).parentrevs(rev) |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
495 |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
496 def flags(self, rev): |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
497 """filtered version of revlog.flags""" |
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
498 if rev in self.filteredrevs: |
23014
f00813325c5a
repoview: add a FilteredIndexError class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22484
diff
changeset
|
499 raise error.FilteredIndexError(rev) |
17677
5c89e7fa5bc2
clfilter: introduce `filteredrevs` attribute on changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
500 return super(changelog, self).flags(rev) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
501 |
23203
3872d563e01a
changelog: handle writepending in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23201
diff
changeset
|
502 def delayupdate(self, tr): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
503 b"delay visibility of index updates to other readers" |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
504 |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
505 if not self._delayed: |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
506 if len(self) == 0: |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
507 self._divert = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 if self._realopener.exists(self.indexfile + b'.a'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
509 self._realopener.unlink(self.indexfile + b'.a') |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
510 self.opener = _divertopener(self._realopener, self.indexfile) |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
511 else: |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
512 self._delaybuf = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
513 self.opener = _delayopener( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
514 self._realopener, self.indexfile, self._delaybuf |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
515 ) |
8644
c2ef478b2efa
changelog: make delayopener less intrusive
Matt Mackall <mpm@selenic.com>
parents:
8499
diff
changeset
|
516 self._delayed = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 tr.addpending(b'cl-%i' % id(self), self._writepending) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
518 tr.addfinalize(b'cl-%i' % id(self), self._finalize) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
519 |
23205
2d54aa5397cd
changelog: rely on transaction for finalization
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23203
diff
changeset
|
520 def _finalize(self, tr): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
521 b"finalize index updates" |
8644
c2ef478b2efa
changelog: make delayopener less intrusive
Matt Mackall <mpm@selenic.com>
parents:
8499
diff
changeset
|
522 self._delayed = False |
9165
07f9b2f4a9aa
changelog: swap opener to switch delay modes
Matt Mackall <mpm@selenic.com>
parents:
9164
diff
changeset
|
523 self.opener = self._realopener |
4269
73c918c71300
changelog: optimize delayed updates for clone vs pull
Matt Mackall <mpm@selenic.com>
parents:
4261
diff
changeset
|
524 # move redirected index data back into place |
9164
b0d995b6b0a6
changelog: factor out _delayname
Matt Mackall <mpm@selenic.com>
parents:
9163
diff
changeset
|
525 if self._divert: |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
526 assert not self._delaybuf |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
527 tmpname = self.indexfile + b".a" |
19898
3f92e749d381
changelog: use "vfs.rename()" instead of "util.rename()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18587
diff
changeset
|
528 nfile = self.opener.open(tmpname) |
14207
c1cca38818b9
changelog: fixes leaked file handle
Zachary Gramana <zgramana@pottsconsultinggroup.com>
parents:
14004
diff
changeset
|
529 nfile.close() |
29999
003c41edc5f5
changelog: specify checkambig=True to avoid ambiguity around truncation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29997
diff
changeset
|
530 self.opener.rename(tmpname, self.indexfile, checkambig=True) |
4269
73c918c71300
changelog: optimize delayed updates for clone vs pull
Matt Mackall <mpm@selenic.com>
parents:
4261
diff
changeset
|
531 elif self._delaybuf: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
532 fp = self.opener(self.indexfile, b'a', checkambig=True) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
533 fp.write(b"".join(self._delaybuf)) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
534 fp.close() |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
535 self._delaybuf = None |
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
536 self._divert = False |
4269
73c918c71300
changelog: optimize delayed updates for clone vs pull
Matt Mackall <mpm@selenic.com>
parents:
4261
diff
changeset
|
537 # split when we're done |
35974
9ba1d0c724e2
revlog: rename 'self.checkinlinesize' into '_enforceinlinesize'
Boris Feld <boris.feld@octobus.net>
parents:
35963
diff
changeset
|
538 self._enforceinlinesize(tr) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
539 |
23280
b01c491af0cf
transaction: pass the transaction to 'pending' callback
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23205
diff
changeset
|
540 def _writepending(self, tr): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
541 b"create a file containing the unfinalized state for pretxnchangegroup" |
7787
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
542 if self._delaybuf: |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
543 # make a temporary copy of the index |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
544 fp1 = self._realopener(self.indexfile) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
545 pendingfilename = self.indexfile + b".a" |
23292
e44399c494ab
changelog: register changelog.i.a as a temporary file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23281
diff
changeset
|
546 # register as a temp file to ensure cleanup on failure |
e44399c494ab
changelog: register changelog.i.a as a temporary file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23281
diff
changeset
|
547 tr.registertmp(pendingfilename) |
e44399c494ab
changelog: register changelog.i.a as a temporary file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23281
diff
changeset
|
548 # write existing data |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
549 fp2 = self._realopener(pendingfilename, b"w") |
7787
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
550 fp2.write(fp1.read()) |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
551 # add pending data |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
552 fp2.write(b"".join(self._delaybuf)) |
7787
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
553 fp2.close() |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
554 # switch modes so finalize can simply rename |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
555 self._delaybuf = None |
9164
b0d995b6b0a6
changelog: factor out _delayname
Matt Mackall <mpm@selenic.com>
parents:
9163
diff
changeset
|
556 self._divert = True |
23201
7e97bf6ee2d6
changelog: rework the delayupdate mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23088
diff
changeset
|
557 self.opener = _divertopener(self._realopener, self.indexfile) |
7787
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
558 |
9164
b0d995b6b0a6
changelog: factor out _delayname
Matt Mackall <mpm@selenic.com>
parents:
9163
diff
changeset
|
559 if self._divert: |
7787
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
560 return True |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
561 |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
562 return False |
b8d750daadde
Introduce HG_PREPEND to solve pretxn races
Matt Mackall <mpm@selenic.com>
parents:
7634
diff
changeset
|
563 |
35974
9ba1d0c724e2
revlog: rename 'self.checkinlinesize' into '_enforceinlinesize'
Boris Feld <boris.feld@octobus.net>
parents:
35963
diff
changeset
|
564 def _enforceinlinesize(self, tr, fp=None): |
9165
07f9b2f4a9aa
changelog: swap opener to switch delay modes
Matt Mackall <mpm@selenic.com>
parents:
9164
diff
changeset
|
565 if not self._delayed: |
35974
9ba1d0c724e2
revlog: rename 'self.checkinlinesize' into '_enforceinlinesize'
Boris Feld <boris.feld@octobus.net>
parents:
35963
diff
changeset
|
566 revlog.revlog._enforceinlinesize(self, tr, fp) |
4261
cd7b36b7869c
restructure changelog file appending
Matt Mackall <mpm@selenic.com>
parents:
4258
diff
changeset
|
567 |
5744
9db7fd77417d
changelog: remove extract function
Matt Mackall <mpm@selenic.com>
parents:
5450
diff
changeset
|
568 def read(self, node): |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
569 """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
|
570 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
571 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
|
572 |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
573 - manifest node in binary |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
574 - author/user as a localstr |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
575 - 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
|
576 - list of files |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
577 - commit message as a localstr |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
578 - dict of extra metadata |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
579 |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
580 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
|
581 ``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
|
582 access. |
3077
ad6aecaf4eed
document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
583 """ |
43143
037a8759eda1
sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43142
diff
changeset
|
584 c = changelogrevision(*self._revisiondata(node)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
585 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
|
586 |
28487
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
587 def changelogrevision(self, nodeorrev): |
98d98a645e9d
changelog: add class to represent parsed changelog revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28315
diff
changeset
|
588 """Obtain a ``changelogrevision`` for a node or revision.""" |
43143
037a8759eda1
sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43142
diff
changeset
|
589 text, sidedata = self._revisiondata(nodeorrev) |
037a8759eda1
sidedatacopies: get and store sidedata in the changelogrevision object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43142
diff
changeset
|
590 return changelogrevision(text, sidedata) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
591 |
27439
ed003859f1d8
changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents:
26094
diff
changeset
|
592 def readfiles(self, node): |
ed003859f1d8
changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents:
26094
diff
changeset
|
593 """ |
ed003859f1d8
changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents:
26094
diff
changeset
|
594 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
|
595 """ |
ed003859f1d8
changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents:
26094
diff
changeset
|
596 text = self.revision(node) |
ed003859f1d8
changelog: add a new method to get files modified by a changeset
Laurent Charignon <lcharignon@fb.com>
parents:
26094
diff
changeset
|
597 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
|
598 return [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
599 last = text.index(b"\n\n") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
600 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
|
601 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
|
602 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
603 def add( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
604 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
605 manifest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
606 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
607 desc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
608 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
609 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
610 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
611 user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
612 date=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
613 extra=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
614 p1copies=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
615 p2copies=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
616 filesadded=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
617 filesremoved=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
618 ): |
14379
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
10420
diff
changeset
|
619 # 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
|
620 # 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
|
621 # 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
|
622 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
|
623 |
7035
9d023ef7b467
forbid username with '\n' at the changelog level
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6259
diff
changeset
|
624 user = user.strip() |
8424
c5b3d3e30de7
changelog: refuse to add revisions with empty usernames
Martin Geisler <mg@lazybytes.net>
parents:
7807
diff
changeset
|
625 # 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
|
626 # 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
|
627 # 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
|
628 if not user: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
629 raise error.StorageError(_(b"empty username")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
630 if b"\n" in user: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
631 raise error.StorageError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
632 _(b"username %r contains a newline") % pycompat.bytestr(user) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
633 ) |
8499
fb9b83df45f3
commit: move description trimming into changelog
Matt Mackall <mpm@selenic.com>
parents:
8443
diff
changeset
|
634 |
17810
2894d180afa1
changelog: extract description cleaning logic in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17677
diff
changeset
|
635 desc = stripdesc(desc) |
8499
fb9b83df45f3
commit: move description trimming into changelog
Matt Mackall <mpm@selenic.com>
parents:
8443
diff
changeset
|
636 |
1195
f92af8d53330
Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1095
diff
changeset
|
637 if date: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
638 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
|
639 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
640 parseddate = b"%d %d" % dateutil.makedate() |
10417
58e040c51231
branch: avoid using reserved tag names
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
10263
diff
changeset
|
641 if extra: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
642 branch = extra.get(b"branch") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
643 if branch in (b"default", b""): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
644 del extra[b"branch"] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
645 elif branch in (b".", b"null", b"tip"): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
646 raise error.StorageError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
647 _(b'the name \'%s\' is reserved') % branch |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43027
diff
changeset
|
648 ) |
42426
a1f87294471f
copies: also encode p[12]copies destination as index into "files" list
Martin von Zweigbergk <martinvonz@google.com>
parents:
42407
diff
changeset
|
649 sortedfiles = sorted(files) |
43142
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
650 sidedata = None |
42861
57ea0a81a65c
copies: remove existing copy info from the changeset on amend (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42553
diff
changeset
|
651 if extra is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
652 for name in ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
653 b'p1copies', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
654 b'p2copies', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
655 b'filesadded', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
656 b'filesremoved', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
657 ): |
42861
57ea0a81a65c
copies: remove existing copy info from the changeset on amend (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42553
diff
changeset
|
658 extra.pop(name, None) |
43027
041f042afcc5
copies: move file input processsing early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43026
diff
changeset
|
659 if p1copies is not None: |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
660 p1copies = copies.encodecopies(sortedfiles, p1copies) |
43027
041f042afcc5
copies: move file input processsing early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43026
diff
changeset
|
661 if p2copies is not None: |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
662 p2copies = copies.encodecopies(sortedfiles, p2copies) |
43027
041f042afcc5
copies: move file input processsing early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43026
diff
changeset
|
663 if filesadded is not None: |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
664 filesadded = copies.encodefileindices(sortedfiles, filesadded) |
43027
041f042afcc5
copies: move file input processsing early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43026
diff
changeset
|
665 if filesremoved is not None: |
43147
54e943b28101
sidedatacopies: move various copies related function to the copies modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43146
diff
changeset
|
666 filesremoved = copies.encodefileindices(sortedfiles, filesremoved) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
667 if self._copiesstorage == b'extra': |
43026
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
668 extrasentries = p1copies, p2copies, filesadded, filesremoved |
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
669 if extra is None and any(x is not None for x in extrasentries): |
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
670 extra = {} |
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
671 if p1copies is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
672 extra[b'p1copies'] = p1copies |
43026
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
673 if p2copies is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
674 extra[b'p2copies'] = p2copies |
43026
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
675 if filesadded is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 extra[b'filesadded'] = filesadded |
43026
0b87eb2fba67
copies: prepare changelog for more copies storage mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42861
diff
changeset
|
677 if filesremoved is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
678 extra[b'filesremoved'] = filesremoved |
43142
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
679 elif self._copiesstorage == b'changeset-sidedata': |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
680 sidedata = {} |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
681 if p1copies is not None: |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
682 sidedata[sidedatamod.SD_P1COPIES] = p1copies |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
683 if p2copies is not None: |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
684 sidedata[sidedatamod.SD_P2COPIES] = p2copies |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
685 if filesadded is not None: |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
686 sidedata[sidedatamod.SD_FILESADDED] = filesadded |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
687 if filesremoved is not None: |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
688 sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved |
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
|
689 |
3233
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3232
diff
changeset
|
690 if extra: |
8443
53ff4a5af284
changelog: turn {de,en}code_extra methods into functions
Martin Geisler <mg@lazybytes.net>
parents:
8442
diff
changeset
|
691 extra = encodeextra(extra) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
692 parseddate = b"%s %s" % (parseddate, extra) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
693 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
|
694 text = b"\n".join(l) |
43142
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
695 return self.addrevision( |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
696 text, transaction, len(self), p1, p2, sidedata=sidedata |
beed7ce61681
sidedatacopies: write copies information in sidedata when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
697 ) |
18306
06185554e7e3
changelog: add a `branch` method, bypassing changectx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18231
diff
changeset
|
698 |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
19899
diff
changeset
|
699 def branchinfo(self, rev): |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
19899
diff
changeset
|
700 """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
|
701 |
18308
4e27b06a0fd9
changelog: please check-code and remove tabs
Mads Kiilerich <mads@kiilerich.com>
parents:
18306
diff
changeset
|
702 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
|
703 just to access this is costly.""" |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
19899
diff
changeset
|
704 extra = self.read(rev)[5] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
705 return encoding.tolocal(extra.get(b"branch")), b'close' in extra |
39887
a3095bc47217
changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents:
39777
diff
changeset
|
706 |
a3095bc47217
changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents:
39777
diff
changeset
|
707 def _nodeduplicatecallback(self, transaction, node): |
a3095bc47217
changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents:
39777
diff
changeset
|
708 # 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
|
709 # |
a3095bc47217
changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents:
39777
diff
changeset
|
710 # 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
|
711 duplicates = transaction.changes.setdefault(b'revduplicates', []) |
39887
a3095bc47217
changelog: keep track of duplicated node in the transaction adding them
Boris Feld <boris.feld@octobus.net>
parents:
39777
diff
changeset
|
712 duplicates.append(self.rev(node)) |