annotate mercurial/manifest.py @ 52669:e627cc25b6f3

pyupgrade: rewrite `yield` statements in a loop to `yield from` This is the `legacy` fixer in `pyupgrade`, with the `yield` statement yielding loop commented back in. This seems to help pytype in some cases, and hurt it in others. But that can be manually fixed later. Note that it's possibly buggy in that it aggressively changed `import-checker.py` to `yield from 'fcntl', 'grp', 'pwd', 'select', 'termios': # Unix only`, which is invalid syntax. Possibly it needed help from the token fixer that I've disabled locally (because that wants to make a bunch of unrelated changes). Just change those few places to yield from a list, to avoid having to constantly revert that.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 22:26:16 -0500
parents 5cc8deb96b48
children 4cb75772818d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents: 1072
diff changeset
1 # manifest.py - manifest revision class for mercurial
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46793
diff changeset
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9420
diff changeset
6 # GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
7
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51868
diff changeset
8 from __future__ import annotations
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
9
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
10 import heapq
32569
aa333c1982ab manifest: use itertools.chain() instead of + for Python 3 compat
Augie Fackler <raf@durin42.com>
parents: 32568
diff changeset
11 import itertools
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
12 import struct
52250
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
13 import typing
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
14 import weakref
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
15
51817
50b3ff0ec297 manifest: adds some type things for manifestdict.added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51816
diff changeset
16 from typing import (
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
17 Callable,
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
18 Collection,
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
19 Dict,
51817
50b3ff0ec297 manifest: adds some type things for manifestdict.added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51816
diff changeset
20 Iterable,
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
21 Iterator,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
22 List,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
23 Optional,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
24 Set,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
25 Tuple,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
26 Union,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
27 cast,
51817
50b3ff0ec297 manifest: adds some type things for manifestdict.added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51816
diff changeset
28 )
50b3ff0ec297 manifest: adds some type things for manifestdict.added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51816
diff changeset
29
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
30 from .i18n import _
31536
160e7ad941e9 manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents: 31483
diff changeset
31 from .node import (
160e7ad941e9 manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents: 31483
diff changeset
32 bin,
160e7ad941e9 manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents: 31483
diff changeset
33 hex,
39343
53363a8eff57 manifest: don't go through revlog to access node symbols
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39342
diff changeset
34 nullrev,
31536
160e7ad941e9 manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents: 31483
diff changeset
35 )
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
36 from . import (
44164
c443b9ba6f63 py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents: 43798
diff changeset
37 encoding,
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
38 error,
44332
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
39 match as matchmod,
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
40 mdiff,
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
41 pathutil,
32411
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32292
diff changeset
42 policy,
38340
cf59de802883 py3: remove b'' from error message of disallowed filename
Yuya Nishihara <yuya@tcha.org>
parents: 37374
diff changeset
43 pycompat,
27502
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
44 revlog,
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
45 util,
2df7f5c09c34 manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27466
diff changeset
46 )
42823
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42740
diff changeset
47 from .interfaces import (
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42740
diff changeset
48 repository,
38532
c82ea938efbb repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38514
diff changeset
49 )
47089
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47083
diff changeset
50 from .revlogutils import (
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47083
diff changeset
51 constants as revlog_constants,
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47083
diff changeset
52 )
79
837d473d54d5 Add basic annotation support
mpm@selenic.com
parents: 78
diff changeset
53
52250
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
54 if typing.TYPE_CHECKING:
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
55 from typing import (
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
56 ByteString,
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
57 )
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
58
0851d94bfdaa manifest: delay import of `typing.ByteString` for py 3.14 support (issue6940)
Matt Harbison <matt_harbison@yahoo.com>
parents: 52098
diff changeset
59
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43346
diff changeset
60 parsers = policy.importmod('parsers')
24322
f263814c72ac manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents: 24298
diff changeset
61 propertycache = util.propertycache
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
62
42170
89c0c8edc9d4 tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents: 41970
diff changeset
63 # Allow tests to more easily test the alternate path in manifestdict.fastdelta()
89c0c8edc9d4 tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents: 41970
diff changeset
64 FASTDELTA_TEXTDIFF_THRESHOLD = 1000
89c0c8edc9d4 tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents: 41970
diff changeset
65
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
66
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
67 def _parse(nodelen, data: bytes):
24524
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
68 # This method does a little bit of excessive-looking
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
69 # precondition checking. This is so that the behavior of this
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
70 # class exactly matches its C counterpart to try and help
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
71 # prevent surprise breakage for anyone that develops against
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
72 # the pure version.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
73 if data and data[-1:] != b'\n':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
74 raise ValueError(b'Manifest did not end in a newline.')
24524
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
75 prev = None
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
76 for l in data.splitlines():
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
77 if prev is not None and prev > l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
78 raise ValueError(b'Manifest lines not in sorted order.')
24524
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
79 prev = l
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
80 f, n = l.split(b'\0')
44706
ce126b6bea79 manifest: remove a final 40-byte assumption from pure-python parser
Augie Fackler <augie@google.com>
parents: 44705
diff changeset
81 nl = len(n)
45119
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
82 flags = n[-1:]
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
83 if flags in _manifestflags:
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
84 n = n[:-1]
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
85 nl -= 1
24524
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
86 else:
45119
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
87 flags = b''
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
88 if nl != 2 * nodelen:
45119
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
89 raise ValueError(b'Invalid manifest line')
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
90
19748c73c208 manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents: 45118
diff changeset
91 yield f, bin(n), flags
24524
63b6031384fc manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24502
diff changeset
92
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
93
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
94 def _text(it):
24525
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
95 files = []
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
96 lines = []
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
97 for f, n, fl in it:
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
98 files.append(f)
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
99 # if this is changed to support newlines in filenames,
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
100 # be sure to check the templates/ dir again (especially *-raw.tmpl)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
101 lines.append(b"%s\0%s%s\n" % (f, hex(n), fl))
24525
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
102
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
103 _checkforbidden(files)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
104 return b''.join(lines)
24525
e118f74d246f manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents: 24524
diff changeset
105
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
106
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49017
diff changeset
107 class lazymanifestiter:
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
108 def __init__(self, lm: '_LazyManifest') -> None:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
109 self.pos = 0
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
110 self.lm = lm
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
111
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
112 def __iter__(self) -> 'lazymanifestiter':
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
113 return self
24223
b4df0d0c49e7 manifest: move parsing functions up in file
Augie Fackler <augie@google.com>
parents: 24215
diff changeset
114
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
115 def next(self) -> bytes:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
116 try:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
117 data, pos = self.lm._get(self.pos)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
118 except IndexError:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
119 raise StopIteration
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
120 if pos == -1:
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
121 assert isinstance(data, tuple)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
122 self.pos += 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
123 return data[0]
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
124 assert isinstance(data, bytes)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
125 self.pos += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
126 zeropos = data.find(b'\x00', pos)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
127 return data[pos:zeropos]
24224
d71837d06597 manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents: 24223
diff changeset
128
31373
91874c247d61 manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents: 31361
diff changeset
129 __next__ = next
91874c247d61 manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents: 31361
diff changeset
130
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
131
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49017
diff changeset
132 class lazymanifestiterentries:
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
133 def __init__(self, lm: '_LazyManifest') -> None:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
134 self.lm = lm
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
135 self.pos = 0
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
136
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
137 def __iter__(self) -> 'lazymanifestiterentries':
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
138 return self
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
139
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
140 def next(self) -> Tuple[bytes, bytes, bytes]:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
141 try:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
142 data, pos = self.lm._get(self.pos)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
143 except IndexError:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
144 raise StopIteration
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
145 if pos == -1:
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
146 assert isinstance(data, tuple)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
147 self.pos += 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
148 return data
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
149 assert isinstance(data, bytes)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
150 zeropos = data.find(b'\x00', pos)
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
151 nlpos = data.find(b'\n', pos)
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
152 if zeropos == -1 or nlpos == -1 or nlpos < zeropos:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
153 raise error.StorageError(b'Invalid manifest line')
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
154 flags = data[nlpos - 1 : nlpos]
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
155 if flags in _manifestflags:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
156 hlen = nlpos - zeropos - 2
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
157 else:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
158 hlen = nlpos - zeropos - 1
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
159 flags = b''
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
160 if hlen != 2 * self.lm._nodelen:
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
161 raise error.StorageError(b'Invalid manifest line')
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
162 hashval = unhexlify(
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
163 data, self.lm.extrainfo[self.pos], zeropos + 1, hlen
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
164 )
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
165 self.pos += 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
166 return (data[pos:zeropos], hashval, flags)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
167
31373
91874c247d61 manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents: 31361
diff changeset
168 __next__ = next
91874c247d61 manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents: 31361
diff changeset
169
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
170
51816
2f88df88f5b9 manifest: type and fix unhexlify
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51812
diff changeset
171 def unhexlify(data: bytes, extra: int, pos, length: int):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
172 s = bin(data[pos : pos + length])
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
173 if extra:
51816
2f88df88f5b9 manifest: type and fix unhexlify
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51812
diff changeset
174 s += bytes([extra & 0xFF])
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
175 return s
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
176
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
177
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
178 def _cmp(a, b):
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
179 return (a > b) - (a < b)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
180
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
181
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
182 _manifestflags = {b'', b'l', b't', b'x'}
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
183
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
184
51820
3e9a660b074a manifest: expose a version of the Class without interface decorator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51818
diff changeset
185 class _LazyManifest:
42172
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
186 """A pure python manifest backed by a byte string. It is supplimented with
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
187 internal lists as it is modified, until it is compacted back to a pure byte
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
188 string.
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
189
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
190 ``data`` is the initial manifest data.
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
191
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
192 ``positions`` is a list of offsets, one per manifest entry. Positive
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
193 values are offsets into ``data``, negative values are offsets into the
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
194 ``extradata`` list. When an entry is removed, its entry is dropped from
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
195 ``positions``. The values are encoded such that when walking the list and
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
196 indexing into ``data`` or ``extradata`` as appropriate, the entries are
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
197 sorted by filename.
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
198
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
199 ``extradata`` is a list of (key, hash, flags) for entries that were added or
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
200 modified since the manifest was created or compacted.
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
201 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
202
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
203 def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
204 self,
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
205 nodelen: int,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
206 data: bytes,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
207 positions=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
208 extrainfo=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
209 extradata=None,
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
210 hasremovals: bool = False,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
211 ):
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
212 self._nodelen = nodelen
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
213 if positions is None:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
214 self.positions = self.findlines(data)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
215 self.extrainfo = [0] * len(self.positions)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
216 self.data = data
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
217 self.extradata = []
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
218 self.hasremovals = False
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
219 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
220 self.positions = positions[:]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
221 self.extrainfo = extrainfo[:]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
222 self.extradata = extradata[:]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
223 self.data = data
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
224 self.hasremovals = hasremovals
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
225
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
226 def findlines(self, data: bytes) -> List[int]:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
227 if not data:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
228 return []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
229 pos = data.find(b"\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
230 if pos == -1 or data[-1:] != b'\n':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
231 raise ValueError(b"Manifest did not end in a newline.")
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
232 positions = [0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
233 prev = data[: data.find(b'\x00')]
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
234 while pos < len(data) - 1 and pos != -1:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
235 positions.append(pos + 1)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
236 nexts = data[pos + 1 : data.find(b'\x00', pos + 1)]
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
237 if nexts < prev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
238 raise ValueError(b"Manifest lines not in sorted order.")
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
239 prev = nexts
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
240 pos = data.find(b"\n", pos + 1)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
241 return positions
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
242
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
243 def _get(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
244 self, index: int
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
245 ) -> Tuple[Union[bytes, Tuple[bytes, bytes, bytes]], int]:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
246 # get the position encoded in pos:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
247 # positive number is an index in 'data'
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
248 # negative number is in extrapieces
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
249 pos = self.positions[index]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
250 if pos >= 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
251 return self.data, pos
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
252 return self.extradata[-pos - 1], -1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
253
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
254 def _getkey(self, pos) -> bytes:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
255 if pos >= 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
256 return self.data[pos : self.data.find(b'\x00', pos + 1)]
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
257 return self.extradata[-pos - 1][0]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
258
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
259 def bsearch(self, key: bytes) -> int:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
260 first = 0
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
261 last = len(self.positions) - 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
262
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
263 while first <= last:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
264 midpoint = (first + last) // 2
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
265 nextpos = self.positions[midpoint]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
266 candidate = self._getkey(nextpos)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
267 r = _cmp(key, candidate)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
268 if r == 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
269 return midpoint
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
270 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
271 if r < 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
272 last = midpoint - 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
273 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
274 first = midpoint + 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
275 return -1
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
276
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
277 def bsearch2(self, key: bytes) -> Tuple[int, bool]:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
278 # same as the above, but will always return the position
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
279 # done for performance reasons
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
280 first = 0
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
281 last = len(self.positions) - 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
282
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
283 while first <= last:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
284 midpoint = (first + last) // 2
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
285 nextpos = self.positions[midpoint]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
286 candidate = self._getkey(nextpos)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
287 r = _cmp(key, candidate)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
288 if r == 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
289 return (midpoint, True)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
290 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
291 if r < 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
292 last = midpoint - 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
293 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
294 first = midpoint + 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
295 return (first, False)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
296
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
297 def __contains__(self, key: bytes) -> bool:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
298 return self.bsearch(key) != -1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
299
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
300 def __getitem__(self, key: bytes) -> Tuple[bytes, bytes]:
31376
ef50b491c17d manifest: ensure paths are bytes (not str) in pure parser
Augie Fackler <augie@google.com>
parents: 31375
diff changeset
301 if not isinstance(key, bytes):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
302 raise TypeError(b"getitem: manifest keys must be a bytes.")
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
303 needle = self.bsearch(key)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
304 if needle == -1:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
305 raise KeyError
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
306 data, pos = self._get(needle)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
307 if pos == -1:
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
308 assert isinstance(data, tuple)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
309 return (data[1], data[2])
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
310
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
311 assert isinstance(data, bytes)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
312 zeropos = data.find(b'\x00', pos)
44706
ce126b6bea79 manifest: remove a final 40-byte assumption from pure-python parser
Augie Fackler <augie@google.com>
parents: 44705
diff changeset
313 nlpos = data.find(b'\n', zeropos)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
314 assert 0 <= needle <= len(self.positions)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
315 assert len(self.extrainfo) == len(self.positions)
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
316 if zeropos == -1 or nlpos == -1 or nlpos < zeropos:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
317 raise error.StorageError(b'Invalid manifest line')
44706
ce126b6bea79 manifest: remove a final 40-byte assumption from pure-python parser
Augie Fackler <augie@google.com>
parents: 44705
diff changeset
318 hlen = nlpos - zeropos - 1
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
319 flags = data[nlpos - 1 : nlpos]
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
320 if flags in _manifestflags:
44706
ce126b6bea79 manifest: remove a final 40-byte assumption from pure-python parser
Augie Fackler <augie@google.com>
parents: 44705
diff changeset
321 hlen -= 1
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
322 else:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
323 flags = b''
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
324 if hlen != 2 * self._nodelen:
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
325 raise error.StorageError(b'Invalid manifest line')
44706
ce126b6bea79 manifest: remove a final 40-byte assumption from pure-python parser
Augie Fackler <augie@google.com>
parents: 44705
diff changeset
326 hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, hlen)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
327 return (hashval, flags)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
328
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
329 def __delitem__(self, key: bytes) -> None:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
330 needle, found = self.bsearch2(key)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
331 if not found:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
332 raise KeyError
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
333 cur = self.positions[needle]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
334 self.positions = self.positions[:needle] + self.positions[needle + 1 :]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
335 self.extrainfo = self.extrainfo[:needle] + self.extrainfo[needle + 1 :]
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
336 if cur >= 0:
42172
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
337 # This does NOT unsort the list as far as the search functions are
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
338 # concerned, as they only examine lines mapped by self.positions.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
339 self.data = self.data[:cur] + b'\x00' + self.data[cur + 1 :]
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
340 self.hasremovals = True
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
341
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
342 def __setitem__(self, key: bytes, value: Tuple[bytes, bytes]):
31537
326bca5477d0 manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents: 31536
diff changeset
343 if not isinstance(key, bytes):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
344 raise TypeError(b"setitem: manifest keys must be a byte string.")
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
345 if not isinstance(value, tuple) or len(value) != 2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
346 raise TypeError(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
347 b"Manifest values must be a tuple of (node, flags)."
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
348 )
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
349 hashval = value[0]
45253
ff59af8395a5 manifest: kill one more instance of the old merge hash hack
Joerg Sonnenberger <joerg@bec.de>
parents: 45119
diff changeset
350 if not isinstance(hashval, bytes) or len(hashval) not in (20, 32):
44705
75f1197db884 manifest: fix yet another 20-byte-hash assumption
Augie Fackler <augie@google.com>
parents: 44704
diff changeset
351 raise TypeError(b"node must be a 20-byte or 32-byte byte string")
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
352 flags = value[1]
31537
326bca5477d0 manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents: 31536
diff changeset
353 if not isinstance(flags, bytes) or len(flags) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
354 raise TypeError(b"flags must a 0 or 1 byte string, got %r", flags)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
355 needle, found = self.bsearch2(key)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
356 if found:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
357 # put the item
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
358 pos = self.positions[needle]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
359 if pos < 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
360 self.extradata[-pos - 1] = (key, hashval, value[1])
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
361 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
362 # just don't bother
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
363 self.extradata.append((key, hashval, value[1]))
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
364 self.positions[needle] = -len(self.extradata)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
365 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
366 # not found, put it in with extra positions
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
367 self.extradata.append((key, hashval, value[1]))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
368 self.positions = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
369 self.positions[:needle]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
370 + [-len(self.extradata)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
371 + self.positions[needle:]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
372 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
373 self.extrainfo = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
374 self.extrainfo[:needle] + [0] + self.extrainfo[needle:]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
375 )
24298
49cd847fd69a lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents: 24297
diff changeset
376
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
377 def copy(self) -> '_LazyManifest':
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
378 # XXX call _compact like in C?
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
379 return _lazymanifest(
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
380 self._nodelen,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
381 self.data,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
382 self.positions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
383 self.extrainfo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
384 self.extradata,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
385 self.hasremovals,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
386 )
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
387
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
388 def _compact(self) -> None:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
389 # hopefully not called TOO often
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
390 if len(self.extradata) == 0 and not self.hasremovals:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
391 return
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
392 l = []
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
393 i = 0
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
394 offset = 0
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
395 self.extrainfo = [0] * len(self.positions)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
396 while i < len(self.positions):
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
397 if self.positions[i] >= 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
398 cur = self.positions[i]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
399 last_cut = cur
42172
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
400
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
401 # Collect all contiguous entries in the buffer at the current
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
402 # offset, breaking out only for added/modified items held in
c3484ddbdb96 manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents: 42171
diff changeset
403 # extradata, or a deleted line prior to the next position.
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
404 while True:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
405 self.positions[i] = offset
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
406 i += 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
407 if i == len(self.positions) or self.positions[i] < 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
408 break
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
409
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
410 # A removed file has no positions[] entry, but does have an
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
411 # overwritten first byte. Break out and find the end of the
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
412 # current good entry/entries if there is a removed file
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
413 # before the next position.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
414 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
415 self.hasremovals
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
416 and self.data.find(b'\n\x00', cur, self.positions[i])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
417 != -1
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
418 ):
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
419 break
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
420
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
421 offset += self.positions[i] - cur
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
422 cur = self.positions[i]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
423 end_cut = self.data.find(b'\n', cur)
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
424 if end_cut != -1:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
425 end_cut += 1
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
426 offset += end_cut - cur
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
427 l.append(self.data[last_cut:end_cut])
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
428 else:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
429 while i < len(self.positions) and self.positions[i] < 0:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
430 cur = self.positions[i]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
431 t = self.extradata[-cur - 1]
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
432 l.append(self._pack(t))
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
433 self.positions[i] = offset
44704
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
434 # Hashes are either 20 bytes (old sha1s) or 32
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
435 # bytes (new non-sha1).
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
436 hlen = 20
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
437 if len(t[1]) > 25:
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
438 hlen = 32
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
439 if len(t[1]) > hlen:
0415a566742a manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents: 44703
diff changeset
440 self.extrainfo[i] = ord(t[1][hlen + 1])
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
441 offset += len(l[-1])
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
442 i += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
443 self.data = b''.join(l)
42171
0546ead39a7e manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42170
diff changeset
444 self.hasremovals = False
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
445 self.extradata = []
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
446
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
447 def _pack(self, d: Tuple[bytes, bytes, bytes]) -> bytes:
44701
ecbba7b2e444 manifest: remove a 20-byte-hash assumption from pure manifest parsing
Augie Fackler <augie@google.com>
parents: 44666
diff changeset
448 n = d[1]
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
449 assert len(n) in (20, 32)
44701
ecbba7b2e444 manifest: remove a 20-byte-hash assumption from pure manifest parsing
Augie Fackler <augie@google.com>
parents: 44666
diff changeset
450 return d[0] + b'\x00' + hex(n) + d[2] + b'\n'
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
451
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
452 def text(self) -> ByteString:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
453 self._compact()
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
454 return self.data
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
455
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
456 def diff(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
457 self, m2: '_LazyManifest', clean: bool = False
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
458 ) -> Dict[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
459 bytes,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
460 Optional[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
461 Tuple[Tuple[Optional[bytes], bytes], Tuple[Optional[bytes], bytes]]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
462 ],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
463 ]:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
464 '''Finds changes between the current manifest and m2.'''
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
465 # XXX think whether efficiency matters here
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
466 diff = {}
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
467
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
468 for fn, e1, flags in self.iterentries():
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
469 if fn not in m2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
470 diff[fn] = (e1, flags), (None, b'')
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
471 else:
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
472 e2 = m2[fn]
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
473 if (e1, flags) != e2:
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
474 diff[fn] = (e1, flags), e2
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
475 elif clean:
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
476 diff[fn] = None
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
477
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
478 for fn, e2, flags in m2.iterentries():
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
479 if fn not in self:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
480 diff[fn] = (None, b''), (e2, flags)
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
481
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
482 return diff
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
483
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
484 def iterentries(self) -> lazymanifestiterentries:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
485 return lazymanifestiterentries(self)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
486
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
487 def iterkeys(self) -> lazymanifestiter:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
488 return lazymanifestiter(self)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
489
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
490 def __iter__(self) -> lazymanifestiter:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
491 return lazymanifestiter(self)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
492
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
493 def __len__(self) -> int:
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
494 return len(self.positions)
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
495
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
496 def filtercopy(self, filterfn: Callable[[bytes], bool]) -> '_LazyManifest':
30042
d24e03da24b5 lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents: 30002
diff changeset
497 # XXX should be optimized
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
498 c = _lazymanifest(self._nodelen, b'')
24298
49cd847fd69a lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents: 24297
diff changeset
499 for f, n, fl in self.iterentries():
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
500 if filterfn(f):
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
501 c[f] = n, fl
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
502 return c
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
503
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
504
24226
b992769dd1be manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
505 try:
b992769dd1be manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
506 _lazymanifest = parsers.lazymanifest
b992769dd1be manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
507 except AttributeError:
51820
3e9a660b074a manifest: expose a version of the Class without interface decorator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51818
diff changeset
508 _lazymanifest = _LazyManifest
24226
b992769dd1be manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
509
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
510
52524
6412dcec52d3 manifest: subclass the new `repository.imanifestdict` Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 52513
diff changeset
511 class manifestdict(repository.imanifestdict):
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
512 def __init__(self, nodelen: int, data: ByteString = b''):
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
513 self._nodelen = nodelen
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
514 self._lm = _lazymanifest(nodelen, data)
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
515
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
516 def __getitem__(self, key: bytes) -> bytes:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
517 return self._lm[key][0]
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
518
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
519 def find(self, key: bytes) -> Tuple[bytes, bytes]:
24277
22d560fe1516 manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24226
diff changeset
520 return self._lm[key]
22d560fe1516 manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24226
diff changeset
521
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
522 def __len__(self) -> int:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
523 return len(self._lm)
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
524
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
525 def __nonzero__(self) -> bool:
30341
b19291e5d506 manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents: 30309
diff changeset
526 # nonzero is covered by the __len__ function, but implementing it here
b19291e5d506 manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents: 30309
diff changeset
527 # makes it easier for extensions to override.
b19291e5d506 manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents: 30309
diff changeset
528 return len(self._lm) != 0
b19291e5d506 manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents: 30309
diff changeset
529
31483
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31376
diff changeset
530 __bool__ = __nonzero__
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31376
diff changeset
531
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
532 def set(self, key: bytes, node: bytes, flags: bytes) -> None:
51812
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
533 self._lm[key] = node, flags
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
534
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
535 def __setitem__(self, key: bytes, node: bytes) -> None:
44304
dbbae122f5e4 manifest: remove optional default= argument on flags(path)
Augie Fackler <augie@google.com>
parents: 43798
diff changeset
536 self._lm[key] = node, self.flags(key)
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
537
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
538 def __contains__(self, key: bytes) -> bool:
34352
05167447f90d py3: return False early while checking whether None is a key in lazymanifest
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34303
diff changeset
539 if key is None:
05167447f90d py3: return False early while checking whether None is a key in lazymanifest
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34303
diff changeset
540 return False
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
541 return key in self._lm
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
542
51844
62b25293b620 typing: correct a type hint in `mercurial.manifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51840
diff changeset
543 def __delitem__(self, key: bytes) -> None:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
544 del self._lm[key]
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
545
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
546 def __iter__(self) -> Iterator[bytes]:
24298
49cd847fd69a lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents: 24297
diff changeset
547 return self._lm.__iter__()
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
548
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
549 def iterkeys(self) -> Iterator[bytes]:
24295
2b7ab29627fd lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24292
diff changeset
550 return self._lm.iterkeys()
2b7ab29627fd lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24292
diff changeset
551
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
552 def keys(self) -> List[bytes]:
24295
2b7ab29627fd lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24292
diff changeset
553 return list(self.iterkeys())
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
554
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
555 def filesnotin(self, m2, match=None) -> Set[bytes]:
24184
cd66080ef6d4 copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24147
diff changeset
556 '''Set of files in this manifest that are not in the other'''
44332
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
557 if match is not None:
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
558 match = matchmod.badmatch(match, lambda path, msg: None)
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
559 sm2 = set(m2.walk(match))
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
560 return {f for f in self.walk(match) if f not in sm2}
bbecb6d80aa7 manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents: 44331
diff changeset
561 return {f for f in self if f not in m2}
24184
cd66080ef6d4 copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 24147
diff changeset
562
24322
f263814c72ac manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents: 24298
diff changeset
563 @propertycache
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
564 def _dirs(self) -> pathutil.dirs:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
565 return pathutil.dirs(self)
24322
f263814c72ac manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents: 24298
diff changeset
566
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
567 def dirs(self) -> pathutil.dirs:
24322
f263814c72ac manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents: 24298
diff changeset
568 return self._dirs
f263814c72ac manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents: 24298
diff changeset
569
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
570 def hasdir(self, dir: bytes) -> bool:
24324
149cc171e4a0 manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents: 24322
diff changeset
571 return dir in self._dirs
149cc171e4a0 manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents: 24322
diff changeset
572
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
573 def _filesfastpath(self, match: matchmod.basematcher) -> bool:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
574 """Checks whether we can correctly and quickly iterate over matcher
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
575 files instead of over manifest files."""
24685
b3d78d82d84c manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24684
diff changeset
576 files = match.files()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
577 return len(files) < 100 and (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
578 match.isexact()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
579 or (match.prefix() and all(fn in self for fn in files))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
580 )
24685
b3d78d82d84c manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24684
diff changeset
581
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
582 def walk(self, match: matchmod.basematcher) -> Iterator[bytes]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
583 """Generates matching file names.
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
584
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
585 Equivalent to manifest.matches(match).iterkeys(), but without creating
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
586 an entirely new manifest.
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
587
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
588 It also reports nonexistent files by marking them bad with match.bad().
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
589 """
24683
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
590 if match.always():
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
591 yield from iter(self)
24683
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
592 return
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
593
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
594 fset = set(match.files())
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
595
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
596 # avoid the entire walk if we're only looking for specific files
24685
b3d78d82d84c manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24684
diff changeset
597 if self._filesfastpath(match):
24667
19c5b0913960 manifest.walk: join nested if-conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 24666
diff changeset
598 for fn in sorted(fset):
44316
48a1a974a92c manifest: fix _very_ subtle bug with exact matchers passed to walk()
Augie Fackler <augie@google.com>
parents: 44309
diff changeset
599 if fn in self:
48a1a974a92c manifest: fix _very_ subtle bug with exact matchers passed to walk()
Augie Fackler <augie@google.com>
parents: 44309
diff changeset
600 yield fn
24682
aef3d1469773 manifest.walk: use return instead of StopIteration in generator
Martin von Zweigbergk <martinvonz@google.com>
parents: 24670
diff changeset
601 return
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
602
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
603 for fn in self:
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
604 if fn in fset:
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
605 # specified pattern is the exact name
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
606 fset.remove(fn)
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
607 if match(fn):
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
608 yield fn
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
609
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
610 # for dirstate.walk, files=[''] means "walk the whole tree".
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
611 # follow that here, too
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
612 fset.discard(b'')
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
613
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
614 for fn in sorted(fset):
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
615 if not self.hasdir(fn):
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
616 match.bad(fn, None)
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
617
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
618 def _matches(self, match: matchmod.basematcher) -> 'manifestdict':
23305
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
619 '''generate a new manifest filtered by the match argument'''
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
620 if match.always():
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
621 return self.copy()
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
622
24685
b3d78d82d84c manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24684
diff changeset
623 if self._filesfastpath(match):
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
624 m = manifestdict(self._nodelen)
24666
3092885b5b32 manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24665
diff changeset
625 lm = self._lm
3092885b5b32 manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24665
diff changeset
626 for fn in match.files():
3092885b5b32 manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24665
diff changeset
627 if fn in lm:
3092885b5b32 manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24665
diff changeset
628 m._lm[fn] = lm[fn]
3092885b5b32 manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24665
diff changeset
629 return m
23305
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
630
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
631 m = manifestdict(self._nodelen)
24664
ea4a7c8909ae manifestdict.matches: avoid name 'lm' for a not-lazymanifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24647
diff changeset
632 m._lm = self._lm.filtercopy(match)
ea4a7c8909ae manifestdict.matches: avoid name 'lm' for a not-lazymanifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24647
diff changeset
633 return m
23305
0cc283f44655 manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 22966
diff changeset
634
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
635 def diff(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
636 self,
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
637 m2: 'manifestdict',
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
638 match: Optional[matchmod.basematcher] = None,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
639 clean: bool = False,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
640 ) -> Dict[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
641 bytes,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
642 Optional[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
643 Tuple[Tuple[Optional[bytes], bytes], Tuple[Optional[bytes], bytes]]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
644 ],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
645 ]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
646 """Finds changes between the current manifest and m2.
23756
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
647
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
648 Args:
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
649 m2: the manifest to which this manifest should be compared.
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
650 clean: if true, include files unchanged between these manifests
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
651 with a None value in the returned dictionary.
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
652
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
653 The result is returned as a dict with filename as key and
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
654 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
655 nodeid in the current/other manifest and fl1/fl2 is the flag
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
656 in the current/other manifest. Where the file does not exist,
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
657 the nodeid will be None and the flags will be the empty
829f640b5540 manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents: 23602
diff changeset
658 string.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
659 """
31265
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 31163
diff changeset
660 if match:
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
661 m1 = self._matches(match)
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
662 m2 = m2._matches(match)
31265
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 31163
diff changeset
663 return m1.diff(m2, clean=clean)
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
664 return self._lm.diff(m2._lm, clean)
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
665
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
666 def setflag(self, key: bytes, flag: bytes) -> None:
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
667 if flag not in _manifestflags:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
668 raise TypeError(b"Invalid manifest flag set.")
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
669 self._lm[key] = self[key], flag
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
670
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
671 def get(self, key: bytes, default=None) -> Optional[bytes]:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
672 try:
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
673 return self._lm[key][0]
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
674 except KeyError:
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
675 return default
22965
b697fa74b475 manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22964
diff changeset
676
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
677 def flags(self, key: bytes) -> bytes:
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
678 try:
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
679 return self._lm[key][1]
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
680 except KeyError:
44304
dbbae122f5e4 manifest: remove optional default= argument on flags(path)
Augie Fackler <augie@google.com>
parents: 43798
diff changeset
681 return b''
22965
b697fa74b475 manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22964
diff changeset
682
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
683 def copy(self) -> 'manifestdict':
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
684 c = manifestdict(self._nodelen)
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
685 c._lm = self._lm.copy()
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
686 return c
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24224
diff changeset
687
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
688 def items(self) -> Iterator[Tuple[bytes, bytes]]:
24298
49cd847fd69a lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents: 24297
diff changeset
689 return (x[:2] for x in self._lm.iterentries())
2831
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
690
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
691 def iteritems(self) -> Iterator[Tuple[bytes, bytes]]:
38657
28c9d67d88ab manifest: just duplicate the definition of items as iteritems
Augie Fackler <augie@google.com>
parents: 38557
diff changeset
692 return (x[:2] for x in self._lm.iterentries())
32583
b98199a5c3e1 cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents: 32569
diff changeset
693
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
694 def iterentries(self) -> Iterator[Tuple[bytes, bytes, bytes]]:
28203
7297e9e13a8a verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27502
diff changeset
695 return self._lm.iterentries()
7297e9e13a8a verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27502
diff changeset
696
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
697 def text(self) -> ByteString:
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
698 # most likely uses native version
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
699 return self._lm.text()
22408
dc97e04c12ad manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents: 21879
diff changeset
700
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
701 def fastdelta(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
702 self, base: ByteString, changes: Iterable[Tuple[bytes, bool]]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
703 ) -> Tuple[ByteString, ByteString]:
31790
6bfea18df609 manifest: update comment to be about bytearray
Martin von Zweigbergk <martinvonz@google.com>
parents: 31655
diff changeset
704 """Given a base manifest text as a bytearray and a list of changes
22931
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
705 relative to that text, compute a delta that can be used by revlog.
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
706 """
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
707 delta = []
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
708 dstart = None
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
709 dend = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
710 dline = [b""]
22931
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
711 start = 0
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
712 # zero copy representation of base as a buffer
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
713 addbuf = util.buffer(base)
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
714
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
715 changes = list(changes)
42170
89c0c8edc9d4 tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents: 41970
diff changeset
716 if len(changes) < FASTDELTA_TEXTDIFF_THRESHOLD:
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
717 # start with a readonly loop that finds the offset of
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
718 # each line and creates the deltas
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
719 for f, todelete in changes:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
720 # bs will either be the index of the item or the insert point
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
721 start, end = _msearch(addbuf, f, start)
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
722 if not todelete:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
723 h, fl = self._lm[f]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
724 l = b"%s\0%s%s\n" % (f, hex(h), fl)
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
725 else:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
726 if start == end:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
727 # item we want to delete was not found, error out
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
728 raise AssertionError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
729 _(b"failed to remove %s from manifest") % f
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
730 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
731 l = b""
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
732 if dstart is not None and dstart <= start and dend >= start:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
733 if dend < end:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
734 dend = end
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
735 if l:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
736 dline.append(l)
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
737 else:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
738 if dstart is not None:
51821
897972398e61 manifest: use tuple for `delta` in `fastdelta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51820
diff changeset
739 delta.append((dstart, dend, b"".join(dline)))
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
740 dstart = start
22931
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
741 dend = end
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
742 dline = [l]
22931
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
743
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
744 if dstart is not None:
51821
897972398e61 manifest: use tuple for `delta` in `fastdelta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51820
diff changeset
745 delta.append((dstart, dend, b"".join(dline)))
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
746 # apply the delta to the base, and get a delta for addrevision
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
747 deltatext, arraytext = _addlistdelta(base, delta)
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
748 else:
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
749 # For large changes, it's much cheaper to just build the text and
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
750 # diff it.
31355
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31303
diff changeset
751 arraytext = bytearray(self.text())
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31303
diff changeset
752 deltatext = mdiff.textdiff(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
753 util.buffer(base), util.buffer(arraytext)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
754 )
26871
1cbf144fd8a1 manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents: 26402
diff changeset
755
22931
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
756 return arraytext, deltatext
48c0b101a9de manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents: 22930
diff changeset
757
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
758
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
759 def _msearch(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
760 m: ByteString, s: bytes, lo: int = 0, hi: Optional[int] = None
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
761 ) -> Tuple[int, int]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
762 """return a tuple (start, end) that says where to find s within m.
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
763
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
764 If the string is found m[start:end] are the line containing
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
765 that string. If start == end the string was not found and
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
766 they indicate the proper sorted insertion point.
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
767 """
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
768
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
769 def advance(i: int, c: bytes):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
770 while i < lenm and m[i : i + 1] != c:
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
771 i += 1
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
772 return i
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
773
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
774 if not s:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
775 return (lo, lo)
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
776 lenm = len(m)
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
777 if not hi:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
778 hi = lenm
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
779 while lo < hi:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
780 mid = (lo + hi) // 2
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
781 start = mid
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
782 while start > 0 and m[start - 1 : start] != b'\n':
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
783 start -= 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
784 end = advance(start, b'\0')
31655
23391acfc421 py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents: 31537
diff changeset
785 if bytes(m[start:end]) < s:
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
786 # we know that after the null there are 40 bytes of sha1
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
787 # this translates to the bisect lo = mid + 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
788 lo = advance(end + 40, b'\n') + 1
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
789 else:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
790 # this translates to the bisect hi = mid
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
791 hi = start
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
792 end = advance(lo, b'\0')
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
793 found = m[lo:end]
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
794 if s == found:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
795 # we know that after the null there are 40 bytes of sha1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
796 end = advance(end + 40, b'\n')
22930
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
797 return (lo, end + 1)
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
798 else:
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
799 return (lo, lo)
1acb81d10eaf manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents: 22929
diff changeset
800
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
801
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
802 def _checkforbidden(l: Iterable[bytes]) -> None:
22408
dc97e04c12ad manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents: 21879
diff changeset
803 """Check filenames for illegal characters."""
dc97e04c12ad manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents: 21879
diff changeset
804 for f in l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
805 if b'\n' in f or b'\r' in f:
39793
b63dee7bd0d9 global: replace most uses of RevlogError with StorageError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39779
diff changeset
806 raise error.StorageError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
807 _(b"'\\n' and '\\r' disallowed in filenames: %r")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
808 % pycompat.bytestr(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
809 )
22408
dc97e04c12ad manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents: 21879
diff changeset
810
dc97e04c12ad manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents: 21879
diff changeset
811
22409
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
812 # apply the changes collected during the bisect loop to our addlist
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
813 # return a delta suitable for addrevision
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
814 def _addlistdelta(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
815 addlist: ByteString,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
816 x: Iterable[Tuple[int, int, bytes]],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
817 ) -> Tuple[bytes, ByteString]:
22409
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
818 # for large addlist arrays, building a new array is cheaper
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
819 # than repeatedly modifying the existing one
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
820 currentposition = 0
31355
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31303
diff changeset
821 newaddlist = bytearray()
22409
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
822
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
823 for start, end, content in x:
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
824 newaddlist += addlist[currentposition:start]
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
825 if content:
31355
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31303
diff changeset
826 newaddlist += bytearray(content)
22409
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
827
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
828 currentposition = end
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
829
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
830 newaddlist += addlist[currentposition:]
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
831
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
832 deltatext = b"".join(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
833 struct.pack(b">lll", start, end, len(content)) + content
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
834 for start, end, content in x
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
835 )
22409
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
836 return deltatext, newaddlist
8f09b785b59b manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents: 22408
diff changeset
837
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
838
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
839 def _splittopdir(f: bytes) -> Tuple[bytes, bytes]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
840 if b'/' in f:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
841 dir, subpath = f.split(b'/', 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
842 return dir + b'/', subpath
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
843 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
844 return b'', f
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
845
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
846
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
847 _noop = lambda s: None
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
848
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
849
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
850 class treemanifest: # (repository.imanifestdict)
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
851 _dir: bytes
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
852 _dirs: Dict[bytes, 'treemanifest']
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
853 _dirty: bool
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
854 _files: Dict[bytes, bytes]
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
855 _flags: Dict[bytes, bytes]
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
856
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
857 def __init__(self, nodeconstants, dir: bytes = b'', text: bytes = b''):
24403
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
858 self._dir = dir
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
859 self.nodeconstants = nodeconstants
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
860 self._node = self.nodeconstants.nullid
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
861 self._nodelen = self.nodeconstants.nodelen
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
862 self._loadfunc = _noop
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
863 self._copyfunc = _noop
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
864 self._dirty = False
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
865 self._dirs = {}
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
866 self._lazydirs: Dict[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
867 bytes,
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
868 Tuple[bytes, Callable[[bytes, bytes], 'treemanifest'], bool],
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
869 ] = {}
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
870 # Using _lazymanifest here is a little slower than plain old dicts
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
871 self._files = {}
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
872 self._flags = {}
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
873 if text:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
874
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
875 def readsubtree(subdir, subm):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
876 raise AssertionError(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
877 b'treemanifest constructor only accepts flat manifests'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
878 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
879
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
880 self.parse(text, readsubtree)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
881 self._dirty = True # Mark flat manifest dirty after parsing
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
882
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
883 def _subpath(self, path: bytes) -> bytes:
24403
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
884 return self._dir + path
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
885
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
886 def _loadalllazy(self) -> None:
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
887 selfdirs = self._dirs
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
888 subpath = self._subpath
49017
3d35e7483602 manifest: remove pycompat.iteritems()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
889 for d, (node, readsubtree, docopy) in self._lazydirs.items():
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
890 if docopy:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
891 selfdirs[d] = readsubtree(subpath(d), node).copy()
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
892 else:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
893 selfdirs[d] = readsubtree(subpath(d), node)
51822
3be39e36732a manifest: clear `_lazydirs` in place in `_loadalllazy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51821
diff changeset
894 self._lazydirs.clear()
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
895
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
896 def _loadlazy(self, d: bytes) -> None:
39982
da0319e024c0 treemanifests: make _loadlazy tolerate item not on _lazydirs
spectral <spectral@google.com>
parents: 39874
diff changeset
897 v = self._lazydirs.get(d)
51823
1c28d9fdcd08 manifest: use explicit None checking in `_loadlazy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51822
diff changeset
898 if v is not None:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
899 node, readsubtree, docopy = v
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
900 if docopy:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
901 self._dirs[d] = readsubtree(self._subpath(d), node).copy()
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
902 else:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
903 self._dirs[d] = readsubtree(self._subpath(d), node)
39982
da0319e024c0 treemanifests: make _loadlazy tolerate item not on _lazydirs
spectral <spectral@google.com>
parents: 39874
diff changeset
904 del self._lazydirs[d]
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
905
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
906 def _loadchildrensetlazy(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
907 self, visit: Union[Set[bytes], bytes]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
908 ) -> Optional[Set[bytes]]:
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
909 if not visit:
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
910 return None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
911 if visit == b'all' or visit == b'this':
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
912 self._loadalllazy()
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
913 return None
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
914
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
915 visit = cast(Set[bytes], visit)
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
916
39983
19103e68a698 treemanifests: make _loadchildrensetlazy just call _loadlazy
spectral <spectral@google.com>
parents: 39982
diff changeset
917 loadlazy = self._loadlazy
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
918 for k in visit:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
919 loadlazy(k + b'/')
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
920 return visit
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
921
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
922 def _loaddifflazy(self, t1: 'treemanifest', t2: 'treemanifest'):
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
923 """load items in t1 and t2 if they're needed for diffing.
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
924
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
925 The criteria currently is:
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
926 - if it's not present in _lazydirs in either t1 or t2, load it in the
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
927 other (it may already be loaded or it may not exist, doesn't matter)
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
928 - if it's present in _lazydirs in both, compare the nodeid; if it
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
929 differs, load it in both
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
930 """
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
931 toloadlazy = []
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
932 for d, v1 in t1._lazydirs.items():
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
933 v2 = t2._lazydirs.get(d)
51824
8e1b28687704 manifest: use explicit None checking in `_loaddifflazy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51823
diff changeset
934 if v2 is None or v2[0] != v1[0]:
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
935 toloadlazy.append(d)
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
936 for d, v1 in t2._lazydirs.items():
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
937 if d not in t1._lazydirs:
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
938 toloadlazy.append(d)
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
939
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
940 for d in toloadlazy:
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
941 t1._loadlazy(d)
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
942 t2._loadlazy(d)
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
943
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
944 def __len__(self) -> int:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
945 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
946 size = len(self._files)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
947 self._loadalllazy()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
948 for m in self._dirs.values():
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
949 size += m.__len__()
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
950 return size
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
951
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
952 def __nonzero__(self) -> bool:
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
953 # Faster than "__len__() != 0" since it avoids loading sub-manifests
36212
b42c47b8c9d4 treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents: 36133
diff changeset
954 return not self._isempty()
b42c47b8c9d4 treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents: 36133
diff changeset
955
b42c47b8c9d4 treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents: 36133
diff changeset
956 __bool__ = __nonzero__
b42c47b8c9d4 treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents: 36133
diff changeset
957
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
958 def _isempty(self) -> bool:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
959 self._load() # for consistency; already loaded by all callers
39533
079d7bfa463d treemanifest: attempt to avoid loading all lazily-loaded subdirs in _isempty
Kyle Lippincott <spectral@google.com>
parents: 39532
diff changeset
960 # See if we can skip loading everything.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
961 if self._files or (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
962 self._dirs and any(not m._isempty() for m in self._dirs.values())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
963 ):
39533
079d7bfa463d treemanifest: attempt to avoid loading all lazily-loaded subdirs in _isempty
Kyle Lippincott <spectral@google.com>
parents: 39532
diff changeset
964 return False
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
965 self._loadalllazy()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
966 return not self._dirs or all(m._isempty() for m in self._dirs.values())
24551
4fdf5eac5b39 treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents: 24550
diff changeset
967
44164
c443b9ba6f63 py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents: 43798
diff changeset
968 @encoding.strmethod
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
969 def __repr__(self) -> bytes:
43346
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
970 return (
44164
c443b9ba6f63 py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents: 43798
diff changeset
971 b'<treemanifest dir=%s, node=%s, loaded=%r, dirty=%r at 0x%x>'
43346
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
972 % (
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
973 self._dir,
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
974 hex(self._node),
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
975 bool(self._loadfunc is _noop),
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
976 self._dirty,
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
977 id(self),
6ada8a274b9c formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43117
diff changeset
978 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
979 )
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
980
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
981 def dir(self) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
982 """The directory that this tree manifest represents, including a
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
983 trailing '/'. Empty string for the repo root directory."""
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
984 return self._dir
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
985
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
986 def node(self) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
987 """This node of this instance. nullid for unsaved instances. Should
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
988 be updated when the instance is read or written from a revlog.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
989 """
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
990 assert not self._dirty
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
991 return self._node
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
992
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
993 def setnode(self, node: bytes) -> None:
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
994 self._node = node
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
995 self._dirty = False
24403
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
996
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
997 def iterentries(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
998 self,
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
999 ) -> Iterator[Tuple[bytes, Union[bytes, 'treemanifest'], bytes]]:
28206
8ab91d9290ce treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents: 28203
diff changeset
1000 self._load()
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1001 self._loadalllazy()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1002 for p, n in sorted(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1003 itertools.chain(self._dirs.items(), self._files.items())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1004 ):
28206
8ab91d9290ce treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents: 28203
diff changeset
1005 if p in self._files:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1006 yield self._subpath(p), n, self._flags.get(p, b'')
28206
8ab91d9290ce treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents: 28203
diff changeset
1007 else:
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1008 yield from n.iterentries()
28206
8ab91d9290ce treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents: 28203
diff changeset
1009
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1010 def items(self) -> Iterator[Tuple[bytes, Union[bytes, 'treemanifest']]]:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1011 self._load()
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1012 self._loadalllazy()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1013 for p, n in sorted(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1014 itertools.chain(self._dirs.items(), self._files.items())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1015 ):
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1016 if p in self._files:
24403
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
1017 yield self._subpath(p), n
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1018 else:
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1019 yield from n.items()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1020
32583
b98199a5c3e1 cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents: 32569
diff changeset
1021 iteritems = items
b98199a5c3e1 cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents: 32569
diff changeset
1022
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1023 def iterkeys(self) -> Iterator[bytes]:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1024 self._load()
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1025 self._loadalllazy()
32569
aa333c1982ab manifest: use itertools.chain() instead of + for Python 3 compat
Augie Fackler <raf@durin42.com>
parents: 32568
diff changeset
1026 for p in sorted(itertools.chain(self._dirs, self._files)):
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1027 if p in self._files:
24403
0e23faa1511c treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24402
diff changeset
1028 yield self._subpath(p)
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1029 else:
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1030 yield from self._dirs[p]
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1031
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1032 def keys(self) -> List[bytes]:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1033 return list(self.iterkeys())
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1034
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1035 def __iter__(self) -> Iterator[bytes]:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1036 return self.iterkeys()
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1037
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1038 def __contains__(self, f: bytes) -> bool:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1039 if f is None:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1040 return False
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1041 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1042 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1043 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1044 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1045
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1046 if dir not in self._dirs:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1047 return False
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1048
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1049 return self._dirs[dir].__contains__(subpath)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1050 else:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1051 return f in self._files
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1052
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1053 def get(self, f: bytes, default: Optional[bytes] = None) -> Optional[bytes]:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1054 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1055 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1056 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1057 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1058
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1059 if dir not in self._dirs:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1060 return default
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1061 return self._dirs[dir].get(subpath, default)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1062 else:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1063 return self._files.get(f, default)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1064
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1065 def __getitem__(self, f: bytes) -> bytes:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1066 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1067 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1068 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1069 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1070
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1071 return self._dirs[dir].__getitem__(subpath)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1072 else:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1073 return self._files[f]
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1074
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1075 def flags(self, f: bytes) -> bytes:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1076 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1077 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1078 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1079 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1080
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1081 if dir not in self._dirs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1082 return b''
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1083 return self._dirs[dir].flags(subpath)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1084 else:
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1085 if f in self._lazydirs or f in self._dirs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1086 return b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1087 return self._flags.get(f, b'')
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1088
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1089 def find(self, f: bytes) -> Tuple[bytes, bytes]:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1090 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1091 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1092 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1093 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1094
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1095 return self._dirs[dir].find(subpath)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1096 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1097 return self._files[f], self._flags.get(f, b'')
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1098
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1099 def __delitem__(self, f: bytes) -> None:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1100 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1101 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1102 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1103 self._loadlazy(dir)
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1104
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1105 self._dirs[dir].__delitem__(subpath)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1106 # If the directory is now empty, remove it
24551
4fdf5eac5b39 treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents: 24550
diff changeset
1107 if self._dirs[dir]._isempty():
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1108 del self._dirs[dir]
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1109 else:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1110 del self._files[f]
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1111 if f in self._flags:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1112 del self._flags[f]
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1113 self._dirty = True
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1114
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1115 def set(self, f: bytes, node: bytes, flags: bytes) -> None:
51812
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1116 """Set both the node and the flags for path f."""
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1117 assert node is not None
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1118 if flags not in _manifestflags:
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1119 raise TypeError(b"Invalid manifest flag set.")
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1120 self._load()
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1121 dir, subpath = _splittopdir(f)
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1122 if dir:
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1123 self._loadlazy(dir)
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1124 if dir not in self._dirs:
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1125 self._dirs[dir] = treemanifest(
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1126 self.nodeconstants, self._subpath(dir)
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1127 )
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1128 self._dirs[dir].set(subpath, node, flags)
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1129 else:
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1130 assert len(node) in (20, 32)
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1131 self._files[f] = node
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1132 self._flags[f] = flags
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1133 self._dirty = True
421c9b3f2f4e commit: set whole manifest entries at once (node with its associated flags)
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51052
diff changeset
1134
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1135 def __setitem__(self, f: bytes, n: bytes) -> None:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1136 assert n is not None
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1137 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1138 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1139 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1140 self._loadlazy(dir)
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1141 if dir not in self._dirs:
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1142 self._dirs[dir] = treemanifest(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1143 self.nodeconstants, self._subpath(dir)
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1144 )
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1145 self._dirs[dir].__setitem__(subpath, n)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1146 else:
44703
0e99b876966a manifest: teach treemanifest about long hashes
Augie Fackler <augie@google.com>
parents: 44701
diff changeset
1147 # manifest nodes are either 20 bytes or 32 bytes,
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1148 # depending on the hash in use. Assert this as historically
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1149 # sometimes extra bytes were added.
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1150 assert len(n) in (20, 32)
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1151 self._files[f] = n
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1152 self._dirty = True
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1153
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1154 def _load(self) -> None:
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1155 if self._loadfunc is not _noop:
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1156 lf, self._loadfunc = self._loadfunc, _noop
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1157 lf(self)
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1158 elif self._copyfunc is not _noop:
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1159 cf, self._copyfunc = self._copyfunc, _noop
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1160 cf(self)
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1161
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1162 def setflag(self, f: bytes, flags: bytes) -> None:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1163 """Set the flags (symlink, executable) for path f."""
45118
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1164 if flags not in _manifestflags:
d0ef8c1dddd4 manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents: 45067
diff changeset
1165 raise TypeError(b"Invalid manifest flag set.")
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1166 self._load()
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1167 dir, subpath = _splittopdir(f)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1168 if dir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1169 self._loadlazy(dir)
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1170 if dir not in self._dirs:
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1171 self._dirs[dir] = treemanifest(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1172 self.nodeconstants, self._subpath(dir)
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1173 )
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1174 self._dirs[dir].setflag(subpath, flags)
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1175 else:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1176 self._flags[f] = flags
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1177 self._dirty = True
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1178
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1179 def copy(self) -> 'treemanifest':
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1180 copy = treemanifest(self.nodeconstants, self._dir)
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1181 copy._node = self._node
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1182 copy._dirty = self._dirty
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1183 if self._copyfunc is _noop:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1184
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1185 def _copyfunc(s):
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1186 self._load()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1187 s._lazydirs = {
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1188 d: (n, r, True) for d, (n, r, c) in self._lazydirs.items()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1189 }
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1190 sdirs = s._dirs
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1191 for d, v in self._dirs.items():
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1192 sdirs[d] = v.copy()
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1193 s._files = dict.copy(self._files)
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1194 s._flags = dict.copy(self._flags)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1195
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1196 if self._loadfunc is _noop:
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1197 _copyfunc(copy)
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1198 else:
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1199 copy._copyfunc = _copyfunc
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1200 else:
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1201 copy._copyfunc = self._copyfunc
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1202 return copy
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1203
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1204 def filesnotin(
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1205 self, m2: 'treemanifest', match: Optional[matchmod.basematcher] = None
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1206 ) -> Set[bytes]:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1207 '''Set of files in this manifest that are not in the other'''
39534
8798be5f04fc treemanifest: avoid unnecessary copies/processing when using alwaysmatcher
Kyle Lippincott <spectral@google.com>
parents: 39533
diff changeset
1208 if match and not match.always():
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1209 m1 = self._matches(match)
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1210 m2 = m2._matches(match)
31265
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 31163
diff changeset
1211 return m1.filesnotin(m2)
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 31163
diff changeset
1212
24405
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1213 files = set()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1214
24405
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1215 def _filesnotin(t1, t2):
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1216 if t1._node == t2._node and not t1._dirty and not t2._dirty:
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1217 return
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1218 t1._load()
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1219 t2._load()
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
1220 self._loaddifflazy(t1, t2)
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1221 for d, m1 in t1._dirs.items():
24405
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1222 if d in t2._dirs:
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1223 m2 = t2._dirs[d]
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1224 _filesnotin(m1, m2)
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1225 else:
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1226 files.update(m1.iterkeys())
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1227
36333
413c179cf7d5 manifest: correct the one use of iterkeys() on a dict
Augie Fackler <augie@google.com>
parents: 36212
diff changeset
1228 for fn in t1._files:
24405
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1229 if fn not in t2._files:
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1230 files.add(t1._subpath(fn))
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1231
cbe9d50d9e65 treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24404
diff changeset
1232 _filesnotin(self, m2)
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1233 return files
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1234
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1235 @propertycache
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1236 def _alldirs(self) -> pathutil.dirs:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
1237 return pathutil.dirs(self)
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1238
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1239 def dirs(self) -> pathutil.dirs:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1240 return self._alldirs
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1241
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1242 def hasdir(self, dir: bytes) -> bool:
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1243 self._load()
24406
1297480ed347 treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24405
diff changeset
1244 topdir, subdir = _splittopdir(dir)
1297480ed347 treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24405
diff changeset
1245 if topdir:
39984
3cacb74c3a22 treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents: 39983
diff changeset
1246 self._loadlazy(topdir)
24406
1297480ed347 treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24405
diff changeset
1247 if topdir in self._dirs:
1297480ed347 treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24405
diff changeset
1248 return self._dirs[topdir].hasdir(subdir)
1297480ed347 treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24405
diff changeset
1249 return False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1250 dirslash = dir + b'/'
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1251 return dirslash in self._dirs or dirslash in self._lazydirs
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1252
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1253 def walk(self, match: matchmod.basematcher) -> Iterator[bytes]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1254 """Generates matching file names.
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1255
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1256 It also reports nonexistent files by marking them bad with match.bad().
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1257 """
24683
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
1258 if match.always():
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1259 yield from iter(self)
24683
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
1260 return
4eaea0ed8dc1 manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents: 24682
diff changeset
1261
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1262 fset = set(match.files())
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1263
24647
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1264 for fn in self._walk(match):
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1265 if fn in fset:
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1266 # specified pattern is the exact name
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1267 fset.remove(fn)
24647
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1268 yield fn
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1269
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
1270 # for dirstate.walk, files=[''] means "walk the whole tree".
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1271 # follow that here, too
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1272 fset.discard(b'')
24646
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1273
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1274 for fn in sorted(fset):
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1275 if not self.hasdir(fn):
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1276 match.bad(fn, None)
5693c834bcb4 manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents: 24636
diff changeset
1277
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1278 def _walk(self, match: matchmod.basematcher) -> Iterator[bytes]:
25188
2773540c3650 match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents: 25185
diff changeset
1279 '''Recursively generates matching file names for walk().'''
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
1280 visit = match.visitchildrenset(self._dir[:-1])
39539
3ba9ef0fb693 treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents: 39538
diff changeset
1281 if not visit:
25188
2773540c3650 match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents: 25185
diff changeset
1282 return
24647
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1283
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1284 # yield this dir's files and walk its submanifests
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1285 self._load()
39539
3ba9ef0fb693 treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents: 39538
diff changeset
1286 visit = self._loadchildrensetlazy(visit)
36334
5245bac09e6a manifest: use list(dict) instead of dict.keys() to get a list of keys
Augie Fackler <augie@google.com>
parents: 36333
diff changeset
1287 for p in sorted(list(self._dirs) + list(self._files)):
24647
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1288 if p in self._files:
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1289 fullp = self._subpath(p)
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1290 if match(fullp):
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1291 yield fullp
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1292 else:
39539
3ba9ef0fb693 treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents: 39538
diff changeset
1293 if not visit or p[:-1] in visit:
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1294 yield from self._dirs[p]._walk(match)
24647
fb446c57f8f9 treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents: 24646
diff changeset
1295
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1296 def _matches(self, match: matchmod.basematcher) -> 'treemanifest':
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1297 """recursively generate a new manifest filtered by the match argument."""
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1298 if match.always():
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1299 return self.copy()
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1300 return self._matches_inner(match)
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1301
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1302 def _matches_inner(self, match: matchmod.basematcher) -> 'treemanifest':
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1303 if match.always():
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1304 return self.copy()
27343
c59647c6694d treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27271
diff changeset
1305
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
1306 visit = match.visitchildrenset(self._dir[:-1])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1307 if visit == b'all':
27343
c59647c6694d treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27271
diff changeset
1308 return self.copy()
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1309 ret = treemanifest(self.nodeconstants, self._dir)
27343
c59647c6694d treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27271
diff changeset
1310 if not visit:
25188
2773540c3650 match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents: 25185
diff changeset
1311 return ret
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1312
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1313 self._load()
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1314 for fn in self._files:
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1315 # While visitchildrenset *usually* lists only subdirs, this is
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1316 # actually up to the matcher and may have some files in the set().
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1317 # If visit == 'this', we should obviously look at the files in this
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1318 # directory; if visit is a set, and fn is in it, we should inspect
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1319 # fn (but no need to inspect things not in the set).
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1320 if visit != b'this' and fn not in visit:
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1321 continue
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1322 fullp = self._subpath(fn)
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1323 # visitchildrenset isn't perfect, we still need to call the regular
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1324 # matcher code to further filter results.
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1325 if not match(fullp):
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1326 continue
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1327 ret._files[fn] = self._files[fn]
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1328 if fn in self._flags:
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1329 ret._flags[fn] = self._flags[fn]
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1330
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1331 visit = self._loadchildrensetlazy(visit)
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1332 for dir, subm in self._dirs.items():
39538
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1333 if visit and dir[:-1] not in visit:
154e4f84b51c treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents: 39535
diff changeset
1334 continue
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1335 m = subm._matches_inner(match)
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1336 if not m._isempty():
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1337 ret._dirs[dir] = m
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1338
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1339 if not ret._isempty():
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1340 ret._dirty = True
24552
a2292da6d821 treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents: 24551
diff changeset
1341 return ret
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1342
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1343 def fastdelta(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1344 self, base: ByteString, changes: Iterable[Tuple[bytes, bool]]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1345 ) -> ByteString:
44665
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1346 raise FastdeltaUnavailable()
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1347
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1348 def diff(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1349 self,
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1350 m2: 'treemanifest',
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1351 match: Optional[matchmod.basematcher] = None,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1352 clean: bool = False,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1353 ) -> Dict[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1354 bytes,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1355 Optional[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1356 Tuple[Tuple[Optional[bytes], bytes], Tuple[Optional[bytes], bytes]]
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1357 ],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1358 ]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1359 """Finds changes between the current manifest and m2.
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1360
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1361 Args:
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1362 m2: the manifest to which this manifest should be compared.
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1363 clean: if true, include files unchanged between these manifests
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1364 with a None value in the returned dictionary.
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1365
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1366 The result is returned as a dict with filename as key and
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1367 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1368 nodeid in the current/other manifest and fl1/fl2 is the flag
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1369 in the current/other manifest. Where the file does not exist,
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1370 the nodeid will be None and the flags will be the empty
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1371 string.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1372 """
39534
8798be5f04fc treemanifest: avoid unnecessary copies/processing when using alwaysmatcher
Kyle Lippincott <spectral@google.com>
parents: 39533
diff changeset
1373 if match and not match.always():
44386
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1374 m1 = self._matches(match)
0bf3b5e80d30 manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents: 44332
diff changeset
1375 m2 = m2._matches(match)
31265
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 31163
diff changeset
1376 return m1.diff(m2, clean=clean)
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1377 result = {}
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1378 emptytree = treemanifest(self.nodeconstants)
41153
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1379
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1380 def _iterativediff(t1, t2, stack):
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1381 """compares two tree manifests and append new tree-manifests which
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1382 needs to be compared to stack"""
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1383 if t1._node == t2._node and not t1._dirty and not t2._dirty:
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1384 return
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1385 t1._load()
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1386 t2._load()
40039
906c95073ff7 treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents: 39988
diff changeset
1387 self._loaddifflazy(t1, t2)
39985
731961d972ba treemanifests: remove _loadalllazy in _diff()
spectral <spectral@google.com>
parents: 39984
diff changeset
1388
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1389 for d, m1 in t1._dirs.items():
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1390 m2 = t2._dirs.get(d, emptytree)
41153
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1391 stack.append((m1, m2))
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1392
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1393 for d, m2 in t2._dirs.items():
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1394 if d not in t1._dirs:
41153
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1395 stack.append((emptytree, m2))
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1396
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1397 for fn, n1 in t1._files.items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1398 fl1 = t1._flags.get(fn, b'')
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1399 n2 = t2._files.get(fn, None)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1400 fl2 = t2._flags.get(fn, b'')
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1401 if n1 != n2 or fl1 != fl2:
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1402 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2))
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1403 elif clean:
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1404 result[t1._subpath(fn)] = None
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1405
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1406 for fn, n2 in t2._files.items():
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1407 if fn not in t1._files:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1408 fl2 = t2._flags.get(fn, b'')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1409 result[t2._subpath(fn)] = ((None, b''), (n2, fl2))
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1410
41153
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1411 stackls = []
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1412 _iterativediff(self, m2, stackls)
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1413 while stackls:
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1414 t1, t2 = stackls.pop()
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1415 # stackls is populated in the function call
2c3f69855ce8 manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41041
diff changeset
1416 _iterativediff(t1, t2, stackls)
24404
96cccf1e3257 treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents: 24403
diff changeset
1417 return result
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1418
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1419 def unmodifiedsince(self, m2: 'treemanifest') -> bool:
25221
eafa06e9edde treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents: 25220
diff changeset
1420 return not self._dirty and not m2._dirty and self._node == m2._node
eafa06e9edde treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents: 25220
diff changeset
1421
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1422 def parse(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1423 self,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1424 text: bytes,
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1425 readsubtree: Callable[[bytes, bytes], 'treemanifest'],
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1426 ) -> None:
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1427 selflazy = self._lazydirs
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
1428 for f, n, fl in _parse(self._nodelen, text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1429 if fl == b't':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1430 f = f + b'/'
40040
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
1431 # False below means "doesn't need to be copied" and can use the
a0c18b271ea1 treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents: 40039
diff changeset
1432 # cached value from readsubtree directly.
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
1433 selflazy[f] = (n, readsubtree, False)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1434 elif b'/' in f:
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1435 # This is a flat manifest, so use __setitem__ and setflag rather
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1436 # than assigning directly to _files and _flags, so we can
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1437 # assign a path in a subdirectory, and to mark dirty (compared
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1438 # to nullid).
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1439 self[f] = n
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1440 if fl:
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1441 self.setflag(f, fl)
25220
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1442 else:
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1443 # Assigning to _files and _flags avoids marking as dirty,
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1444 # and should be a little faster.
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1445 self._files[f] = n
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1446 if fl:
f0fbd88b21fb treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 25188
diff changeset
1447 self._flags[f] = fl
24781
055b3cbe6c57 treemanifest: extract parse method from constructor
Martin von Zweigbergk <martinvonz@google.com>
parents: 24780
diff changeset
1448
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1449 def text(self) -> ByteString:
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1450 """Get the full data of this manifest as a bytestring."""
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1451 self._load()
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
1452 return _text(self.iterentries())
24401
e6e023d57e94 treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24396
diff changeset
1453
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1454 def dirtext(self) -> ByteString:
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1455 """Get the full data of this directory as a bytestring. Make sure that
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1456 any submanifests have been written first, so their nodeids are correct.
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1457 """
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1458 self._load()
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1459 flags = self.flags
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1460 lazydirs = [(d[:-1], v[0], b't') for d, v in self._lazydirs.items()]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1461 dirs = [(d[:-1], self._dirs[d]._node, b't') for d in self._dirs]
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1462 files = [(f, self._files[f], flags(f)) for f in self._files]
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1463 return _text(sorted(dirs + files + lazydirs))
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1464
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1465 def read(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1466 self,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1467 gettext: Callable[[], ByteString],
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1468 readsubtree: Callable[[bytes, bytes], 'treemanifest'],
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1469 ) -> None:
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1470 def _load_for_read(s):
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1471 s.parse(gettext(), readsubtree)
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1472 s._dirty = False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1473
26402
05871262acd5 treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents: 26401
diff changeset
1474 self._loadfunc = _load_for_read
25222
0de132d5328a treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 25221
diff changeset
1475
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1476 def writesubtrees(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1477 self,
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1478 m1: 'treemanifest',
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1479 m2: 'treemanifest',
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1480 writesubtree: Callable[
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1481 [
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1482 Callable[['treemanifest'], None],
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1483 bytes,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1484 bytes,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1485 matchmod.basematcher,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1486 ],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1487 None,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1488 ],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1489 match: matchmod.basematcher,
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1490 ) -> None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1491 self._load() # for consistency; should never have any effect here
29892
8a84347b9907 manifest: call m1.load and m2.load before writing a subtree
Durham Goode <durham@fb.com>
parents: 29837
diff changeset
1492 m1._load()
8a84347b9907 manifest: call m1.load and m2.load before writing a subtree
Durham Goode <durham@fb.com>
parents: 29837
diff changeset
1493 m2._load()
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1494 emptytree = treemanifest(self.nodeconstants)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1495
39535
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1496 def getnode(m, d):
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1497 ld = m._lazydirs.get(d)
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1498 if ld:
46096
93e09d370003 treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents: 45957
diff changeset
1499 return ld[0]
51825
e2f1efa2bd86 manifest: help pytype to understant `writesubtrees`'s `getnode` type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51824
diff changeset
1500 tree = m._dirs.get(d, emptytree)
e2f1efa2bd86 manifest: help pytype to understant `writesubtrees`'s `getnode` type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51824
diff changeset
1501 assert tree is not None # helps pytype
e2f1efa2bd86 manifest: help pytype to understant `writesubtrees`'s `getnode` type
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51824
diff changeset
1502 return tree._node
39535
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1503
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1504 # let's skip investigating things that `match` says we do not need.
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
1505 visit = match.visitchildrenset(self._dir[:-1])
40041
67b93cd847fb treemanifests: remove _loadalllazy when doing copies
spectral <spectral@google.com>
parents: 40040
diff changeset
1506 visit = self._loadchildrensetlazy(visit)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1507 if visit == b'this' or visit == b'all':
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1508 visit = None
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1509 for d, subm in self._dirs.items():
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1510 if visit and d[:-1] not in visit:
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1511 continue
39535
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1512 subp1 = getnode(m1, d)
c29548ba4a75 treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents: 39534
diff changeset
1513 subp2 = getnode(m2, d)
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
1514 if subp1 == self.nodeconstants.nullid:
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1515 subp1, subp2 = subp2, subp1
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1516 writesubtree(subm, subp1, subp2, match)
25091
b5052fc73300 treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 24956
diff changeset
1517
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1518 def walksubtrees(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1519 self, matcher: Optional[matchmod.basematcher] = None
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
1520 ) -> Iterator['treemanifest']:
31876
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1521 """Returns an iterator of the subtrees of this manifest, including this
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1522 manifest itself.
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1523
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1524 If `matcher` is provided, it only returns subtrees that match.
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1525 """
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
1526 if matcher and not matcher.visitdir(self._dir[:-1]):
31876
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1527 return
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1528 if not matcher or matcher(self._dir[:-1]):
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1529 yield self
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1530
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1531 self._load()
39532
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1532 # OPT: use visitchildrenset to avoid loading everything.
93486cc46125 treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents: 39349
diff changeset
1533 self._loadalllazy()
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
1534 for d, subm in self._dirs.items():
52669
e627cc25b6f3 pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52668
diff changeset
1535 yield from subm.walksubtrees(matcher=matcher)
31876
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31790
diff changeset
1536
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1537
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1538 class manifestfulltextcache(util.lrucachedict):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1539 """File-backed LRU cache for the manifest cache
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1540
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1541 File consists of entries, up to EOF:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1542
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1543 - 20 bytes node, 4 bytes length, <length> manifest data
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1544
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1545 These are written in reverse cache order (oldest to newest).
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1546
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1547 """
41967
07c80298b5a1 manifestcache: abstract the filename in a class attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41966
diff changeset
1548
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1549 _file = b'manifestfulltextcache'
41967
07c80298b5a1 manifestcache: abstract the filename in a class attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41966
diff changeset
1550
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1551 def __init__(self, max):
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1552 super().__init__(max)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1553 self._dirty = False
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1554 self._read = False
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1555 self._opener = None
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1556
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1557 def read(self):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1558 if self._read or self._opener is None:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1559 return
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1560
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1561 try:
41967
07c80298b5a1 manifestcache: abstract the filename in a class attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41966
diff changeset
1562 with self._opener(self._file) as fp:
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1563 set = super().__setitem__
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1564 # ignore trailing data, this is a cache, corruption is skipped
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1565 while True:
44708
61134a232d00 manifest: leave a TODO where we may have more work for sha1 portability
Augie Fackler <augie@google.com>
parents: 44706
diff changeset
1566 # TODO do we need to do work here for sha1 portability?
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1567 node = fp.read(20)
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1568 if len(node) < 20:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1569 break
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1570 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1571 size = struct.unpack(b'>L', fp.read(4))[0]
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1572 except struct.error:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1573 break
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1574 value = bytearray(fp.read(size))
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1575 if len(value) != size:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1576 break
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1577 set(node, value)
52665
24ee91ba9aa8 pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52524
diff changeset
1578 except OSError:
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1579 # the file is allowed to be missing
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1580 pass
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1581
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1582 self._read = True
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1583 self._dirty = False
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1584
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1585 def write(self):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1586 if not self._dirty or self._opener is None:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1587 return
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1588 # rotate backwards to the first used node
44773
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1589 try:
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1590 with self._opener(
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1591 self._file, b'w', atomictemp=True, checkambig=True
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1592 ) as fp:
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1593 node = self._head.prev
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1594 while True:
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1595 if node.key in self._cache:
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1596 fp.write(node.key)
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1597 fp.write(struct.pack(b'>L', len(node.value)))
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1598 fp.write(node.value)
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1599 if node is self._head:
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1600 break
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1601 node = node.prev
52665
24ee91ba9aa8 pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52524
diff changeset
1602 except OSError:
44773
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1603 # We could not write the cache (eg: permission error)
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1604 # the content can be missing.
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1605 #
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1606 # We could try harder and see if we could recreate a wcache
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1607 # directory were we coudl write too.
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1608 #
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1609 # XXX the error pass silently, having some way to issue an error
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1610 # log `ui.log` would be nice.
35bb67427f63 manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44708
diff changeset
1611 pass
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1612
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1613 def __len__(self):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1614 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1615 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1616 return super().__len__()
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1617
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1618 def __contains__(self, k):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1619 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1620 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1621 return super().__contains__(k)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1622
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1623 def __iter__(self):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1624 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1625 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1626 return super().__iter__()
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1627
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1628 def __getitem__(self, k):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1629 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1630 self.read()
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1631 # the cache lru order can change on read
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1632 setdirty = self._cache.get(k) is not self._head
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1633 value = super().__getitem__(k)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1634 if setdirty:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1635 self._dirty = True
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1636 return value
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1637
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1638 def __setitem__(self, k, v):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1639 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1640 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1641 super().__setitem__(k, v)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1642 self._dirty = True
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1643
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1644 def __delitem__(self, k):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1645 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1646 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1647 super().__delitem__(k)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1648 self._dirty = True
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1649
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1650 def get(self, k, default=None):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1651 if not self._read:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1652 self.read()
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1653 return super().get(k, default=default)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1654
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1655 def clear(self, clear_persisted_data=False):
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
1656 super().clear()
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1657 if clear_persisted_data:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1658 self._dirty = True
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1659 self.write()
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1660 self._read = False
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1661
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1662
42478
bc4373babd04 revlog: add the option to track the expected compression upper bound
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42399
diff changeset
1663 # and upper bound of what we expect from compression
bc4373babd04 revlog: add the option to track the expected compression upper bound
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42399
diff changeset
1664 # (real live value seems to be "3")
42485
4a3abb33380a deltas: set estimated compression upper bound to "3x" instead of "10x"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42478
diff changeset
1665 MAXCOMPRESSION = 3
42478
bc4373babd04 revlog: add the option to track the expected compression upper bound
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42399
diff changeset
1666
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1667
44665
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1668 class FastdeltaUnavailable(Exception):
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1669 """Exception raised when fastdelta isn't usable on a manifest."""
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1670
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1671
52093
4675ab746a02 manifest: drop the CamelCase name for `manifest.manifestrevlog`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52092
diff changeset
1672 class manifestrevlog: # (repository.imanifeststorage)
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1673 """A revlog that stores manifest texts. This is responsible for caching the
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1674 full-text manifest contents.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
1675 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1676
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1677 def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1678 self,
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1679 nodeconstants,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1680 opener,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1681 tree=b'',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1682 dirlogcache=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1683 treemanifest=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1684 ):
31161
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1685 """Constructs a new manifest revlog
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1686
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1687 `indexfile` - used by extensions to have two manifests at once, like
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1688 when transitioning between flatmanifeset and treemanifests.
32292
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1689
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1690 `treemanifest` - used to indicate this is a tree manifest revlog. Opener
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1691 options can also be used to make this a tree manifest revlog. The opener
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1692 option takes precedence, so if it is set to True, we ignore whatever
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1693 value is passed in to the constructor.
31161
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1694 """
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1695 self.nodeconstants = nodeconstants
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1696 # During normal operations, we expect to deal with not more than four
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1697 # revs at a time (such as during commit --amend). When rebasing large
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1698 # stacks of commits, the number can go up, hence the config knob below.
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1699 cachesize = 4
32292
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1700 optiontreemanifest = False
51818
f0be60ed6242 manifest: align some vfs option access on the fact we might not have options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51817
diff changeset
1701 persistentnodemap = False
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1702 opts = getattr(opener, 'options', None)
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1703 if opts is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1704 cachesize = opts.get(b'manifestcachesize', cachesize)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1705 optiontreemanifest = opts.get(b'treemanifest', False)
51818
f0be60ed6242 manifest: align some vfs option access on the fact we might not have options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51817
diff changeset
1706 persistentnodemap = opts.get(b'persistent-nodemap', False)
29944
fa145a205a7f manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29943
diff changeset
1707
32292
d67991c4fefe treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents: 32240
diff changeset
1708 self._treeondisk = optiontreemanifest or treemanifest
29944
fa145a205a7f manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29943
diff changeset
1709
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1710 self._fulltextcache = manifestfulltextcache(cachesize)
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1711
39271
0d97530eb535 manifest: rename dir argument and attribute to tree
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39270
diff changeset
1712 if tree:
49234
b5858e02e3ba manifest: improve error message in case for tree manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49037
diff changeset
1713 assert self._treeondisk, (tree, b'opts is %r' % opts)
31161
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1714
47164
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47160
diff changeset
1715 radix = b'00manifest'
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47160
diff changeset
1716 if tree:
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47160
diff changeset
1717 radix = b"meta/" + tree + radix
31161
6d9f8bc2b5ea manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents: 31114
diff changeset
1718
39342
57c3864f3aad manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39341
diff changeset
1719 self.tree = tree
57c3864f3aad manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39341
diff changeset
1720
29945
1cc93a154723 manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29944
diff changeset
1721 # The dirlogcache is kept on the root manifest log
39271
0d97530eb535 manifest: rename dir argument and attribute to tree
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39270
diff changeset
1722 if tree:
29945
1cc93a154723 manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29944
diff changeset
1723 self._dirlogcache = dirlogcache
1cc93a154723 manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29944
diff changeset
1724 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1725 self._dirlogcache = {b'': self}
29944
fa145a205a7f manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29943
diff changeset
1726
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1727 self._revlog = revlog.revlog(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1728 opener,
47089
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47083
diff changeset
1729 target=(revlog_constants.KIND_MANIFESTLOG, self.tree),
47164
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47160
diff changeset
1730 radix=radix,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1731 # only root indexfile is cached
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1732 checkambig=not bool(tree),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1733 mmaplargeindex=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1734 upperboundcomp=MAXCOMPRESSION,
51818
f0be60ed6242 manifest: align some vfs option access on the fact we might not have options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51817
diff changeset
1735 persistentnodemap=persistentnodemap,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1736 )
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1737
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1738 self.index = self._revlog.index
29944
fa145a205a7f manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29943
diff changeset
1739
50667
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1740 def get_revlog(self):
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1741 """return an actual revlog instance if any
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1742
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1743 This exist because a lot of code leverage the fact the underlying
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1744 storage is a revlog for optimization, so giving simple way to access
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1745 the revlog instance helps such code.
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1746 """
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1747 return self._revlog
32837c7e2e4b revlog: add a `get_revlog` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50619
diff changeset
1748
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1749 def _setupmanifestcachehooks(self, repo):
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1750 """Persist the manifestfulltextcache on lock release"""
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50667
diff changeset
1751 if not hasattr(repo, '_wlockref'):
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1752 return
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1753
41970
e4ac7e63c213 manifestcache: use `wcache` directory for manifest cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41969
diff changeset
1754 self._fulltextcache._opener = repo.wcachevfs
41969
d121823072b8 manifestcache: protect write with `wlock` instead of `lock`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41967
diff changeset
1755 if repo._currentlock(repo._wlockref) is None:
41966
c3522b015f81 manifestcache: skip setup earlier if we don't have the lock
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41387
diff changeset
1756 return
c3522b015f81 manifestcache: skip setup earlier if we don't have the lock
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41387
diff changeset
1757
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1758 reporef = weakref.ref(repo)
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1759 manifestrevlogref = weakref.ref(self)
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1760
43798
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43571
diff changeset
1761 def persistmanifestcache(success):
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43571
diff changeset
1762 # Repo is in an unknown state, do not persist.
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43571
diff changeset
1763 if not success:
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43571
diff changeset
1764 return
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43571
diff changeset
1765
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1766 repo = reporef()
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1767 self = manifestrevlogref()
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1768 if repo is None or self is None:
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1769 return
39347
57301ba47e66 manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39344
diff changeset
1770 if repo.manifestlog.getstorage(b'') is not self:
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1771 # there's a different manifest in play now, abort
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1772 return
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1773 self._fulltextcache.write()
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1774
41966
c3522b015f81 manifestcache: skip setup earlier if we don't have the lock
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41387
diff changeset
1775 repo._afterlock(persistmanifestcache)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1776
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1777 @property
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1778 def fulltextcache(self):
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1779 return self._fulltextcache
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1780
51909
5e79783d4bc7 revlog: make `clearcaches()` signature consistent with ManifestRevlog
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
1781 def clearcaches(self, clear_persisted_data: bool = False) -> None:
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1782 self._revlog.clearcaches()
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
1783 self._fulltextcache.clear(clear_persisted_data=clear_persisted_data)
39342
57c3864f3aad manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39341
diff changeset
1784 self._dirlogcache = {self.tree: self}
29945
1cc93a154723 manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29944
diff changeset
1785
36133
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 35586
diff changeset
1786 def dirlog(self, d):
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 35586
diff changeset
1787 if d:
29945
1cc93a154723 manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents: 29944
diff changeset
1788 assert self._treeondisk
36133
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 35586
diff changeset
1789 if d not in self._dirlogcache:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1790 mfrevlog = manifestrevlog(
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1791 self.nodeconstants,
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1792 self.opener,
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1793 d,
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1794 self._dirlogcache,
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
1795 treemanifest=self._treeondisk,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1796 )
36133
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 35586
diff changeset
1797 self._dirlogcache[d] = mfrevlog
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 35586
diff changeset
1798 return self._dirlogcache[d]
29835
58d4ecdc531e manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents: 29834
diff changeset
1799
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1800 def add(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1801 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1802 m,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1803 transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1804 link,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1805 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1806 p2,
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1807 added: Iterable[bytes],
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
1808 removed: Iterable[bytes],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1809 readtree=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1810 match=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1811 ):
45067
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1812 """add some manifest entry in to the manifest log
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1813
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1814 input:
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1815
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1816 m: the manifest dict we want to store
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1817 transaction: the open transaction
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1818 p1: manifest-node of p1
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1819 p2: manifest-node of p2
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1820 added: file added/changed compared to parent
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1821 removed: file removed compared to parent
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1822
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1823 tree manifest input:
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1824
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1825 readtree: a function to read a subtree
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1826 match: a filematcher for the subpart of the tree manifest
5a80915e99ce commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44911
diff changeset
1827 """
44665
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1828 try:
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1829 if p1 not in self.fulltextcache:
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1830 raise FastdeltaUnavailable()
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1831 # If our first parent is in the manifest cache, we can
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1832 # compute a delta here using properties we know about the
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1833 # manifest up-front, which may save time later for the
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1834 # revlog layer.
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1835
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1836 _checkforbidden(added)
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1837 # combine the changed lists into one sorted iterator
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1838 work = heapq.merge(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1839 [(x, False) for x in sorted(added)],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1840 [(x, True) for x in sorted(removed)],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1841 )
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1842
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1843 arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work)
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1844 cachedelta = self._revlog.rev(p1), deltatext
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1845 text = util.buffer(arraytext)
46560
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1846 rev = self._revlog.addrevision(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1847 text, transaction, link, p1, p2, cachedelta
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1848 )
46560
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1849 n = self._revlog.node(rev)
44665
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1850 except FastdeltaUnavailable:
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1851 # The first parent manifest isn't already loaded or the
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1852 # manifest implementation doesn't support fastdelta, so
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1853 # we'll just encode a fulltext of the manifest and pass
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1854 # that through to the revlog layer, and let it handle the
948fac24bc39 manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents: 44386
diff changeset
1855 # delta process.
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1856 if self._treeondisk:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1857 assert readtree, b"readtree must be set for treemanifest writes"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1858 assert match, b"match must be specified for treemanifest writes"
39342
57c3864f3aad manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39341
diff changeset
1859 m1 = readtree(self.tree, p1)
57c3864f3aad manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39341
diff changeset
1860 m2 = readtree(self.tree, p2)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1861 n = self._addtree(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1862 m, transaction, link, m1, m2, readtree, match=match
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1863 )
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1864 arraytext = None
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1865 else:
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
1866 text = m.text()
46560
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1867 rev = self._revlog.addrevision(text, transaction, link, p1, p2)
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1868 n = self._revlog.node(rev)
31355
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31303
diff changeset
1869 arraytext = bytearray(text)
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1870
30209
9d06b65c5df2 manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents: 30207
diff changeset
1871 if arraytext is not None:
9d06b65c5df2 manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents: 30207
diff changeset
1872 self.fulltextcache[n] = arraytext
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1873
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1874 return n
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1875
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1876 def _addtree(self, m, transaction, link, m1, m2, readtree, match):
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1877 # If the manifest is unchanged compared to one parent,
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1878 # don't write a new revision
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1879 if self.tree != b'' and (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1880 m.unmodifiedsince(m1) or m.unmodifiedsince(m2)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1881 ):
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1882 return m.node()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1883
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1884 def writesubtree(subm, subp1, subp2, match):
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1885 sublog = self.dirlog(subm.dir())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1886 sublog.add(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1887 subm,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1888 transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1889 link,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1890 subp1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1891 subp2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1892 None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1893 None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1894 readtree=readtree,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1895 match=match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1896 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1897
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
1898 m.writesubtrees(m1, m2, writesubtree, match)
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
1899 text = m.dirtext()
31303
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1900 n = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1901 if self.tree != b'':
31303
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1902 # Double-check whether contents are unchanged to one parent
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
1903 if text == m1.dirtext():
31303
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1904 n = m1.node()
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
1905 elif text == m2.dirtext():
31303
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1906 n = m2.node()
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1907
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1908 if not n:
46560
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1909 rev = self._revlog.addrevision(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1910 text, transaction, link, m1.node(), m2.node()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1911 )
46560
f7b61ad3c64a revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents: 46445
diff changeset
1912 n = self._revlog.node(rev)
31303
c134a33b1d73 treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents: 31265
diff changeset
1913
29965
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1914 # Save nodeid so parent manifest can calculate its nodeid
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1915 m.setnode(n)
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1916 return n
774a15b129e8 manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents: 29964
diff changeset
1917
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1918 def __len__(self):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1919 return len(self._revlog)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1920
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1921 def __iter__(self):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1922 return self._revlog.__iter__()
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1923
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1924 def rev(self, node):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1925 return self._revlog.rev(node)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1926
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1927 def node(self, rev):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1928 return self._revlog.node(rev)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1929
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1930 def lookup(self, value):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1931 return self._revlog.lookup(value)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1932
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1933 def parentrevs(self, rev):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1934 return self._revlog.parentrevs(rev)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1935
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1936 def parents(self, node):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1937 return self._revlog.parents(node)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1938
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1939 def linkrev(self, rev):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1940 return self._revlog.linkrev(rev)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1941
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1942 def checksize(self):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1943 return self._revlog.checksize()
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1944
51027
33d2f0164d0d revlog: drop the df argument to `revision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
1945 def revision(self, node):
33d2f0164d0d revlog: drop the df argument to `revision`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
1946 return self._revlog.revision(node)
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1947
51028
14de15825253 revlog: drop the df argument to `rawdata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51027
diff changeset
1948 def rawdata(self, node):
14de15825253 revlog: drop the df argument to `rawdata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51027
diff changeset
1949 return self._revlog.rawdata(node)
42740
2128c76c8970 rawdata: forward `rawdata` call on `manifestlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42485
diff changeset
1950
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1951 def revdiff(self, rev1, rev2):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1952 return self._revlog.revdiff(rev1, rev2)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1953
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1954 def cmp(self, node, text):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1955 return self._revlog.cmp(node, text)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1956
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1957 def deltaparent(self, rev):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1958 return self._revlog.deltaparent(rev)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
1959
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1960 def emitrevisions(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1961 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1962 nodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1963 nodesorder=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1964 revisiondata=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1965 assumehaveparentrevisions=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1966 deltamode=repository.CG_DELTAMODE_STD,
46728
45f0d5297698 changegroupv4: add sidedata helpers
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46727
diff changeset
1967 sidedata_helpers=None,
49738
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49234
diff changeset
1968 debug_info=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1969 ):
39867
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39863
diff changeset
1970 return self._revlog.emitrevisions(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1971 nodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1972 nodesorder=nodesorder,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1973 revisiondata=revisiondata,
39867
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39863
diff changeset
1974 assumehaveparentrevisions=assumehaveparentrevisions,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1975 deltamode=deltamode,
46728
45f0d5297698 changegroupv4: add sidedata helpers
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46727
diff changeset
1976 sidedata_helpers=sidedata_helpers,
49738
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49234
diff changeset
1977 debug_info=debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1978 )
39867
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39863
diff changeset
1979
45811
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1980 def addgroup(
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1981 self,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1982 deltas,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1983 linkmapper,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1984 transaction,
46445
711ba0f1057e revlog: decouple caching from addrevision callback for addgroup
Joerg Sonnenberger <joerg@bec.de>
parents: 46247
diff changeset
1985 alwayscache=False,
45811
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1986 addrevisioncb=None,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1987 duplicaterevisioncb=None,
49739
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49738
diff changeset
1988 debug_info=None,
49877
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49739
diff changeset
1989 delta_base_reuse_policy=None,
45811
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1990 ):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
1991 return self._revlog.addgroup(
45811
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1992 deltas,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1993 linkmapper,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1994 transaction,
46445
711ba0f1057e revlog: decouple caching from addrevision callback for addgroup
Joerg Sonnenberger <joerg@bec.de>
parents: 46247
diff changeset
1995 alwayscache=alwayscache,
45811
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1996 addrevisioncb=addrevisioncb,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45253
diff changeset
1997 duplicaterevisioncb=duplicaterevisioncb,
49739
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49738
diff changeset
1998 debug_info=debug_info,
49877
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49739
diff changeset
1999 delta_base_reuse_policy=delta_base_reuse_policy,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2000 )
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2001
39863
9534fe1e5d28 manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39793
diff changeset
2002 def rawsize(self, rev):
9534fe1e5d28 manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39793
diff changeset
2003 return self._revlog.rawsize(rev)
9534fe1e5d28 manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39793
diff changeset
2004
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2005 def getstrippoint(self, minlink):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2006 return self._revlog.getstrippoint(minlink)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2007
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2008 def strip(self, minlink, transaction):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2009 return self._revlog.strip(minlink, transaction)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2010
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2011 def files(self):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2012 return self._revlog.files()
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2013
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2014 def clone(self, tr, destrevlog, **kwargs):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2015 if not isinstance(destrevlog, manifestrevlog):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2016 raise error.ProgrammingError(b'expected manifestrevlog to clone()')
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2017
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2018 return self._revlog.clone(tr, destrevlog._revlog, **kwargs)
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2019
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2020 def storageinfo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2021 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2022 exclusivefiles=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2023 sharedfiles=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2024 revisionscount=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2025 trackedsize=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2026 storedsize=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2027 ):
39874
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39871
diff changeset
2028 return self._revlog.storageinfo(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2029 exclusivefiles=exclusivefiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2030 sharedfiles=sharedfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2031 revisionscount=revisionscount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2032 trackedsize=trackedsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2033 storedsize=storedsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2034 )
39874
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39871
diff changeset
2035
39341
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2036 @property
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2037 def opener(self):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2038 return self._revlog.opener
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2039
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2040 @opener.setter
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2041 def opener(self, value):
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2042 self._revlog.opener = value
7f5e6d3e9032 manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39274
diff changeset
2043
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2044
52098
33f255bf19d9 manifest: drop the CamelCase name for `manifest.treemanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52097
diff changeset
2045 # TODO: drop this in favor of repository.imanifestrevisionstored?
33f255bf19d9 manifest: drop the CamelCase name for `manifest.treemanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52097
diff changeset
2046 AnyManifestCtx = Union['manifestctx', 'treemanifestctx']
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2047 # TODO: drop this in favor of repository.imanifestdict
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2048 AnyManifestDict = Union[manifestdict, treemanifest]
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2049
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2050
52513
d371efa7c358 manifest: subclass the new `repository.imanifestlog` Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 52510
diff changeset
2051 class manifestlog(repository.imanifestlog):
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2052 """A collection class representing the collection of manifest snapshots
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2053 referenced by commits in the repository.
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2054
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2055 In this situation, 'manifest' refers to the abstract concept of a snapshot
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2056 of the list of files in the given commit. Consumers of the output of this
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2057 class do not care about the implementation details of the actual manifests
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2058 they receive (i.e. tree or flat or lazily loaded, etc)."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2059
41041
3913223417ea manifest: accept narrowmatch into constructor instead of getting from repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 40496
diff changeset
2060 def __init__(self, opener, repo, rootstore, narrowmatch):
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2061 self.nodeconstants = repo.nodeconstants
29963
483003c27938 manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents: 29945
diff changeset
2062 usetreemanifest = False
30382
7c7d845f8b64 manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents: 30381
diff changeset
2063 cachesize = 4
29963
483003c27938 manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents: 29945
diff changeset
2064
483003c27938 manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents: 29945
diff changeset
2065 opts = getattr(opener, 'options', None)
483003c27938 manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents: 29945
diff changeset
2066 if opts is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2067 usetreemanifest = opts.get(b'treemanifest', usetreemanifest)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2068 cachesize = opts.get(b'manifestcachesize', cachesize)
39273
071f97d03acb manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
2069
071f97d03acb manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
2070 self._treemanifests = usetreemanifest
29963
483003c27938 manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents: 29945
diff changeset
2071
39779
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39684
diff changeset
2072 self._rootstore = rootstore
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2073 self._rootstore._setupmanifestcachehooks(repo)
41041
3913223417ea manifest: accept narrowmatch into constructor instead of getting from repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 40496
diff changeset
2074 self._narrowmatch = narrowmatch
30219
3c8811efdddc manifest: make manifestlog a storecache
Durham Goode <durham@fb.com>
parents: 30209
diff changeset
2075
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2076 # A cache of the manifestctx or treemanifestctx for each directory
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2077 self._dirmancache = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2078 self._dirmancache[b''] = util.lrucachedict(cachesize)
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2079
38514
561a450c7b64 manifest: make cachesize a private attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38340
diff changeset
2080 self._cachesize = cachesize
29837
93b44aa17691 manifest: use property instead of field for manifest revlog storage
Durham Goode <durham@fb.com>
parents: 29836
diff changeset
2081
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2082 def __getitem__(self, node):
30304
1a0c1ad57833 manifest: throw LookupError if node not in revlog
Durham Goode <durham@fb.com>
parents: 30221
diff changeset
2083 """Retrieves the manifest instance for the given node. Throws a
1a0c1ad57833 manifest: throw LookupError if node not in revlog
Durham Goode <durham@fb.com>
parents: 30221
diff changeset
2084 LookupError if not found.
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2085 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2086 return self.get(b'', node)
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2087
51837
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2088 @property
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2089 def narrowed(self):
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2090 return not (self._narrowmatch is None or self._narrowmatch.always())
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2091
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2092 def get(
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2093 self, tree: bytes, node: bytes, verify: bool = True
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2094 ) -> AnyManifestCtx:
30305
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2095 """Retrieves the manifest instance for the given node. Throws a
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2096 LookupError if not found.
30413
a431daa93f8c manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents: 30387
diff changeset
2097
a431daa93f8c manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents: 30387
diff changeset
2098 `verify` - if True an exception will be thrown if the node is not in
a431daa93f8c manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents: 30387
diff changeset
2099 the revlog
30305
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2100 """
39263
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2101 if node in self._dirmancache.get(tree, ()):
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2102 return self._dirmancache[tree][node]
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2103
37374
ac42e39b1b77 narrow: move manifestlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37373
diff changeset
2104 if not self._narrowmatch.always():
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
2105 if not self._narrowmatch.visitdir(tree[:-1]):
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2106 return excludeddirmanifestctx(self.nodeconstants, tree, node)
39263
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2107 if tree:
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2108 if self._rootstore._treeondisk:
30413
a431daa93f8c manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents: 30387
diff changeset
2109 if verify:
39274
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2110 # Side-effect is LookupError is raised if node doesn't
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2111 # exist.
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2112 self.getstorage(tree).rev(node)
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2113
39263
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2114 m = treemanifestctx(self, tree, node)
30305
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2115 else:
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2116 raise error.Abort(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2117 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2118 b"cannot ask for manifest directory '%s' in a flat "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2119 b"manifest"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2120 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2121 % tree
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2122 )
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2123 else:
30413
a431daa93f8c manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents: 30387
diff changeset
2124 if verify:
39274
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2125 # Side-effect is LookupError is raised if node doesn't exist.
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2126 self._rootstore.rev(node)
39274
61700d525a3b manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39273
diff changeset
2127
39273
071f97d03acb manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
2128 if self._treemanifests:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2129 m = treemanifestctx(self, b'', node)
30305
dc21ea3323c4 manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents: 30304
diff changeset
2130 else:
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2131 m = manifestctx(self, node)
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2132
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
2133 if node != self.nodeconstants.nullid:
39263
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2134 mancache = self._dirmancache.get(tree)
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2135 if not mancache:
38514
561a450c7b64 manifest: make cachesize a private attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38340
diff changeset
2136 mancache = util.lrucachedict(self._cachesize)
39263
43387fd2aa1f manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38821
diff changeset
2137 self._dirmancache[tree] = mancache
30306
d4b340bf68c5 manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents: 30305
diff changeset
2138 mancache[node] = m
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2139 return m
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2140
39272
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39271
diff changeset
2141 def getstorage(self, tree):
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2142 return self._rootstore.dirlog(tree)
39272
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39271
diff changeset
2143
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2144 def clearcaches(self, clear_persisted_data: bool = False) -> None:
30380
10c924596e5c manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents: 30379
diff changeset
2145 self._dirmancache.clear()
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2146 self._rootstore.clearcaches(clear_persisted_data=clear_persisted_data)
30380
10c924596e5c manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents: 30379
diff changeset
2147
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2148 def rev(self, node) -> int:
39348
52860f52ed13 manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39347
diff changeset
2149 return self._rootstore.rev(node)
38556
f2f9bacf0587 manifest: define and implement rev() on manifestlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38532
diff changeset
2150
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2151 def update_caches(self, transaction) -> None:
44864
97ebdb192b00 nodemap: also warm manifest nodemap with other caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44863
diff changeset
2152 return self._rootstore._revlog.update_caches(transaction=transaction)
97ebdb192b00 nodemap: also warm manifest nodemap with other caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44863
diff changeset
2153
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2154
52095
3f47f0d92b4a manifest: drop the CamelCase name for `manifest.memmanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52094
diff changeset
2155 class memmanifestctx: # (repository.imanifestrevisionwritable)
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2156 _manifestdict: manifestdict
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2157
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2158 def __init__(self, manifestlog):
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2159 self._manifestlog = manifestlog
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2160 self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen)
30352
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2161
52093
4675ab746a02 manifest: drop the CamelCase name for `manifest.manifestrevlog`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52092
diff changeset
2162 def _storage(self) -> manifestrevlog:
39347
57301ba47e66 manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39344
diff changeset
2163 return self._manifestlog.getstorage(b'')
30355
fa54f7ade491 manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents: 30353
diff changeset
2164
52095
3f47f0d92b4a manifest: drop the CamelCase name for `manifest.memmanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52094
diff changeset
2165 def copy(self) -> 'memmanifestctx':
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2166 memmf = memmanifestctx(self._manifestlog)
30353
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2167 memmf._manifestdict = self.read().copy()
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2168 return memmf
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2169
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2170 def read(self) -> 'manifestdict':
30352
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2171 return self._manifestdict
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2172
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
2173 def write(self, transaction, link, p1, p2, added, removed, match=None):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2174 return self._storage().add(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2175 self._manifestdict,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2176 transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2177 link,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2178 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2179 p2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2180 added,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2181 removed,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2182 match=match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2183 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2184
30355
fa54f7ade491 manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents: 30353
diff changeset
2185
52506
d37d8dfe65bd manifest: subclass the new `repository.imanifestrevisionstored` Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 52503
diff changeset
2186 class manifestctx(repository.imanifestrevisionstored):
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2187 """A class representing a single revision of a manifest, including its
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2188 contents, its parent revs, and its linkrev.
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2189 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2190
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2191 _data: Optional[manifestdict]
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2192
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2193 def __init__(self, manifestlog, node):
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2194 self._manifestlog = manifestlog
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2195 self._data = None
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2196
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2197 self._node = node
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2198
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2199 # TODO: We eventually want p1, p2, and linkrev exposed on this class,
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2200 # but let's add it later when something needs it and we can load it
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2201 # lazily.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2202 # self.p1, self.p2 = store.parents(node)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2203 # rev = store.rev(node)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2204 # self.linkrev = store.linkrev(rev)
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2205
52093
4675ab746a02 manifest: drop the CamelCase name for `manifest.manifestrevlog`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52092
diff changeset
2206 def _storage(self) -> 'manifestrevlog':
39347
57301ba47e66 manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39344
diff changeset
2207 return self._manifestlog.getstorage(b'')
30351
3dfb5a0171c9 manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents: 30350
diff changeset
2208
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2209 def node(self) -> bytes:
29836
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2210 return self._node
426d931e5db2 manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents: 29835
diff changeset
2211
52095
3f47f0d92b4a manifest: drop the CamelCase name for `manifest.memmanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52094
diff changeset
2212 def copy(self) -> memmanifestctx:
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2213 memmf = memmanifestctx(self._manifestlog)
30353
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2214 memmf._manifestdict = self.read().copy()
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2215 return memmf
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2216
30570
7fbc8a742b4d manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents: 30452
diff changeset
2217 @propertycache
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2218 def parents(self) -> Tuple[bytes, bytes]:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2219 return self._storage().parents(self._node)
30570
7fbc8a742b4d manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents: 30452
diff changeset
2220
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2221 def read(self) -> 'manifestdict':
31114
4a1486c73fdf manifest: check 'if x is None' instead of 'if not x'
Durham Goode <durham@fb.com>
parents: 30570
diff changeset
2222 if self._data is None:
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2223 nc = self._manifestlog.nodeconstants
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2224 if self._node == nc.nullid:
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2225 self._data = manifestdict(nc.nodelen)
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2226 else:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2227 store = self._storage()
39349
5886384d1ac5 manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39348
diff changeset
2228 if self._node in store.fulltextcache:
5886384d1ac5 manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39348
diff changeset
2229 text = pycompat.bytestr(store.fulltextcache[self._node])
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
2230 else:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2231 text = store.revision(self._node)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
2232 arraytext = bytearray(text)
39349
5886384d1ac5 manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39348
diff changeset
2233 store.fulltextcache[self._node] = arraytext
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2234 self._data = manifestdict(nc.nodelen, text)
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2235 return self._data
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2236
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2237 def readfast(self, shallow: bool = False) -> 'manifestdict':
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2238 """Calls either readdelta or read, based on which would be less work.
30308
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2239 readdelta is called if the delta is against the p1, and therefore can be
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2240 read quickly.
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2241
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2242 If `shallow` is True, nothing changes since this is a flat manifest.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2243 """
51840
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2244 util.nouideprecwarn(
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2245 b'"readfast" is deprecated use "read_any_fast_delta" or "read_delta_parents"',
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2246 b"6.9",
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2247 stacklevel=2,
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2248 )
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2249 store = self._storage()
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2250 r = store.rev(self._node)
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2251 deltaparent = store.deltaparent(r)
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2252 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
29943
80be4436e4cc manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents: 29942
diff changeset
2253 return self.readdelta()
80be4436e4cc manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents: 29942
diff changeset
2254 return self.read()
80be4436e4cc manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents: 29942
diff changeset
2255
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2256 def readdelta(self, shallow: bool = False) -> 'manifestdict':
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2257 """Returns a manifest containing just the entries that are present
30309
f65faa4422c8 manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents: 30308
diff changeset
2258 in this manifest, but not in its p1 manifest. This is efficient to read
f65faa4422c8 manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents: 30308
diff changeset
2259 if the revlog delta is already p1.
f65faa4422c8 manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents: 30308
diff changeset
2260
f65faa4422c8 manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents: 30308
diff changeset
2261 Changing the value of `shallow` has no effect on flat manifests.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2262 """
51840
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2263 util.nouideprecwarn(
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2264 b'"readfast" is deprecated use "read_any_fast_delta" or "read_delta_new_entries"',
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2265 b"6.9",
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2266 stacklevel=2,
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2267 )
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2268 store = self._storage()
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2269 r = store.rev(self._node)
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2270 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2271 return manifestdict(store.nodeconstants.nodelen, d)
29942
a059b17352ef manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents: 29930
diff changeset
2272
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2273 def read_any_fast_delta(
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2274 self,
51828
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2275 valid_bases: Optional[Collection[int]] = None,
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2276 *,
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2277 shallow: bool = False,
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2278 ) -> Tuple[Optional[int], manifestdict]:
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2279 """see `imanifestrevisionstored` documentation"""
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2280 store = self._storage()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2281 r = store.rev(self._node)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2282 deltaparent = store.deltaparent(r)
51828
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2283 if valid_bases is None:
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2284 # make sure the next check is True
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2285 valid_bases = (deltaparent,)
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2286 if deltaparent != nullrev and deltaparent in valid_bases:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2287 d = mdiff.patchtext(store.revdiff(deltaparent, r))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2288 return (
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2289 deltaparent,
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2290 manifestdict(store.nodeconstants.nodelen, d),
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2291 )
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2292 return (None, self.read())
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2293
51833
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2294 def read_delta_parents(
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2295 self,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2296 *,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2297 shallow: bool = False,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2298 exact: bool = True,
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2299 ) -> manifestdict:
51833
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2300 """see `interface.imanifestrevisionbase` documentations"""
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2301 store = self._storage()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2302 r = store.rev(self._node)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2303 deltaparent = store.deltaparent(r)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2304 parents = [p for p in store.parentrevs(r) if p is not nullrev]
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2305 if not exact and deltaparent in parents:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2306 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2307 return manifestdict(store.nodeconstants.nodelen, d)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2308 elif not exact or len(parents) == 0:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2309 return self.read()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2310 elif len(parents) == 1:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2311 p = parents[0]
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2312 d = mdiff.patchtext(store.revdiff(p, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2313 return manifestdict(store.nodeconstants.nodelen, d)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2314 else:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2315 p1, p2 = parents
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2316 d1 = mdiff.patchtext(store.revdiff(p1, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2317 d2 = mdiff.patchtext(store.revdiff(p2, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2318 d1 = manifestdict(store.nodeconstants.nodelen, d1)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2319 d2 = manifestdict(store.nodeconstants.nodelen, d2)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2320 md = manifestdict(store.nodeconstants.nodelen)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2321 for f, new_node, new_flag in d1.iterentries():
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2322 if f not in d2:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2323 continue
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2324 if new_node is not None:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2325 md.set(f, new_node, new_flag)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2326 return md
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2327
52503
048c11993d6a typing: (mostly) align the signatures of `imanifestrevisionstored` overrides
Matt Harbison <matt_harbison@yahoo.com>
parents: 52250
diff changeset
2328 def read_delta_new_entries(self, *, shallow: bool = False) -> manifestdict:
51837
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2329 """see `interface.imanifestrevisionbase` documentations"""
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2330 # If we are using narrow, returning a delta against an arbitrary
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2331 # changeset might return file outside the narrowspec. This can create
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2332 # issue when running validation server side with strict security as
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2333 # push from low priviledge usage might be seen as adding new revision
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2334 # for files they cannot touch. So we are strict if narrow is involved.
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2335 if self._manifestlog.narrowed:
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2336 return self.read_delta_parents(shallow=shallow, exact=True)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2337 store = self._storage()
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2338 r = store.rev(self._node)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2339 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2340 return manifestdict(store.nodeconstants.nodelen, d)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2341
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2342 def find(self, key: bytes) -> Tuple[bytes, bytes]:
30350
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30348
diff changeset
2343 return self.read().find(key)
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30348
diff changeset
2344
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2345
52510
22f97aa5e8b2 manifest: subclass the new `imanifestrevisionwritable` Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 52506
diff changeset
2346 class memtreemanifestctx(repository.imanifestrevisionwritable):
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2347 _treemanifest: treemanifest
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2348
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2349 def __init__(self, manifestlog, dir=b''):
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2350 self._manifestlog = manifestlog
30352
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2351 self._dir = dir
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2352 self._treemanifest = treemanifest(manifestlog.nodeconstants)
30352
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2353
52093
4675ab746a02 manifest: drop the CamelCase name for `manifest.manifestrevlog`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52092
diff changeset
2354 def _storage(self) -> manifestrevlog:
39347
57301ba47e66 manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39344
diff changeset
2355 return self._manifestlog.getstorage(b'')
30355
fa54f7ade491 manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents: 30353
diff changeset
2356
52097
569e074894fa manifest: drop the CamelCase name for `manifest.memtreemanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52096
diff changeset
2357 def copy(self) -> 'memtreemanifestctx':
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2358 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
30353
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2359 memmf._treemanifest = self._treemanifest.copy()
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2360 return memmf
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2361
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2362 def read(self) -> 'treemanifest':
30352
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2363 return self._treemanifest
fe1ee393de78 manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents: 30351
diff changeset
2364
39684
24870f1be088 narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents: 39539
diff changeset
2365 def write(self, transaction, link, p1, p2, added, removed, match=None):
30378
ed45283a0ca7 manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents: 30355
diff changeset
2366 def readtree(dir, node):
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2367 return self._manifestlog.get(dir, node).read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2368
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2369 return self._storage().add(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2370 self._treemanifest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2371 transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2372 link,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2373 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2374 p2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2375 added,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2376 removed,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2377 readtree=readtree,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2378 match=match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2379 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2380
30355
fa54f7ade491 manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents: 30353
diff changeset
2381
52506
d37d8dfe65bd manifest: subclass the new `repository.imanifestrevisionstored` Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 52503
diff changeset
2382 class treemanifestctx(repository.imanifestrevisionstored):
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2383 _data: Optional[treemanifest]
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2384
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2385 def __init__(self, manifestlog, dir, node):
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2386 self._manifestlog = manifestlog
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2387 self._dir = dir
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2388 self._data = None
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2389
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2390 self._node = node
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2391
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2392 # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2393 # we can instantiate treemanifestctx objects for directories we don't
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2394 # have on disk.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2395 # self.p1, self.p2 = store.parents(node)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2396 # rev = store.rev(node)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2397 # self.linkrev = store.linkrev(rev)
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2398
52093
4675ab746a02 manifest: drop the CamelCase name for `manifest.manifestrevlog`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52092
diff changeset
2399 def _storage(self) -> manifestrevlog:
37373
c50078fc32f3 narrow: move manifestrevlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37372
diff changeset
2400 narrowmatch = self._manifestlog._narrowmatch
c50078fc32f3 narrow: move manifestrevlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37372
diff changeset
2401 if not narrowmatch.always():
42363
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41970
diff changeset
2402 if not narrowmatch.visitdir(self._dir[:-1]):
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2403 return excludedmanifestrevlog(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2404 self._manifestlog.nodeconstants, self._dir
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2405 )
39272
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39271
diff changeset
2406 return self._manifestlog.getstorage(self._dir)
30221
f2c5b9d48b29 manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents: 30220
diff changeset
2407
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2408 def read(self) -> 'treemanifest':
31114
4a1486c73fdf manifest: check 'if x is None' instead of 'if not x'
Durham Goode <durham@fb.com>
parents: 30570
diff changeset
2409 if self._data is None:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2410 store = self._storage()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
2411 if self._node == self._manifestlog.nodeconstants.nullid:
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2412 self._data = treemanifest(self._manifestlog.nodeconstants)
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2413 # TODO accessing non-public API
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2414 elif store._treeondisk:
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2415 m = treemanifest(self._manifestlog.nodeconstants, dir=self._dir)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2416
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2417 def gettext():
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2418 return store.revision(self._node)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2419
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2420 def readsubtree(dir, subm):
30414
a1beadaa4061 manifest: change treemanifestctx to construct subtrees from the manifestlog
Durham Goode <durham@fb.com>
parents: 30413
diff changeset
2421 # Set verify to False since we need to be able to create
a1beadaa4061 manifest: change treemanifestctx to construct subtrees from the manifestlog
Durham Goode <durham@fb.com>
parents: 30413
diff changeset
2422 # subtrees for trees that don't exist on disk.
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2423 return self._manifestlog.get(dir, subm, verify=False).read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2424
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2425 m.read(gettext, readsubtree)
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2426 m.setnode(self._node)
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2427 self._data = m
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2428 else:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2429 if self._node in store.fulltextcache:
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2430 text = pycompat.bytestr(store.fulltextcache[self._node])
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
2431 else:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2432 text = store.revision(self._node)
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38657
diff changeset
2433 arraytext = bytearray(text)
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2434 store.fulltextcache[self._node] = arraytext
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2435 self._data = treemanifest(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2436 self._manifestlog.nodeconstants, dir=self._dir, text=text
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2437 )
29930
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2438
be16091ac14d manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents: 29920
diff changeset
2439 return self._data
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2440
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2441 def node(self) -> bytes:
29911
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2442 return self._node
4fb4fc331699 manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents: 29892
diff changeset
2443
52097
569e074894fa manifest: drop the CamelCase name for `manifest.memtreemanifestctx`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52096
diff changeset
2444 def copy(self) -> 'memtreemanifestctx':
31163
5cab44fd1257 manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents: 31161
diff changeset
2445 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
30353
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2446 memmf._treemanifest = self.read().copy()
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2447 return memmf
952e1916ae56 manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents: 30352
diff changeset
2448
30570
7fbc8a742b4d manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents: 30452
diff changeset
2449 @propertycache
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2450 def parents(self) -> Tuple[bytes, bytes]:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2451 return self._storage().parents(self._node)
30570
7fbc8a742b4d manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents: 30452
diff changeset
2452
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2453 def readdelta(self, shallow: bool = False) -> AnyManifestDict:
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2454 """see `imanifestrevisionstored` documentation"""
51840
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2455 util.nouideprecwarn(
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2456 b'"readdelta" is deprecated use "read_any_fast_delta" or "read_delta_new_entries"',
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2457 b"6.9",
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2458 stacklevel=2,
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2459 )
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2460 store = self._storage()
36404
0147a4730420 cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents: 36334
diff changeset
2461 if shallow:
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2462 r = store.rev(self._node)
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2463 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2464 return manifestdict(store.nodeconstants.nodelen, d)
30307
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2465 else:
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2466 # Need to perform a slow delta
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2467 r0 = store.deltaparent(store.rev(self._node))
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2468 m0 = self._manifestlog.get(self._dir, store.node(r0)).read()
30307
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2469 m1 = self.read()
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2470 md = treemanifest(self._manifestlog.nodeconstants, dir=self._dir)
49017
3d35e7483602 manifest: remove pycompat.iteritems()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
2471 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).items():
30307
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2472 if n1:
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2473 md[f] = n1
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2474 if fl1:
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2475 md.setflag(f, fl1)
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2476 return md
29942
a059b17352ef manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents: 29930
diff changeset
2477
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2478 def read_any_fast_delta(
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2479 self,
51828
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2480 valid_bases: Optional[Collection[int]] = None,
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2481 *,
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2482 shallow: bool = False,
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2483 ) -> Tuple[Optional[int], AnyManifestDict]:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2484 """see `imanifestrevisionstored` documentation"""
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2485 store = self._storage()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2486 r = store.rev(self._node)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2487 deltaparent = store.deltaparent(r)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2488
51828
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2489 if valid_bases is None:
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2490 # make sure the next check is True
e1fd715df257 manifest: allow skipping valid_bases argument to `read_any_fast_delta`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51827
diff changeset
2491 valid_bases = (deltaparent,)
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2492 can_use_delta = deltaparent != nullrev and deltaparent in valid_bases
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2493
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2494 if shallow:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2495 if can_use_delta:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2496 return (deltaparent, self._read_storage_delta_shallow())
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2497 else:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2498 d = store.revision(self._node)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2499 return (None, manifestdict(store.nodeconstants.nodelen, d))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2500 else:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2501 # note: This use "slow_delta" here is cargo culted from the previous
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2502 # implementation. I am not sure it make sense since the goal here is to
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2503 # be fast, so why are we computing a delta? On the other hand, tree
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2504 # manifest delta as fairly "cheap" and allow for skipping whole part of
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2505 # the tree that a full read would access. So it might be a good idea.
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2506 #
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2507 # If we realize we don't need delta here, we should simply use:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2508 #
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2509 # return (None, self.read())
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2510 if can_use_delta:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2511 return (None, self._read_storage_slow_delta(base=deltaparent))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2512 else:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2513 parents = [
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2514 p
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2515 for p in store.parentrevs(r)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2516 if p is not nullrev and p in valid_bases
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2517 ]
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2518 if parents:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2519 best_base = max(parents)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2520 else:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2521 best_base = max(valid_bases)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2522 return (None, self._read_storage_slow_delta(base=best_base))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2523
52091
35400ce47b64 manifest: drop the CamelCase name for `manifest.manifestdict`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51909
diff changeset
2524 def _read_storage_delta_shallow(self) -> manifestdict:
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2525 store = self._storage()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2526 r = store.rev(self._node)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2527 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2528 return manifestdict(store.nodeconstants.nodelen, d)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2529
52092
c392d57e8a06 manifest: drop the CamelCase name for `manifest.treemanifest`
Matt Harbison <matt_harbison@yahoo.com>
parents: 52091
diff changeset
2530 def _read_storage_slow_delta(self, base) -> 'treemanifest':
51827
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2531 store = self._storage()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2532 if base is None:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2533 base = store.deltaparent(store.rev(self._node))
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2534 m0 = self._manifestlog.get(self._dir, store.node(base)).read()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2535 m1 = self.read()
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2536 md = treemanifest(self._manifestlog.nodeconstants, dir=self._dir)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2537 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).items():
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2538 if n1:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2539 md[f] = n1
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2540 if fl1:
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2541 md.setflag(f, fl1)
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2542 return md
ca4208713875 manifest: introduce a `read_any_fast_delta` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51826
diff changeset
2543
51833
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2544 def read_delta_parents(
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2545 self,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2546 *,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2547 shallow: bool = False,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2548 exact: bool = True,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2549 ) -> AnyManifestDict:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2550 """see `interface.imanifestrevisionbase` documentations"""
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2551 store = self._storage()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2552 r = store.rev(self._node)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2553 parents = [p for p in store.parentrevs(r) if p is not nullrev]
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2554 if not exact:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2555 return self.read_any_fast_delta(parents, shallow=shallow)[1]
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2556 elif len(parents) == 0:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2557 if shallow:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2558 d = store.revision(self._node)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2559 return manifestdict(store.nodeconstants.nodelen, d)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2560 else:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2561 return self.read()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2562 elif len(parents) == 1:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2563 p = parents[0]
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2564 if shallow:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2565 d = mdiff.patchtext(store.revdiff(p, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2566 return manifestdict(store.nodeconstants.nodelen, d)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2567 else:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2568 return self._read_storage_slow_delta(base=p)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2569 else:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2570 p1, p2 = parents
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2571 if shallow:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2572 d1 = mdiff.patchtext(store.revdiff(p1, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2573 d2 = mdiff.patchtext(store.revdiff(p2, r))
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2574 d1 = manifestdict(store.nodeconstants.nodelen, d1)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2575 d2 = manifestdict(store.nodeconstants.nodelen, d2)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2576 md = manifestdict(store.nodeconstants.nodelen)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2577 for f, new_node, new_flag in d1.iterentries():
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2578 if f not in d2:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2579 continue
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2580 if new_node is not None:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2581 md.set(f, new_node, new_flag)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2582 return md
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2583 else:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2584 m1 = self._manifestlog.get(self._dir, store.node(p1)).read()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2585 m2 = self._manifestlog.get(self._dir, store.node(p2)).read()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2586 mc = self.read()
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2587 d1 = m1.diff(mc)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2588 d2 = m2.diff(mc)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2589 md = treemanifest(
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2590 self._manifestlog.nodeconstants,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2591 dir=self._dir,
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2592 )
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2593 for f, new_node, new_flag in d1.iterentries():
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2594 if f not in d2:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2595 continue
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2596 if new_node is not None:
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2597 md.set(f, new_node, new_flag)
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2598 return md
a891347058e7 manifest: introduce a `read_delta_parents` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51828
diff changeset
2599
51837
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2600 def read_delta_new_entries(
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2601 self, *, shallow: bool = False
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2602 ) -> AnyManifestDict:
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2603 """see `interface.imanifestrevisionbase` documentations"""
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2604 # If we are using narrow, returning a delta against an arbitrary
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2605 # changeset might return file outside the narrowspec. This can create
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2606 # issue when running validation server side with strict security as
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2607 # push from low priviledge usage might be seen as adding new revision
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2608 # for files they cannot touch. So we are strict if narrow is involved.
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2609 if self._manifestlog.narrowed:
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2610 return self.read_delta_parents(shallow=shallow, exact=True)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2611 # delegate to existing another existing method for simplicity
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2612 store = self._storage()
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2613 r = store.rev(self._node)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2614 bases = (store.deltaparent(r),)
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2615 return self.read_any_fast_delta(bases, shallow=shallow)[1]
bcb825bf0c5e manifest: add a read_delta_new_entries method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51833
diff changeset
2616
52503
048c11993d6a typing: (mostly) align the signatures of `imanifestrevisionstored` overrides
Matt Harbison <matt_harbison@yahoo.com>
parents: 52250
diff changeset
2617 def readfast(self, shallow: bool = False) -> AnyManifestDict:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2618 """Calls either readdelta or read, based on which would be less work.
30308
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2619 readdelta is called if the delta is against the p1, and therefore can be
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2620 read quickly.
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2621
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2622 If `shallow` is True, it only returns the entries from this manifest,
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30307
diff changeset
2623 and not any submanifests.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45811
diff changeset
2624 """
51840
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2625 util.nouideprecwarn(
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2626 b'"readdelta" is deprecated use "read_any_fast_delta" or "read_delta_parents"',
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2627 b"6.9",
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2628 stacklevel=2,
9af1acc1ffab manifest: deprecated readdelta and readfast
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51837
diff changeset
2629 )
39344
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2630 store = self._storage()
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2631 r = store.rev(self._node)
eb9b8679c852 manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39343
diff changeset
2632 deltaparent = store.deltaparent(r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2633 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
30307
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2634 return self.readdelta(shallow=shallow)
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2635
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2636 if shallow:
47083
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2637 return manifestdict(
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2638 store.nodeconstants.nodelen, store.revision(self._node)
12450fbea288 manifests: push down expected node length into the parser
Joerg Sonnenberger <joerg@bec.de>
parents: 47055
diff changeset
2639 )
30307
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2640 else:
78f3c7166f0d manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents: 30306
diff changeset
2641 return self.read()
29943
80be4436e4cc manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents: 29942
diff changeset
2642
51826
79e0ee356f32 manifest: add many type annotations to the manifest module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51825
diff changeset
2643 def find(self, key: bytes) -> Tuple[bytes, bytes]:
30350
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30348
diff changeset
2644 return self.read().find(key)
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2645
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2646
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2647 class excludeddir(treemanifest):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2648 """Stand-in for a directory that is excluded from the repository.
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2649
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2650 With narrowing active on a repository that uses treemanifests,
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2651 some of the directory revlogs will be excluded from the resulting
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2652 clone. This is a huge storage win for clients, but means we need
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2653 some sort of pseudo-manifest to surface to internals so we can
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2654 detect a merge conflict outside the narrowspec. That's what this
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2655 class is: it stands in for a directory whose node is known, but
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2656 whose contents are unknown.
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2657 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2658
51868
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2659 _files: Dict[bytes, bytes]
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2660 _flags: Dict[bytes, bytes]
0338fb200a30 typing: lock in new pytype gains from making revlog related classes typeable
Matt Harbison <matt_harbison@yahoo.com>
parents: 51865
diff changeset
2661
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2662 def __init__(self, nodeconstants, dir, node):
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 52665
diff changeset
2663 super().__init__(nodeconstants, dir)
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2664 self._node = node
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2665 # Add an empty file, which will be included by iterators and such,
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2666 # appearing as the directory itself (i.e. something like "dir/")
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2667 self._files[b''] = node
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2668 self._flags[b''] = b't'
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2669
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2670 # Manifests outside the narrowspec should never be modified, so avoid
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2671 # copying. This makes a noticeable difference when there are very many
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2672 # directories outside the narrowspec. Also, it makes sense for the copy to
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2673 # be of the same type as the original, which would not happen with the
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2674 # super type's copy().
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2675 def copy(self):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2676 return self
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2677
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2678
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2679 class excludeddirmanifestctx(treemanifestctx):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2680 """context wrapper for excludeddir - see that docstring for rationale"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2681
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2682 def __init__(self, nodeconstants, dir, node):
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2683 self.nodeconstants = nodeconstants
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2684 self._dir = dir
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2685 self._node = node
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2686
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2687 def read(self):
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2688 return excludeddir(self.nodeconstants, self._dir, self._node)
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2689
52503
048c11993d6a typing: (mostly) align the signatures of `imanifestrevisionstored` overrides
Matt Harbison <matt_harbison@yahoo.com>
parents: 52250
diff changeset
2690 def readfast(self, shallow: bool = False):
46247
a3ccbac659d8 narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46096
diff changeset
2691 # special version of readfast since we don't have underlying storage
a3ccbac659d8 narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46096
diff changeset
2692 return self.read()
a3ccbac659d8 narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46096
diff changeset
2693
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2694 def write(self, *args):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2695 raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2696 b'attempt to write manifest from excluded dir %s' % self._dir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2697 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2698
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2699
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2700 class excludedmanifestrevlog(manifestrevlog):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2701 """Stand-in for excluded treemanifest revlogs.
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2702
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2703 When narrowing is active on a treemanifest repository, we'll have
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2704 references to directories we can't see due to the revlog being
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2705 skipped. This class exists to conform to the manifestrevlog
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2706 interface for those directories and proactively prevent writes to
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2707 outside the narrowspec.
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2708 """
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2709
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2710 def __init__(self, nodeconstants, dir):
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46728
diff changeset
2711 self.nodeconstants = nodeconstants
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2712 self._dir = dir
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2713
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2714 def __len__(self):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2715 raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2716 b'attempt to get length of excluded dir %s' % self._dir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2717 )
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2718
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2719 def rev(self, node):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2720 raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2721 b'attempt to get rev from excluded dir %s' % self._dir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2722 )
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2723
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2724 def linkrev(self, node):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2725 raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2726 b'attempt to get linkrev from excluded dir %s' % self._dir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2727 )
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2728
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2729 def node(self, rev):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2730 raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2731 b'attempt to get node from excluded dir %s' % self._dir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42824
diff changeset
2732 )
37372
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2733
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2734 def add(self, *args, **kwargs):
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2735 # We should never write entries in dirlogs outside the narrow clone.
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2736 # However, the method still gets called from writesubtree() in
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2737 # _addtree(), so we need to handle it. We should possibly make that
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2738 # avoid calling add() with a clean manifest (_dirty is always False
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2739 # in excludeddir instances).
1b2fa531fd7a narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2740 pass