Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/manifest.py @ 47055:d55b71393907
node: replace nullid and friends with nodeconstants class
The introduction of 256bit hashes require changes to nullid and other
constant magic values. Start pushing them down from repository and
revlog where sensible.
Differential Revision: https://phab.mercurial-scm.org/D9465
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Mon, 29 Mar 2021 01:52:06 +0200 |
parents | d4ba4d51f85f |
children | 12450fbea288 |
rev | line source |
---|---|
1089 | 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 | 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 |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
8 from __future__ import absolute_import |
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 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
13 import weakref |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
14 |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
15 from .i18n import _ |
31536
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
16 from .node import ( |
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
17 bin, |
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
18 hex, |
39343
53363a8eff57
manifest: don't go through revlog to access node symbols
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39342
diff
changeset
|
19 nullrev, |
31536
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
20 ) |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
21 from .pycompat import getattr |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
22 from . import ( |
44164
c443b9ba6f63
py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents:
43798
diff
changeset
|
23 encoding, |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
24 error, |
44332
bbecb6d80aa7
manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents:
44331
diff
changeset
|
25 match as matchmod, |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
26 mdiff, |
43571
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43554
diff
changeset
|
27 pathutil, |
32411
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
32292
diff
changeset
|
28 policy, |
38340
cf59de802883
py3: remove b'' from error message of disallowed filename
Yuya Nishihara <yuya@tcha.org>
parents:
37374
diff
changeset
|
29 pycompat, |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
30 revlog, |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
31 util, |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
32 ) |
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
|
33 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
|
34 repository, |
42824
2c4f656c8e9f
interfaceutil: move to interfaces/
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42823
diff
changeset
|
35 util as interfaceutil, |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
36 ) |
79 | 37 |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43346
diff
changeset
|
38 parsers = policy.importmod('parsers') |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
39 propertycache = util.propertycache |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
40 |
42170
89c0c8edc9d4
tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents:
41970
diff
changeset
|
41 # 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
|
42 FASTDELTA_TEXTDIFF_THRESHOLD = 1000 |
89c0c8edc9d4
tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents:
41970
diff
changeset
|
43 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
44 |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
45 def _parse(data): |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
46 # 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
|
47 # 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
|
48 # 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
|
49 # 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
|
50 # the pure version. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 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
|
52 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
|
53 prev = None |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
54 for l in data.splitlines(): |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
55 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
|
56 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
|
57 prev = l |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 nl -= 1 |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
64 else: |
45119
19748c73c208
manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents:
45118
diff
changeset
|
65 flags = b'' |
19748c73c208
manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents:
45118
diff
changeset
|
66 if nl not in (40, 64): |
19748c73c208
manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents:
45118
diff
changeset
|
67 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
|
68 |
19748c73c208
manifest: use the same logic for handling flags in _parse as elsewhere
Joerg Sonnenberger <joerg@bec.de>
parents:
45118
diff
changeset
|
69 yield f, bin(n), flags |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
70 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
71 |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
72 def _text(it): |
24525
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
73 files = [] |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
74 lines = [] |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
75 for f, n, fl in it: |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
76 files.append(f) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
77 # 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
|
78 # 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
|
79 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
|
80 |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
81 _checkforbidden(files) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 return b''.join(lines) |
24525
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
83 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
84 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
85 class lazymanifestiter(object): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
86 def __init__(self, lm): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
87 self.pos = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
88 self.lm = lm |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
89 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
90 def __iter__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
91 return self |
24223
b4df0d0c49e7
manifest: move parsing functions up in file
Augie Fackler <augie@google.com>
parents:
24215
diff
changeset
|
92 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
93 def next(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
94 try: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
95 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
|
96 except IndexError: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
97 raise StopIteration |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
98 if pos == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
99 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
100 return data[0] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
101 self.pos += 1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 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
|
103 return data[pos:zeropos] |
24224
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
104 |
31373
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
105 __next__ = next |
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
106 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
107 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
108 class lazymanifestiterentries(object): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
109 def __init__(self, lm): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
110 self.lm = lm |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
111 self.pos = 0 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
112 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
113 def __iter__(self): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
114 return self |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
115 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
116 def next(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
117 try: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
118 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
|
119 except IndexError: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
120 raise StopIteration |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
121 if pos == -1: |
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 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
124 zeropos = data.find(b'\x00', pos) |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
125 nlpos = data.find(b'\n', pos) |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
126 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
|
127 raise error.StorageError(b'Invalid manifest line') |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
128 flags = data[nlpos - 1 : nlpos] |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
129 if flags in _manifestflags: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
130 hlen = nlpos - zeropos - 2 |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
131 else: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
132 hlen = nlpos - zeropos - 1 |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
133 flags = b'' |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
134 if hlen not in (40, 64): |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
135 raise error.StorageError(b'Invalid manifest line') |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
136 hashval = unhexlify( |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
137 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
|
138 ) |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
139 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
140 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
|
141 |
31373
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
142 __next__ = next |
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
143 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
144 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
145 def unhexlify(data, extra, pos, length): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
146 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
|
147 if extra: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
148 s += chr(extra & 0xFF) |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
149 return s |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
150 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
151 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
152 def _cmp(a, b): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
153 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
|
154 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
155 |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
156 _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
|
157 |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
158 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
159 class _lazymanifest(object): |
42172
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
160 """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
|
161 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
|
162 string. |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
163 |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
164 ``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
|
165 |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
166 ``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
|
167 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
|
168 ``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
|
169 ``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
|
170 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
|
171 sorted by filename. |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
172 |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
173 ``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
|
174 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
|
175 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
176 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
177 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
178 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
179 data, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
180 positions=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
181 extrainfo=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
182 extradata=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
183 hasremovals=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
184 ): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
185 if positions is None: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
186 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
|
187 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
|
188 self.data = data |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
189 self.extradata = [] |
42171
0546ead39a7e
manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents:
42170
diff
changeset
|
190 self.hasremovals = False |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
191 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
192 self.positions = positions[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
193 self.extrainfo = extrainfo[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
194 self.extradata = extradata[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
195 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
|
196 self.hasremovals = hasremovals |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
197 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
198 def findlines(self, data): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
199 if not data: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
200 return [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 pos = data.find(b"\n") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 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
|
203 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
|
204 positions = [0] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 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
|
206 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
|
207 positions.append(pos + 1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 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
|
209 if nexts < prev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
210 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
|
211 prev = nexts |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
212 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
|
213 return positions |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
214 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
215 def _get(self, index): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
216 # 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
|
217 # 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
|
218 # 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
|
219 pos = self.positions[index] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
220 if pos >= 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
221 return self.data, pos |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
222 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
|
223 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
224 def _getkey(self, pos): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
225 if pos >= 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
226 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
|
227 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
|
228 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
229 def bsearch(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
230 first = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
231 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
|
232 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
233 while first <= last: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
234 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
|
235 nextpos = self.positions[midpoint] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
236 candidate = self._getkey(nextpos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
237 r = _cmp(key, candidate) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
238 if r == 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
239 return midpoint |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
240 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
241 if r < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
242 last = midpoint - 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
243 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
244 first = midpoint + 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
245 return -1 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
246 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
247 def bsearch2(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
248 # 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
|
249 # done for performance reasons |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
250 first = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
251 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
|
252 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
253 while first <= last: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
254 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
|
255 nextpos = self.positions[midpoint] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
256 candidate = self._getkey(nextpos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
257 r = _cmp(key, candidate) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
258 if r == 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
259 return (midpoint, True) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
260 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
261 if r < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
262 last = midpoint - 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
263 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
264 first = midpoint + 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
265 return (first, False) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
266 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
267 def __contains__(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
268 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
|
269 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
270 def __getitem__(self, key): |
31376
ef50b491c17d
manifest: ensure paths are bytes (not str) in pure parser
Augie Fackler <augie@google.com>
parents:
31375
diff
changeset
|
271 if not isinstance(key, bytes): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
272 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
|
273 needle = self.bsearch(key) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
274 if needle == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
275 raise KeyError |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
276 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
|
277 if pos == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
278 return (data[1], data[2]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 hlen = nlpos - zeropos - 1 |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
286 flags = data[nlpos - 1 : nlpos] |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
287 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
|
288 hlen -= 1 |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
289 else: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
290 flags = b'' |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
291 if hlen not in (40, 64): |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
292 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
|
293 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
|
294 return (hashval, flags) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
295 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
296 def __delitem__(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
297 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
|
298 if not found: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
299 raise KeyError |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
300 cur = self.positions[needle] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
301 self.positions = self.positions[:needle] + self.positions[needle + 1 :] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
302 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
|
303 if cur >= 0: |
42172
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
304 # 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
|
305 # 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
|
306 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
|
307 self.hasremovals = True |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
308 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
309 def __setitem__(self, key, value): |
31537
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
310 if not isinstance(key, bytes): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
311 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
|
312 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
|
313 raise TypeError( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 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
|
315 ) |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 flags = value[1] |
31537
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 if found: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
324 # put the item |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
325 pos = self.positions[needle] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
326 if pos < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
327 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
|
328 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
329 # just don't bother |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
330 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
|
331 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
|
332 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
333 # 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
|
334 self.extradata.append((key, hashval, value[1])) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
335 self.positions = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
336 self.positions[:needle] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
337 + [-len(self.extradata)] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
338 + self.positions[needle:] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
339 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
340 self.extrainfo = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
341 self.extrainfo[:needle] + [0] + self.extrainfo[needle:] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
342 ) |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
343 |
2831 | 344 def copy(self): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
345 # XXX call _compact like in C? |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
346 return _lazymanifest( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
347 self.data, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
348 self.positions, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
349 self.extrainfo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
350 self.extradata, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
351 self.hasremovals, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
352 ) |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
353 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
354 def _compact(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
355 # 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
|
356 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
|
357 return |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
358 l = [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
359 i = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
360 offset = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 cur = self.positions[i] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
365 last_cut = cur |
42172
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
366 |
c3484ddbdb96
manifest: add some documentation to _lazymanifest python code
Matt Harbison <matt_harbison@yahoo.com>
parents:
42171
diff
changeset
|
367 # 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
|
368 # 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
|
369 # 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
|
370 while True: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
371 self.positions[i] = offset |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
372 i += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
373 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
|
374 break |
42171
0546ead39a7e
manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents:
42170
diff
changeset
|
375 |
0546ead39a7e
manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents:
42170
diff
changeset
|
376 # 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
|
377 # 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
|
378 # 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
|
379 # before the next position. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
380 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
381 self.hasremovals |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
382 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
|
383 != -1 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
384 ): |
42171
0546ead39a7e
manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents:
42170
diff
changeset
|
385 break |
0546ead39a7e
manifest: avoid corruption by dropping removed files with pure (issue5801)
Matt Harbison <matt_harbison@yahoo.com>
parents:
42170
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 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
|
388 cur = self.positions[i] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
389 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
|
390 if end_cut != -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
391 end_cut += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
392 offset += end_cut - cur |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
393 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
|
394 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
395 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
|
396 cur = self.positions[i] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
397 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
|
398 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
|
399 self.positions[i] = offset |
44704
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
400 # 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
|
401 # bytes (new non-sha1). |
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
402 hlen = 20 |
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
403 if len(t[1]) > 25: |
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
404 hlen = 32 |
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
405 if len(t[1]) > hlen: |
0415a566742a
manifest: fix another pure-parsing 20-byte assumption
Augie Fackler <augie@google.com>
parents:
44703
diff
changeset
|
406 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
|
407 offset += len(l[-1]) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
408 i += 1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
409 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
|
410 self.hasremovals = False |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
411 self.extradata = [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
412 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
413 def _pack(self, d): |
44701
ecbba7b2e444
manifest: remove a 20-byte-hash assumption from pure manifest parsing
Augie Fackler <augie@google.com>
parents:
44666
diff
changeset
|
414 n = d[1] |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
415 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
|
416 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
|
417 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
418 def text(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
419 self._compact() |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
420 return self.data |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
421 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
422 def diff(self, m2, clean=False): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
423 '''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
|
424 # 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
|
425 diff = {} |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
426 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
427 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
|
428 if fn not in m2: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
429 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
|
430 else: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
431 e2 = m2[fn] |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
432 if (e1, flags) != e2: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
433 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
|
434 elif clean: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
435 diff[fn] = None |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
436 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
437 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
|
438 if fn not in self: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
439 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
|
440 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
441 return diff |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
442 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
443 def iterentries(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
444 return lazymanifestiterentries(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
445 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
446 def iterkeys(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
447 return lazymanifestiter(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
448 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
449 def __iter__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
450 return lazymanifestiter(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
451 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
452 def __len__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
453 return len(self.positions) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
454 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
455 def filtercopy(self, filterfn): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
456 # XXX should be optimized |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
457 c = _lazymanifest(b'') |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
458 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
|
459 if filterfn(f): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
460 c[f] = n, fl |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
461 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
462 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
463 |
24226
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
464 try: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
465 _lazymanifest = parsers.lazymanifest |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
466 except AttributeError: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
467 pass |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
468 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
469 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
470 @interfaceutil.implementer(repository.imanifestdict) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
471 class manifestdict(object): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
472 def __init__(self, data=b''): |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
473 self._lm = _lazymanifest(data) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
474 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
475 def __getitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
476 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
|
477 |
24277
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
478 def find(self, key): |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
479 return self._lm[key] |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
480 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
481 def __len__(self): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
482 return len(self._lm) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
483 |
30341
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
484 def __nonzero__(self): |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
485 # 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
|
486 # makes it easier for extensions to override. |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
487 return len(self._lm) != 0 |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
488 |
31483
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31376
diff
changeset
|
489 __bool__ = __nonzero__ |
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31376
diff
changeset
|
490 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
491 def __setitem__(self, key, node): |
44304
dbbae122f5e4
manifest: remove optional default= argument on flags(path)
Augie Fackler <augie@google.com>
parents:
43798
diff
changeset
|
492 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
|
493 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
494 def __contains__(self, key): |
34352
05167447f90d
py3: return False early while checking whether None is a key in lazymanifest
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34303
diff
changeset
|
495 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
|
496 return False |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
497 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
|
498 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
499 def __delitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
500 del self._lm[key] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
501 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
502 def __iter__(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
503 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
|
504 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
505 def iterkeys(self): |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
506 return self._lm.iterkeys() |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
507 |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
508 def keys(self): |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
509 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
|
510 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
511 def filesnotin(self, m2, match=None): |
24184
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
512 '''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
|
513 if match is not None: |
bbecb6d80aa7
manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents:
44331
diff
changeset
|
514 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
|
515 sm2 = set(m2.walk(match)) |
bbecb6d80aa7
manifest: rewrite filesnotin to not make superfluous manifest copies
Augie Fackler <augie@google.com>
parents:
44331
diff
changeset
|
516 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
|
517 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
|
518 |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
519 @propertycache |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
520 def _dirs(self): |
43571
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43554
diff
changeset
|
521 return pathutil.dirs(self) |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
522 |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
523 def dirs(self): |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
524 return self._dirs |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
525 |
24324
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
526 def hasdir(self, dir): |
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
527 return dir in self._dirs |
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
528 |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
529 def _filesfastpath(self, match): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
530 """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
|
531 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
|
532 files = match.files() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
533 return len(files) < 100 and ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
534 match.isexact() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
535 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
|
536 ) |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
537 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
538 def walk(self, match): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
539 """Generates matching file names. |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
540 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
541 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
|
542 an entirely new manifest. |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
543 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
544 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
|
545 """ |
24683
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
546 if match.always(): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
547 for f in iter(self): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
548 yield f |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
549 return |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
550 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
551 fset = set(match.files()) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
552 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
553 # 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
|
554 if self._filesfastpath(match): |
24667
19c5b0913960
manifest.walk: join nested if-conditions
Martin von Zweigbergk <martinvonz@google.com>
parents:
24666
diff
changeset
|
555 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
|
556 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
|
557 yield fn |
24682
aef3d1469773
manifest.walk: use return instead of StopIteration in generator
Martin von Zweigbergk <martinvonz@google.com>
parents:
24670
diff
changeset
|
558 return |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
559 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
560 for fn in self: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
561 if fn in fset: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
562 # specified pattern is the exact name |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
563 fset.remove(fn) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
564 if match(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
565 yield fn |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
566 |
42363
27d6956d386b
match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41970
diff
changeset
|
567 # 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
|
568 # follow that here, too |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
569 fset.discard(b'') |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
570 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
571 for fn in sorted(fset): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
572 if not self.hasdir(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
573 match.bad(fn, None) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
574 |
44386
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
575 def _matches(self, match): |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
576 '''generate a new manifest filtered by the match argument''' |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
577 if match.always(): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
578 return self.copy() |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
579 |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
580 if self._filesfastpath(match): |
24666
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
581 m = manifestdict() |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
582 lm = self._lm |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
583 for fn in match.files(): |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
584 if fn in lm: |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
585 m._lm[fn] = lm[fn] |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
586 return m |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
587 |
24700
32b268cbff00
manifestdict: drop empty-string argument when creating empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24685
diff
changeset
|
588 m = manifestdict() |
24664
ea4a7c8909ae
manifestdict.matches: avoid name 'lm' for a not-lazymanifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24647
diff
changeset
|
589 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
|
590 return m |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
591 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
592 def diff(self, m2, match=None, clean=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
593 """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
|
594 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
595 Args: |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
596 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
|
597 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
|
598 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
|
599 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 string. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
606 """ |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
607 if match: |
44386
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
608 m1 = self._matches(match) |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
609 m2 = m2._matches(match) |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
610 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
|
611 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
|
612 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
613 def setflag(self, key, flag): |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
614 if flag not in _manifestflags: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
615 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
|
616 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
|
617 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
618 def get(self, key, default=None): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
619 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
620 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
|
621 except KeyError: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
622 return default |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
623 |
44304
dbbae122f5e4
manifest: remove optional default= argument on flags(path)
Augie Fackler <augie@google.com>
parents:
43798
diff
changeset
|
624 def flags(self, key): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
625 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
626 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
|
627 except KeyError: |
44304
dbbae122f5e4
manifest: remove optional default= argument on flags(path)
Augie Fackler <augie@google.com>
parents:
43798
diff
changeset
|
628 return b'' |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
629 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
630 def copy(self): |
24700
32b268cbff00
manifestdict: drop empty-string argument when creating empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24685
diff
changeset
|
631 c = manifestdict() |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
632 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
|
633 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
634 |
32583
b98199a5c3e1
cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents:
32569
diff
changeset
|
635 def items(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
636 return (x[:2] for x in self._lm.iterentries()) |
2831 | 637 |
38657
28c9d67d88ab
manifest: just duplicate the definition of items as iteritems
Augie Fackler <augie@google.com>
parents:
38557
diff
changeset
|
638 def iteritems(self): |
28c9d67d88ab
manifest: just duplicate the definition of items as iteritems
Augie Fackler <augie@google.com>
parents:
38557
diff
changeset
|
639 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
|
640 |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
641 def iterentries(self): |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
642 return self._lm.iterentries() |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
643 |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
644 def text(self): |
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
645 # most likely uses native version |
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
646 return self._lm.text() |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
647 |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
648 def fastdelta(self, base, changes): |
31790
6bfea18df609
manifest: update comment to be about bytearray
Martin von Zweigbergk <martinvonz@google.com>
parents:
31655
diff
changeset
|
649 """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
|
650 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
|
651 """ |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
652 delta = [] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
653 dstart = None |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
654 dend = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
655 dline = [b""] |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
656 start = 0 |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
657 # zero copy representation of base as a buffer |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
658 addbuf = util.buffer(base) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
659 |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
660 changes = list(changes) |
42170
89c0c8edc9d4
tests: demonstrate broken manifest generation with the pure module
Matt Harbison <matt_harbison@yahoo.com>
parents:
41970
diff
changeset
|
661 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
|
662 # 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
|
663 # each line and creates the deltas |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
664 for f, todelete in changes: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
665 # 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
|
666 start, end = _msearch(addbuf, f, start) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
667 if not todelete: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
668 h, fl = self._lm[f] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
669 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
|
670 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
671 if start == end: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
672 # 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
|
673 raise AssertionError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
674 _(b"failed to remove %s from manifest") % f |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
675 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 l = b"" |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
677 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
|
678 if dend < end: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
679 dend = end |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
680 if l: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
681 dline.append(l) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
682 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
683 if dstart is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
684 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
|
685 dstart = start |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
686 dend = end |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
687 dline = [l] |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
688 |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
689 if dstart is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
690 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
|
691 # 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
|
692 deltatext, arraytext = _addlistdelta(base, delta) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
693 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
694 # 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
|
695 # diff it. |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
696 arraytext = bytearray(self.text()) |
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
697 deltatext = mdiff.textdiff( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
698 util.buffer(base), util.buffer(arraytext) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
699 ) |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
700 |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
701 return arraytext, deltatext |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
702 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
703 |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
704 def _msearch(m, s, lo=0, hi=None): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
705 """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
|
706 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
707 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
|
708 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
|
709 they indicate the proper sorted insertion point. |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
710 |
31655
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
711 m should be a buffer, a memoryview or a byte string. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
712 s is a byte string""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
713 |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
714 def advance(i, c): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
715 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
|
716 i += 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
717 return i |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
718 |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
719 if not s: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
720 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
721 lenm = len(m) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
722 if not hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
723 hi = lenm |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
724 while lo < hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
725 mid = (lo + hi) // 2 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
726 start = mid |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
727 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
|
728 start -= 1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
729 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
|
730 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
|
731 # 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
|
732 # 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
|
733 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
|
734 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
735 # 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
|
736 hi = start |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
737 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
|
738 found = m[lo:end] |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
739 if s == found: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
740 # 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
|
741 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
|
742 return (lo, end + 1) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
743 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
744 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
745 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
746 |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
747 def _checkforbidden(l): |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
748 """Check filenames for illegal characters.""" |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
749 for f in l: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
750 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
|
751 raise error.StorageError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
752 _(b"'\\n' and '\\r' disallowed in filenames: %r") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
753 % pycompat.bytestr(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
754 ) |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
755 |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
756 |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
757 # 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
|
758 # return a delta suitable for addrevision |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
759 def _addlistdelta(addlist, x): |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
760 # 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
|
761 # than repeatedly modifying the existing one |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
762 currentposition = 0 |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
763 newaddlist = bytearray() |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
764 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
765 for start, end, content in x: |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
766 newaddlist += addlist[currentposition:start] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
767 if content: |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
768 newaddlist += bytearray(content) |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
769 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
770 currentposition = end |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
771 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
772 newaddlist += addlist[currentposition:] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
773 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
774 deltatext = b"".join( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
775 struct.pack(b">lll", start, end, len(content)) + content |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
776 for start, end, content in x |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
777 ) |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
778 return deltatext, newaddlist |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
779 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
780 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
781 def _splittopdir(f): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
782 if b'/' in f: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
783 dir, subpath = f.split(b'/', 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
784 return dir + b'/', subpath |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
785 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
786 return b'', f |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
787 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
788 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
789 _noop = lambda s: None |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
790 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
791 |
44666
8c66a680f396
manifest: also declare treemanifest as implementing imanifestdict
Augie Fackler <augie@google.com>
parents:
44665
diff
changeset
|
792 @interfaceutil.implementer(repository.imanifestdict) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
793 class treemanifest(object): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
794 def __init__(self, nodeconstants, dir=b'', text=b''): |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
795 self._dir = dir |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
796 self.nodeconstants = nodeconstants |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
797 self._node = self.nodeconstants.nullid |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
798 self._loadfunc = _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
799 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
|
800 self._dirty = False |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
801 self._dirs = {} |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
802 self._lazydirs = {} |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
803 # Using _lazymanifest here is a little slower than plain old dicts |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
804 self._files = {} |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
805 self._flags = {} |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
806 if text: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
807 |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
808 def readsubtree(subdir, subm): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
809 raise AssertionError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
810 b'treemanifest constructor only accepts flat manifests' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
811 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
812 |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
813 self.parse(text, readsubtree) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
814 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
|
815 |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
816 def _subpath(self, path): |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
817 return self._dir + path |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
818 |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
819 def _loadalllazy(self): |
40040
a0c18b271ea1
treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents:
40039
diff
changeset
|
820 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
|
821 subpath = self._subpath |
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
822 for d, (node, readsubtree, docopy) in pycompat.iteritems( |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
823 self._lazydirs |
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
824 ): |
40040
a0c18b271ea1
treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents:
40039
diff
changeset
|
825 if docopy: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
826 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
|
827 else: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
828 selfdirs[d] = readsubtree(subpath(d), node) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
829 self._lazydirs = {} |
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
830 |
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
831 def _loadlazy(self, d): |
39982
da0319e024c0
treemanifests: make _loadlazy tolerate item not on _lazydirs
spectral <spectral@google.com>
parents:
39874
diff
changeset
|
832 v = self._lazydirs.get(d) |
da0319e024c0
treemanifests: make _loadlazy tolerate item not on _lazydirs
spectral <spectral@google.com>
parents:
39874
diff
changeset
|
833 if v: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
834 node, readsubtree, docopy = v |
40040
a0c18b271ea1
treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents:
40039
diff
changeset
|
835 if docopy: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
836 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
|
837 else: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
838 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
|
839 del self._lazydirs[d] |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
840 |
39538
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
841 def _loadchildrensetlazy(self, visit): |
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
842 if not visit: |
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
843 return None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
844 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
|
845 self._loadalllazy() |
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
846 return None |
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
847 |
39983
19103e68a698
treemanifests: make _loadchildrensetlazy just call _loadlazy
spectral <spectral@google.com>
parents:
39982
diff
changeset
|
848 loadlazy = self._loadlazy |
39538
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
849 for k in visit: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
850 loadlazy(k + b'/') |
39538
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
851 return visit |
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
852 |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
853 def _loaddifflazy(self, t1, t2): |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
854 """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
|
855 |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
856 The criteria currently is: |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
857 - 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
|
858 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
|
859 - 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
|
860 differs, load it in both |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
861 """ |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
862 toloadlazy = [] |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
863 for d, v1 in pycompat.iteritems(t1._lazydirs): |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
864 v2 = t2._lazydirs.get(d) |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
865 if not v2 or v2[0] != v1[0]: |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
866 toloadlazy.append(d) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
867 for d, v1 in pycompat.iteritems(t2._lazydirs): |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
868 if d not in t1._lazydirs: |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
869 toloadlazy.append(d) |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
870 |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
871 for d in toloadlazy: |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
872 t1._loadlazy(d) |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
873 t2._loadlazy(d) |
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
874 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
875 def __len__(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
876 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
877 size = len(self._files) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
878 self._loadalllazy() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
879 for m in self._dirs.values(): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
880 size += m.__len__() |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
881 return size |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
882 |
36212
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
883 def __nonzero__(self): |
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
884 # Faster than "__len() != 0" since it avoids loading sub-manifests |
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
885 return not self._isempty() |
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
886 |
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
887 __bool__ = __nonzero__ |
b42c47b8c9d4
treemanifest: add an optimized __nonzero__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36133
diff
changeset
|
888 |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
889 def _isempty(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
890 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
|
891 # See if we can skip loading everything. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
892 if self._files or ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
893 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
|
894 ): |
39533
079d7bfa463d
treemanifest: attempt to avoid loading all lazily-loaded subdirs in _isempty
Kyle Lippincott <spectral@google.com>
parents:
39532
diff
changeset
|
895 return False |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
896 self._loadalllazy() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
897 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
|
898 |
44164
c443b9ba6f63
py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents:
43798
diff
changeset
|
899 @encoding.strmethod |
26400
6f9d9e2a661f
manifest: add id(self) to treemanifest __repr__
Augie Fackler <augie@google.com>
parents:
26199
diff
changeset
|
900 def __repr__(self): |
43346
6ada8a274b9c
formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
901 return ( |
44164
c443b9ba6f63
py3: __repr__ needs to return str, not bytes
Kyle Lippincott <spectral@google.com>
parents:
43798
diff
changeset
|
902 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
|
903 % ( |
6ada8a274b9c
formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
904 self._dir, |
6ada8a274b9c
formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
905 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
|
906 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
|
907 self._dirty, |
6ada8a274b9c
formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
908 id(self), |
6ada8a274b9c
formatting: run black version 19.10b0 on the codebase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
909 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
910 ) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
911 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
912 def dir(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
913 """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
|
914 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
|
915 return self._dir |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
916 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
917 def node(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
918 """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
|
919 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
|
920 """ |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
921 assert not self._dirty |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
922 return self._node |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
923 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
924 def setnode(self, node): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
925 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
|
926 self._dirty = False |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
927 |
28206
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
928 def iterentries(self): |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
929 self._load() |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
930 self._loadalllazy() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
931 for p, n in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
932 itertools.chain(self._dirs.items(), self._files.items()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
933 ): |
28206
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
934 if p in self._files: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
935 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
|
936 else: |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
937 for x in n.iterentries(): |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
938 yield x |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
939 |
32583
b98199a5c3e1
cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents:
32569
diff
changeset
|
940 def items(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
941 self._load() |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
942 self._loadalllazy() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
943 for p, n in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
944 itertools.chain(self._dirs.items(), self._files.items()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
945 ): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
946 if p in self._files: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
947 yield self._subpath(p), n |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
948 else: |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
949 for f, sn in pycompat.iteritems(n): |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
950 yield f, sn |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
951 |
32583
b98199a5c3e1
cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents:
32569
diff
changeset
|
952 iteritems = items |
b98199a5c3e1
cleanup: rename all iteritems methods to items and add iteritems alias
Augie Fackler <raf@durin42.com>
parents:
32569
diff
changeset
|
953 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
954 def iterkeys(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
955 self._load() |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
956 self._loadalllazy() |
32569
aa333c1982ab
manifest: use itertools.chain() instead of + for Python 3 compat
Augie Fackler <raf@durin42.com>
parents:
32568
diff
changeset
|
957 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
|
958 if p in self._files: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
959 yield self._subpath(p) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
960 else: |
35586
fbf1a5d680ea
py3: don't use dict.iterkeys()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34352
diff
changeset
|
961 for f in self._dirs[p]: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
962 yield f |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
963 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
964 def keys(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
965 return list(self.iterkeys()) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
966 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
967 def __iter__(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
968 return self.iterkeys() |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
969 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
970 def __contains__(self, f): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
971 if f is None: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
972 return False |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
973 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
974 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
975 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
976 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
977 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
978 if dir not in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
979 return False |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
980 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
981 return self._dirs[dir].__contains__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
982 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
983 return f in self._files |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
984 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
985 def get(self, f, default=None): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
986 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
987 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
988 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
989 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
990 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
991 if dir not in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
992 return default |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
993 return self._dirs[dir].get(subpath, default) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
994 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
995 return self._files.get(f, default) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
996 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
997 def __getitem__(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
998 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
999 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1000 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1001 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1002 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1003 return self._dirs[dir].__getitem__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1004 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1005 return self._files[f] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1006 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1007 def flags(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1008 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1009 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1010 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1011 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1012 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1013 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
|
1014 return b'' |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1015 return self._dirs[dir].flags(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1016 else: |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1017 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
|
1018 return b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1019 return self._flags.get(f, b'') |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1020 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1021 def find(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1022 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1023 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1024 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1025 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1026 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1027 return self._dirs[dir].find(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1028 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1029 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
|
1030 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1031 def __delitem__(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1032 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1033 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1034 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1035 self._loadlazy(dir) |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1036 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1037 self._dirs[dir].__delitem__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1038 # If the directory is now empty, remove it |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
1039 if self._dirs[dir]._isempty(): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1040 del self._dirs[dir] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1041 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1042 del self._files[f] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1043 if f in self._flags: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1044 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
|
1045 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1046 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1047 def __setitem__(self, f, n): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1048 assert n is not None |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1049 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1050 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1051 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1052 self._loadlazy(dir) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1053 if dir not in self._dirs: |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1054 self._dirs[dir] = treemanifest( |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1055 self.nodeconstants, self._subpath(dir) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1056 ) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1057 self._dirs[dir].__setitem__(subpath, n) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1058 else: |
44703
0e99b876966a
manifest: teach treemanifest about long hashes
Augie Fackler <augie@google.com>
parents:
44701
diff
changeset
|
1059 # 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
|
1060 # 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
|
1061 # sometimes extra bytes were added. |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
1062 assert len(n) in (20, 32) |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
1063 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
|
1064 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1065 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1066 def _load(self): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1067 if self._loadfunc is not _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1068 lf, self._loadfunc = self._loadfunc, _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1069 lf(self) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1070 elif self._copyfunc is not _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1071 cf, self._copyfunc = self._copyfunc, _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1072 cf(self) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1073 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1074 def setflag(self, f, flags): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1075 """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
|
1076 if flags not in _manifestflags: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
45067
diff
changeset
|
1077 raise TypeError(b"Invalid manifest flag set.") |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1078 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1079 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1080 if dir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1081 self._loadlazy(dir) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1082 if dir not in self._dirs: |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1083 self._dirs[dir] = treemanifest( |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1084 self.nodeconstants, self._subpath(dir) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1085 ) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1086 self._dirs[dir].setflag(subpath, flags) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1087 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1088 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
|
1089 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1090 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1091 def copy(self): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1092 copy = treemanifest(self.nodeconstants, self._dir) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1093 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
|
1094 copy._dirty = self._dirty |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1095 if self._copyfunc is _noop: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1096 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1097 def _copyfunc(s): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1098 self._load() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1099 s._lazydirs = { |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
1100 d: (n, r, True) |
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
1101 for d, (n, r, c) in pycompat.iteritems(self._lazydirs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1102 } |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1103 sdirs = s._dirs |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1104 for d, v in pycompat.iteritems(self._dirs): |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1105 sdirs[d] = v.copy() |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1106 s._files = dict.copy(self._files) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1107 s._flags = dict.copy(self._flags) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1108 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1109 if self._loadfunc is _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1110 _copyfunc(copy) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1111 else: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1112 copy._copyfunc = _copyfunc |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1113 else: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1114 copy._copyfunc = self._copyfunc |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1115 return copy |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1116 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1117 def filesnotin(self, m2, match=None): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1118 '''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
|
1119 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
|
1120 m1 = self._matches(match) |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1121 m2 = m2._matches(match) |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1122 return m1.filesnotin(m2) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1123 |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1124 files = set() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1125 |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1126 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
|
1127 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
|
1128 return |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1129 t1._load() |
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1130 t2._load() |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
1131 self._loaddifflazy(t1, t2) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1132 for d, m1 in pycompat.iteritems(t1._dirs): |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1133 if d in t2._dirs: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1134 m2 = t2._dirs[d] |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1135 _filesnotin(m1, m2) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1136 else: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1137 files.update(m1.iterkeys()) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1138 |
36333
413c179cf7d5
manifest: correct the one use of iterkeys() on a dict
Augie Fackler <augie@google.com>
parents:
36212
diff
changeset
|
1139 for fn in t1._files: |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1140 if fn not in t2._files: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1141 files.add(t1._subpath(fn)) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1142 |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
1143 _filesnotin(self, m2) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1144 return files |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1145 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1146 @propertycache |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1147 def _alldirs(self): |
43571
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43554
diff
changeset
|
1148 return pathutil.dirs(self) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1149 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1150 def dirs(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1151 return self._alldirs |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1152 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1153 def hasdir(self, dir): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1154 self._load() |
24406
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
1155 topdir, subdir = _splittopdir(dir) |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
1156 if topdir: |
39984
3cacb74c3a22
treemanifests: skip extraneous check for item before calling _loadlazy
spectral <spectral@google.com>
parents:
39983
diff
changeset
|
1157 self._loadlazy(topdir) |
24406
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
1158 if topdir in self._dirs: |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
1159 return self._dirs[topdir].hasdir(subdir) |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
1160 return False |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1161 dirslash = dir + b'/' |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1162 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
|
1163 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1164 def walk(self, match): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1165 """Generates matching file names. |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1166 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1167 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
|
1168 """ |
24683
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
1169 if match.always(): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
1170 for f in iter(self): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
1171 yield f |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
1172 return |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
1173 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1174 fset = set(match.files()) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1175 |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1176 for fn in self._walk(match): |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1177 if fn in fset: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1178 # specified pattern is the exact name |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1179 fset.remove(fn) |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1180 yield fn |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1181 |
42363
27d6956d386b
match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41970
diff
changeset
|
1182 # 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
|
1183 # follow that here, too |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1184 fset.discard(b'') |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1185 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1186 for fn in sorted(fset): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1187 if not self.hasdir(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1188 match.bad(fn, None) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
1189 |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1190 def _walk(self, match): |
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1191 '''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
|
1192 visit = match.visitchildrenset(self._dir[:-1]) |
39539
3ba9ef0fb693
treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents:
39538
diff
changeset
|
1193 if not visit: |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1194 return |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1195 |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1196 # 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
|
1197 self._load() |
39539
3ba9ef0fb693
treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents:
39538
diff
changeset
|
1198 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
|
1199 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
|
1200 if p in self._files: |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1201 fullp = self._subpath(p) |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1202 if match(fullp): |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1203 yield fullp |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1204 else: |
39539
3ba9ef0fb693
treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents:
39538
diff
changeset
|
1205 if not visit or p[:-1] in visit: |
3ba9ef0fb693
treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents:
39538
diff
changeset
|
1206 for f in self._dirs[p]._walk(match): |
3ba9ef0fb693
treemanifest: use visitchildrenset when doing a walk
Kyle Lippincott <spectral@google.com>
parents:
39538
diff
changeset
|
1207 yield f |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1208 |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1209 def _matches(self, match): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1210 """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
|
1211 if match.always(): |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1212 return self.copy() |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1213 return self._matches_inner(match) |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1214 |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1215 def _matches_inner(self, match): |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1216 if match.always(): |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1217 return self.copy() |
27343
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1218 |
42363
27d6956d386b
match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41970
diff
changeset
|
1219 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
|
1220 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
|
1221 return self.copy() |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1222 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
|
1223 if not visit: |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1224 return ret |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1225 |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1226 self._load() |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1227 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
|
1228 # 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
|
1229 # 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
|
1230 # 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
|
1231 # 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
|
1232 # 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
|
1233 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
|
1234 continue |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1235 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
|
1236 # 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
|
1237 # matcher code to further filter results. |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1238 if not match(fullp): |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1239 continue |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1240 ret._files[fn] = self._files[fn] |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1241 if fn in self._flags: |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1242 ret._flags[fn] = self._flags[fn] |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1243 |
39538
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
1244 visit = self._loadchildrensetlazy(visit) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1245 for dir, subm in pycompat.iteritems(self._dirs): |
39538
154e4f84b51c
treemanifest: use visitchildrenset when filtering a manifest to a matcher
Kyle Lippincott <spectral@google.com>
parents:
39535
diff
changeset
|
1246 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
|
1247 continue |
44386
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1248 m = subm._matches_inner(match) |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1249 if not m._isempty(): |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1250 ret._dirs[dir] = m |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1251 |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1252 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
|
1253 ret._dirty = True |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1254 return ret |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1255 |
44665
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1256 def fastdelta(self, base, changes): |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1257 raise FastdeltaUnavailable() |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1258 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1259 def diff(self, m2, match=None, clean=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1260 """Finds changes between the current manifest and m2. |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1261 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1262 Args: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1263 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
|
1264 clean: if true, include files unchanged between these manifests |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1265 with a None value in the returned dictionary. |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1266 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
1271 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
|
1272 string. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1273 """ |
39534
8798be5f04fc
treemanifest: avoid unnecessary copies/processing when using alwaysmatcher
Kyle Lippincott <spectral@google.com>
parents:
39533
diff
changeset
|
1274 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
|
1275 m1 = self._matches(match) |
0bf3b5e80d30
manifest: move matches method to be outside the interface
Augie Fackler <augie@google.com>
parents:
44332
diff
changeset
|
1276 m2 = m2._matches(match) |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1277 return m1.diff(m2, clean=clean) |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1278 result = {} |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1279 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
|
1280 |
2c3f69855ce8
manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41041
diff
changeset
|
1281 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
|
1282 """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
|
1283 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
|
1284 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
|
1285 return |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1286 t1._load() |
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1287 t2._load() |
40039
906c95073ff7
treemanifests: extract _loaddifflazy from _diff, use in _filesnotin
spectral <spectral@google.com>
parents:
39988
diff
changeset
|
1288 self._loaddifflazy(t1, t2) |
39985
731961d972ba
treemanifests: remove _loadalllazy in _diff()
spectral <spectral@google.com>
parents:
39984
diff
changeset
|
1289 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1290 for d, m1 in pycompat.iteritems(t1._dirs): |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1291 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
|
1292 stack.append((m1, m2)) |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1293 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1294 for d, m2 in pycompat.iteritems(t2._dirs): |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1295 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
|
1296 stack.append((emptytree, m2)) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1297 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1298 for fn, n1 in pycompat.iteritems(t1._files): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1299 fl1 = t1._flags.get(fn, b'') |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1300 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
|
1301 fl2 = t2._flags.get(fn, b'') |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1302 if n1 != n2 or fl1 != fl2: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1303 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2)) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1304 elif clean: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1305 result[t1._subpath(fn)] = None |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1306 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1307 for fn, n2 in pycompat.iteritems(t2._files): |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1308 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
|
1309 fl2 = t2._flags.get(fn, b'') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1310 result[t2._subpath(fn)] = ((None, b''), (n2, fl2)) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1311 |
41153
2c3f69855ce8
manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41041
diff
changeset
|
1312 stackls = [] |
2c3f69855ce8
manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41041
diff
changeset
|
1313 _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
|
1314 while stackls: |
2c3f69855ce8
manifest: convert a recursive function to iterative one using stacks
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41041
diff
changeset
|
1315 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
|
1316 # 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
|
1317 _iterativediff(t1, t2, stackls) |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1318 return result |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1319 |
25221
eafa06e9edde
treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
25220
diff
changeset
|
1320 def unmodifiedsince(self, m2): |
eafa06e9edde
treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
25220
diff
changeset
|
1321 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
|
1322 |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1323 def parse(self, text, readsubtree): |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1324 selflazy = self._lazydirs |
24781
055b3cbe6c57
treemanifest: extract parse method from constructor
Martin von Zweigbergk <martinvonz@google.com>
parents:
24780
diff
changeset
|
1325 for f, n, fl in _parse(text): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1326 if fl == b't': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1327 f = f + b'/' |
40040
a0c18b271ea1
treemanifests: store whether a lazydirs entry needs copied after materializing
spectral <spectral@google.com>
parents:
40039
diff
changeset
|
1328 # 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
|
1329 # 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
|
1330 selflazy[f] = (n, readsubtree, False) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1331 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
|
1332 # 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
|
1333 # 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
|
1334 # 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
|
1335 # to nullid). |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1336 self[f] = n |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1337 if fl: |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1338 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
|
1339 else: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1340 # 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
|
1341 # 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
|
1342 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
|
1343 if fl: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1344 self._flags[f] = fl |
24781
055b3cbe6c57
treemanifest: extract parse method from constructor
Martin von Zweigbergk <martinvonz@google.com>
parents:
24780
diff
changeset
|
1345 |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1346 def text(self): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1347 """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
|
1348 self._load() |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1349 return _text(self.iterentries()) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1350 |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1351 def dirtext(self): |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1352 """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
|
1353 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
|
1354 """ |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1355 self._load() |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1356 flags = self.flags |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1357 lazydirs = [ |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
1358 (d[:-1], v[0], b't') for d, v in pycompat.iteritems(self._lazydirs) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1359 ] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1360 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
|
1361 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
|
1362 return _text(sorted(dirs + files + lazydirs)) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1363 |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1364 def read(self, gettext, readsubtree): |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1365 def _load_for_read(s): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1366 s.parse(gettext(), readsubtree) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1367 s._dirty = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1368 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1369 self._loadfunc = _load_for_read |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1370 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1371 def writesubtrees(self, m1, m2, writesubtree, match): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1372 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
|
1373 m1._load() |
8a84347b9907
manifest: call m1.load and m2.load before writing a subtree
Durham Goode <durham@fb.com>
parents:
29837
diff
changeset
|
1374 m2._load() |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1375 emptytree = treemanifest(self.nodeconstants) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1376 |
39535
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1377 def getnode(m, d): |
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1378 ld = m._lazydirs.get(d) |
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1379 if ld: |
46096
93e09d370003
treemanifest: stop storing full path for each item in manifest._lazydirs
Kyle Lippincott <spectral@google.com>
parents:
45957
diff
changeset
|
1380 return ld[0] |
39535
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1381 return m._dirs.get(d, emptytree)._node |
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1382 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1383 # 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
|
1384 visit = match.visitchildrenset(self._dir[:-1]) |
40041
67b93cd847fb
treemanifests: remove _loadalllazy when doing copies
spectral <spectral@google.com>
parents:
40040
diff
changeset
|
1385 visit = self._loadchildrensetlazy(visit) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1386 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
|
1387 visit = None |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1388 for d, subm in pycompat.iteritems(self._dirs): |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1389 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
|
1390 continue |
39535
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1391 subp1 = getnode(m1, d) |
c29548ba4a75
treemanifest: avoid loading everything just to get their nodeid
Kyle Lippincott <spectral@google.com>
parents:
39534
diff
changeset
|
1392 subp2 = getnode(m2, d) |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
1393 if subp1 == self.nodeconstants.nullid: |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1394 subp1, subp2 = subp2, subp1 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1395 writesubtree(subm, subp1, subp2, match) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1396 |
31876
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1397 def walksubtrees(self, matcher=None): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1398 """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
|
1399 manifest itself. |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1400 |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1401 If `matcher` is provided, it only returns subtrees that match. |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1402 """ |
42363
27d6956d386b
match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41970
diff
changeset
|
1403 if matcher and not matcher.visitdir(self._dir[:-1]): |
31876
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1404 return |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1405 if not matcher or matcher(self._dir[:-1]): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1406 yield self |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1407 |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1408 self._load() |
39532
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1409 # OPT: use visitchildrenset to avoid loading everything. |
93486cc46125
treemanifest: introduce lazy loading of subdirs
spectral <spectral@google.com>
parents:
39349
diff
changeset
|
1410 self._loadalllazy() |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1411 for d, subm in pycompat.iteritems(self._dirs): |
31876
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1412 for subtree in subm.walksubtrees(matcher=matcher): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1413 yield subtree |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1414 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1415 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1416 class manifestfulltextcache(util.lrucachedict): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1417 """File-backed LRU cache for the manifest cache |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1418 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1419 File consists of entries, up to EOF: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1420 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1421 - 20 bytes node, 4 bytes length, <length> manifest data |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1422 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1423 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
|
1424 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1425 """ |
41967
07c80298b5a1
manifestcache: abstract the filename in a class attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41966
diff
changeset
|
1426 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1427 _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
|
1428 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1429 def __init__(self, max): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1430 super(manifestfulltextcache, self).__init__(max) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1431 self._dirty = False |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1432 self._read = False |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1433 self._opener = None |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1434 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1435 def read(self): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1436 if self._read or self._opener is None: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1437 return |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1438 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1439 try: |
41967
07c80298b5a1
manifestcache: abstract the filename in a class attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41966
diff
changeset
|
1440 with self._opener(self._file) as fp: |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1441 set = super(manifestfulltextcache, self).__setitem__ |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1442 # 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
|
1443 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
|
1444 # 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
|
1445 node = fp.read(20) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1446 if len(node) < 20: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1447 break |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1448 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1449 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
|
1450 except struct.error: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1451 break |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1452 value = bytearray(fp.read(size)) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1453 if len(value) != size: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1454 break |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1455 set(node, value) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1456 except IOError: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1457 # the file is allowed to be missing |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1458 pass |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1459 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1460 self._read = True |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1461 self._dirty = False |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1462 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1463 def write(self): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1464 if not self._dirty or self._opener is None: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1465 return |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1466 # 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
|
1467 try: |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1468 with self._opener( |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1469 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
|
1470 ) as fp: |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1471 node = self._head.prev |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1472 while True: |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1473 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
|
1474 fp.write(node.key) |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1475 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
|
1476 fp.write(node.value) |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1477 if node is self._head: |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1478 break |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1479 node = node.prev |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1480 except IOError: |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1481 # 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
|
1482 # the content can be missing. |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1483 # |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1484 # 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
|
1485 # 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
|
1486 # |
35bb67427f63
manifest-cache: ignore IOError while writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44708
diff
changeset
|
1487 # 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
|
1488 # 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
|
1489 pass |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1490 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1491 def __len__(self): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1492 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1493 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1494 return super(manifestfulltextcache, self).__len__() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1495 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1496 def __contains__(self, k): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1497 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1498 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1499 return super(manifestfulltextcache, self).__contains__(k) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1500 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1501 def __iter__(self): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1502 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1503 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1504 return super(manifestfulltextcache, self).__iter__() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1505 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1506 def __getitem__(self, k): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1507 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1508 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1509 # the cache lru order can change on read |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1510 setdirty = self._cache.get(k) is not self._head |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1511 value = super(manifestfulltextcache, self).__getitem__(k) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1512 if setdirty: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1513 self._dirty = True |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1514 return value |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1515 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1516 def __setitem__(self, k, v): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1517 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1518 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1519 super(manifestfulltextcache, self).__setitem__(k, v) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1520 self._dirty = True |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1521 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1522 def __delitem__(self, k): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1523 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1524 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1525 super(manifestfulltextcache, self).__delitem__(k) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1526 self._dirty = True |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1527 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1528 def get(self, k, default=None): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1529 if not self._read: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1530 self.read() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1531 return super(manifestfulltextcache, self).get(k, default=default) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1532 |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1533 def clear(self, clear_persisted_data=False): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1534 super(manifestfulltextcache, self).clear() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1535 if clear_persisted_data: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1536 self._dirty = True |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1537 self.write() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1538 self._read = False |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1539 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1540 |
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
|
1541 # 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
|
1542 # (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
|
1543 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
|
1544 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1545 |
44665
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1546 class FastdeltaUnavailable(Exception): |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1547 """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
|
1548 |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1549 |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1550 @interfaceutil.implementer(repository.imanifeststorage) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1551 class manifestrevlog(object): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1552 """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
|
1553 full-text manifest contents. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
1554 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1555 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1556 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1557 self, |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1558 nodeconstants, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1559 opener, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1560 tree=b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1561 dirlogcache=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1562 indexfile=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1563 treemanifest=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1564 ): |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1565 """Constructs a new manifest revlog |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1566 |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1567 `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
|
1568 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
|
1569 |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1570 `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
|
1571 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
|
1572 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
|
1573 value is passed in to the constructor. |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1574 """ |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1575 self.nodeconstants = nodeconstants |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1576 # 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
|
1577 # 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
|
1578 # 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
|
1579 cachesize = 4 |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1580 optiontreemanifest = False |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1581 opts = getattr(opener, 'options', None) |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1582 if opts is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1583 cachesize = opts.get(b'manifestcachesize', cachesize) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1584 optiontreemanifest = opts.get(b'treemanifest', False) |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1585 |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1586 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
|
1587 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1588 self._fulltextcache = manifestfulltextcache(cachesize) |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1589 |
39271
0d97530eb535
manifest: rename dir argument and attribute to tree
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39270
diff
changeset
|
1590 if tree: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1591 assert self._treeondisk, b'opts is %r' % opts |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1592 |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1593 if indexfile is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1594 indexfile = b'00manifest.i' |
39271
0d97530eb535
manifest: rename dir argument and attribute to tree
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39270
diff
changeset
|
1595 if tree: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1596 indexfile = b"meta/" + tree + indexfile |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1597 |
39342
57c3864f3aad
manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39341
diff
changeset
|
1598 self.tree = tree |
57c3864f3aad
manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39341
diff
changeset
|
1599 |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1600 # 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
|
1601 if tree: |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1602 self._dirlogcache = dirlogcache |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1603 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1604 self._dirlogcache = {b'': self} |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1605 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1606 self._revlog = revlog.revlog( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1607 opener, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1608 indexfile, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1609 # only root indexfile is cached |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1610 checkambig=not bool(tree), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1611 mmaplargeindex=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1612 upperboundcomp=MAXCOMPRESSION, |
44869
5e3c718692bb
nodemap: drop the 'exp-' prefix for internal opener option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44864
diff
changeset
|
1613 persistentnodemap=opener.options.get(b'persistent-nodemap', False), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1614 ) |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1615 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1616 self.index = self._revlog.index |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1617 self.version = self._revlog.version |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1618 self._generaldelta = self._revlog._generaldelta |
46727
f63299ee7e4d
revlog: add attribute on revlogs that specifies its kind
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46560
diff
changeset
|
1619 self._revlog.revlog_kind = b'manifest' |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1620 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1621 def _setupmanifestcachehooks(self, repo): |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1622 """Persist the manifestfulltextcache on lock release""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1623 if not util.safehasattr(repo, b'_wlockref'): |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1624 return |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1625 |
41970
e4ac7e63c213
manifestcache: use `wcache` directory for manifest cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41969
diff
changeset
|
1626 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
|
1627 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
|
1628 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
|
1629 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1630 reporef = weakref.ref(repo) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1631 manifestrevlogref = weakref.ref(self) |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1632 |
43798
888bd39ed555
lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents:
43571
diff
changeset
|
1633 def persistmanifestcache(success): |
888bd39ed555
lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents:
43571
diff
changeset
|
1634 # 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
|
1635 if not success: |
888bd39ed555
lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents:
43571
diff
changeset
|
1636 return |
888bd39ed555
lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents:
43571
diff
changeset
|
1637 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1638 repo = reporef() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1639 self = manifestrevlogref() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1640 if repo is None or self is None: |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1641 return |
39347
57301ba47e66
manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39344
diff
changeset
|
1642 if repo.manifestlog.getstorage(b'') is not self: |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1643 # there's a different manifest in play now, abort |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1644 return |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1645 self._fulltextcache.write() |
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1646 |
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
|
1647 repo._afterlock(persistmanifestcache) |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1648 |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1649 @property |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1650 def fulltextcache(self): |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1651 return self._fulltextcache |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1652 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1653 def clearcaches(self, clear_persisted_data=False): |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1654 self._revlog.clearcaches() |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
1655 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
|
1656 self._dirlogcache = {self.tree: self} |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1657 |
36133
59adb3051718
manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents:
35586
diff
changeset
|
1658 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
|
1659 if d: |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1660 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
|
1661 if d not in self._dirlogcache: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1662 mfrevlog = manifestrevlog( |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1663 self.nodeconstants, |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1664 self.opener, |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1665 d, |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1666 self._dirlogcache, |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1667 treemanifest=self._treeondisk, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1668 ) |
36133
59adb3051718
manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents:
35586
diff
changeset
|
1669 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
|
1670 return self._dirlogcache[d] |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1671 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1672 def add( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1673 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1674 m, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1675 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1676 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1677 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1678 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1679 added, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1680 removed, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1681 readtree=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1682 match=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1683 ): |
45067
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1684 """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
|
1685 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1686 input: |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1687 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1688 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
|
1689 transaction: the open transaction |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1690 p1: manifest-node of p1 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1691 p2: manifest-node of p2 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1692 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
|
1693 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
|
1694 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1695 tree manifest input: |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1696 |
5a80915e99ce
commitctx: document the manifest writing function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44911
diff
changeset
|
1697 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
|
1698 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
|
1699 """ |
44665
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1700 try: |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1701 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
|
1702 raise FastdeltaUnavailable() |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1703 # 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
|
1704 # 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
|
1705 # 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
|
1706 # revlog layer. |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1707 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1708 _checkforbidden(added) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1709 # combine the changed lists into one sorted iterator |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1710 work = heapq.merge( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1711 [(x, False) for x in sorted(added)], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1712 [(x, True) for x in sorted(removed)], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1713 ) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1714 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1715 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
|
1716 cachedelta = self._revlog.rev(p1), deltatext |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1717 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
|
1718 rev = self._revlog.addrevision( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1719 text, transaction, link, p1, p2, cachedelta |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1720 ) |
46560
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
46445
diff
changeset
|
1721 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
|
1722 except FastdeltaUnavailable: |
948fac24bc39
manifest: introduce new exception to signal unavailability of fastdelta()
Augie Fackler <augie@google.com>
parents:
44386
diff
changeset
|
1723 # 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
|
1724 # 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
|
1725 # 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
|
1726 # 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
|
1727 # delta process. |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1728 if self._treeondisk: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1729 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
|
1730 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
|
1731 m1 = readtree(self.tree, p1) |
57c3864f3aad
manifest: make tree a public attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39341
diff
changeset
|
1732 m2 = readtree(self.tree, p2) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1733 n = self._addtree( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1734 m, transaction, link, m1, m2, readtree, match=match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1735 ) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1736 arraytext = None |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1737 else: |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1738 text = m.text() |
46560
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
46445
diff
changeset
|
1739 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
|
1740 n = self._revlog.node(rev) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
1741 arraytext = bytearray(text) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1742 |
30209
9d06b65c5df2
manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents:
30207
diff
changeset
|
1743 if arraytext is not None: |
9d06b65c5df2
manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents:
30207
diff
changeset
|
1744 self.fulltextcache[n] = arraytext |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1745 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1746 return n |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1747 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1748 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
|
1749 # 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
|
1750 # 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
|
1751 if self.tree != b'' and ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1752 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
|
1753 ): |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1754 return m.node() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1755 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1756 def writesubtree(subm, subp1, subp2, match): |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1757 sublog = self.dirlog(subm.dir()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1758 sublog.add( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1759 subm, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1760 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1761 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1762 subp1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1763 subp2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1764 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1765 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1766 readtree=readtree, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1767 match=match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1768 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1769 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
1770 m.writesubtrees(m1, m2, writesubtree, match) |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1771 text = m.dirtext() |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1772 n = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1773 if self.tree != b'': |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1774 # 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
|
1775 if text == m1.dirtext(): |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1776 n = m1.node() |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
1777 elif text == m2.dirtext(): |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1778 n = m2.node() |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1779 |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1780 if not n: |
46560
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
46445
diff
changeset
|
1781 rev = self._revlog.addrevision( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1782 text, transaction, link, m1.node(), m2.node() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1783 ) |
46560
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
46445
diff
changeset
|
1784 n = self._revlog.node(rev) |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1785 |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1786 # 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
|
1787 m.setnode(n) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1788 return n |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1789 |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1790 def __len__(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1791 return len(self._revlog) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1792 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1793 def __iter__(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1794 return self._revlog.__iter__() |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1795 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1796 def rev(self, node): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1797 return self._revlog.rev(node) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1798 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1799 def node(self, rev): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1800 return self._revlog.node(rev) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1801 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1802 def lookup(self, value): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1803 return self._revlog.lookup(value) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1804 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1805 def parentrevs(self, rev): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1806 return self._revlog.parentrevs(rev) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1807 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1808 def parents(self, node): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1809 return self._revlog.parents(node) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1810 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1811 def linkrev(self, rev): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1812 return self._revlog.linkrev(rev) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1813 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1814 def checksize(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1815 return self._revlog.checksize() |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1816 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1817 def revision(self, node, _df=None, raw=False): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1818 return self._revlog.revision(node, _df=_df, raw=raw) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1819 |
42740
2128c76c8970
rawdata: forward `rawdata` call on `manifestlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42485
diff
changeset
|
1820 def rawdata(self, node, _df=None): |
2128c76c8970
rawdata: forward `rawdata` call on `manifestlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42485
diff
changeset
|
1821 return self._revlog.rawdata(node, _df=_df) |
2128c76c8970
rawdata: forward `rawdata` call on `manifestlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42485
diff
changeset
|
1822 |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1823 def revdiff(self, rev1, rev2): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1824 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
|
1825 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1826 def cmp(self, node, text): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1827 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
|
1828 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1829 def deltaparent(self, rev): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1830 return self._revlog.deltaparent(rev) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1831 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1832 def emitrevisions( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1833 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1834 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1835 nodesorder=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1836 revisiondata=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1837 assumehaveparentrevisions=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1838 deltamode=repository.CG_DELTAMODE_STD, |
46728
45f0d5297698
changegroupv4: add sidedata helpers
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46727
diff
changeset
|
1839 sidedata_helpers=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1840 ): |
39867
5a9ab91e0a45
revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39863
diff
changeset
|
1841 return self._revlog.emitrevisions( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1842 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1843 nodesorder=nodesorder, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1844 revisiondata=revisiondata, |
39867
5a9ab91e0a45
revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39863
diff
changeset
|
1845 assumehaveparentrevisions=assumehaveparentrevisions, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1846 deltamode=deltamode, |
46728
45f0d5297698
changegroupv4: add sidedata helpers
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46727
diff
changeset
|
1847 sidedata_helpers=sidedata_helpers, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1848 ) |
39867
5a9ab91e0a45
revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39863
diff
changeset
|
1849 |
45811
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1850 def addgroup( |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1851 self, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1852 deltas, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1853 linkmapper, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1854 transaction, |
46445
711ba0f1057e
revlog: decouple caching from addrevision callback for addgroup
Joerg Sonnenberger <joerg@bec.de>
parents:
46247
diff
changeset
|
1855 alwayscache=False, |
45811
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1856 addrevisioncb=None, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1857 duplicaterevisioncb=None, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1858 ): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1859 return self._revlog.addgroup( |
45811
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1860 deltas, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1861 linkmapper, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1862 transaction, |
46445
711ba0f1057e
revlog: decouple caching from addrevision callback for addgroup
Joerg Sonnenberger <joerg@bec.de>
parents:
46247
diff
changeset
|
1863 alwayscache=alwayscache, |
45811
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1864 addrevisioncb=addrevisioncb, |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45253
diff
changeset
|
1865 duplicaterevisioncb=duplicaterevisioncb, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1866 ) |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1867 |
39863
9534fe1e5d28
manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
1868 def rawsize(self, rev): |
9534fe1e5d28
manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
1869 return self._revlog.rawsize(rev) |
9534fe1e5d28
manifest: add rawsize() proxy (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39793
diff
changeset
|
1870 |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1871 def getstrippoint(self, minlink): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1872 return self._revlog.getstrippoint(minlink) |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1873 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1874 def strip(self, minlink, transaction): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1875 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
|
1876 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1877 def files(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1878 return self._revlog.files() |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1879 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1880 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
|
1881 if not isinstance(destrevlog, manifestrevlog): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1882 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
|
1883 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1884 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
|
1885 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1886 def storageinfo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1887 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1888 exclusivefiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1889 sharedfiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1890 revisionscount=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1891 trackedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1892 storedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1893 ): |
39874
14e500b58263
revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39871
diff
changeset
|
1894 return self._revlog.storageinfo( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1895 exclusivefiles=exclusivefiles, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1896 sharedfiles=sharedfiles, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1897 revisionscount=revisionscount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1898 trackedsize=trackedsize, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1899 storedsize=storedsize, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1900 ) |
39874
14e500b58263
revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39871
diff
changeset
|
1901 |
39341
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1902 @property |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1903 def indexfile(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1904 return self._revlog.indexfile |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1905 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1906 @indexfile.setter |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1907 def indexfile(self, value): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1908 self._revlog.indexfile = value |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1909 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1910 @property |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1911 def opener(self): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1912 return self._revlog.opener |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1913 |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1914 @opener.setter |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1915 def opener(self, value): |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1916 self._revlog.opener = value |
7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39274
diff
changeset
|
1917 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1918 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
1919 @interfaceutil.implementer(repository.imanifestlog) |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1920 class manifestlog(object): |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1921 """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
|
1922 referenced by commits in the repository. |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1923 |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1924 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
|
1925 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
|
1926 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
|
1927 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
|
1928 |
41041
3913223417ea
manifest: accept narrowmatch into constructor instead of getting from repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
40496
diff
changeset
|
1929 def __init__(self, opener, repo, rootstore, narrowmatch): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1930 self.nodeconstants = repo.nodeconstants |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1931 usetreemanifest = False |
30382
7c7d845f8b64
manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents:
30381
diff
changeset
|
1932 cachesize = 4 |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1933 |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1934 opts = getattr(opener, 'options', None) |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1935 if opts is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1936 usetreemanifest = opts.get(b'treemanifest', usetreemanifest) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1937 cachesize = opts.get(b'manifestcachesize', cachesize) |
39273
071f97d03acb
manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39272
diff
changeset
|
1938 |
071f97d03acb
manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39272
diff
changeset
|
1939 self._treemanifests = usetreemanifest |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1940 |
39779
5ccd791344f3
localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39684
diff
changeset
|
1941 self._rootstore = rootstore |
39348
52860f52ed13
manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39347
diff
changeset
|
1942 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
|
1943 self._narrowmatch = narrowmatch |
30219
3c8811efdddc
manifest: make manifestlog a storecache
Durham Goode <durham@fb.com>
parents:
30209
diff
changeset
|
1944 |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1945 # 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
|
1946 self._dirmancache = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1947 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
|
1948 |
38514
561a450c7b64
manifest: make cachesize a private attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38340
diff
changeset
|
1949 self._cachesize = cachesize |
29837
93b44aa17691
manifest: use property instead of field for manifest revlog storage
Durham Goode <durham@fb.com>
parents:
29836
diff
changeset
|
1950 |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1951 def __getitem__(self, node): |
30304
1a0c1ad57833
manifest: throw LookupError if node not in revlog
Durham Goode <durham@fb.com>
parents:
30221
diff
changeset
|
1952 """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
|
1953 LookupError if not found. |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1954 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1955 return self.get(b'', node) |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1956 |
39263
43387fd2aa1f
manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38821
diff
changeset
|
1957 def get(self, tree, node, verify=True): |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1958 """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
|
1959 LookupError if not found. |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1960 |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1961 `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
|
1962 the revlog |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1963 """ |
39263
43387fd2aa1f
manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38821
diff
changeset
|
1964 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
|
1965 return self._dirmancache[tree][node] |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1966 |
37374
ac42e39b1b77
narrow: move manifestlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37373
diff
changeset
|
1967 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
|
1968 if not self._narrowmatch.visitdir(tree[:-1]): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
1969 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
|
1970 if tree: |
39348
52860f52ed13
manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39347
diff
changeset
|
1971 if self._rootstore._treeondisk: |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1972 if verify: |
39274
61700d525a3b
manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39273
diff
changeset
|
1973 # 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
|
1974 # exist. |
61700d525a3b
manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39273
diff
changeset
|
1975 self.getstorage(tree).rev(node) |
61700d525a3b
manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39273
diff
changeset
|
1976 |
39263
43387fd2aa1f
manifest: rename dir to tree to avoid shadowing built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38821
diff
changeset
|
1977 m = treemanifestctx(self, tree, node) |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1978 else: |
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1979 raise error.Abort( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1980 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1981 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
|
1982 b"manifest" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1983 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1984 % tree |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
1985 ) |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1986 else: |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1987 if verify: |
39274
61700d525a3b
manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39273
diff
changeset
|
1988 # 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
|
1989 self._rootstore.rev(node) |
39274
61700d525a3b
manifest: use rev() instead of nodemap.__contains__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39273
diff
changeset
|
1990 |
39273
071f97d03acb
manifest: rename manifestlog._treeinmem to ._treemanifests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39272
diff
changeset
|
1991 if self._treemanifests: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1992 m = treemanifestctx(self, b'', node) |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1993 else: |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1994 m = manifestctx(self, node) |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1995 |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
1996 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
|
1997 mancache = self._dirmancache.get(tree) |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1998 if not mancache: |
38514
561a450c7b64
manifest: make cachesize a private attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38340
diff
changeset
|
1999 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
|
2000 self._dirmancache[tree] = mancache |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
2001 mancache[node] = m |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2002 return m |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2003 |
39272
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39271
diff
changeset
|
2004 def getstorage(self, tree): |
39348
52860f52ed13
manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39347
diff
changeset
|
2005 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
|
2006 |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
2007 def clearcaches(self, clear_persisted_data=False): |
30380
10c924596e5c
manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents:
30379
diff
changeset
|
2008 self._dirmancache.clear() |
39348
52860f52ed13
manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39347
diff
changeset
|
2009 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
|
2010 |
38556
f2f9bacf0587
manifest: define and implement rev() on manifestlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38532
diff
changeset
|
2011 def rev(self, node): |
39348
52860f52ed13
manifest: rename manifestlog._revlog to _rootstore
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39347
diff
changeset
|
2012 return self._rootstore.rev(node) |
38556
f2f9bacf0587
manifest: define and implement rev() on manifestlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38532
diff
changeset
|
2013 |
44864
97ebdb192b00
nodemap: also warm manifest nodemap with other caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44863
diff
changeset
|
2014 def update_caches(self, transaction): |
97ebdb192b00
nodemap: also warm manifest nodemap with other caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44863
diff
changeset
|
2015 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
|
2016 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2017 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
2018 @interfaceutil.implementer(repository.imanifestrevisionwritable) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2019 class memmanifestctx(object): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2020 def __init__(self, manifestlog): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2021 self._manifestlog = manifestlog |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2022 self._manifestdict = manifestdict() |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2023 |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2024 def _storage(self): |
39347
57301ba47e66
manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39344
diff
changeset
|
2025 return self._manifestlog.getstorage(b'') |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
2026 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2027 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2028 memmf = memmanifestctx(self._manifestlog) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2029 memmf._manifestdict = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2030 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2031 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2032 def read(self): |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2033 return self._manifestdict |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2034 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
2035 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
|
2036 return self._storage().add( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2037 self._manifestdict, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2038 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2039 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2040 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2041 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2042 added, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2043 removed, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2044 match=match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2045 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2046 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
2047 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
2048 @interfaceutil.implementer(repository.imanifestrevisionstored) |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2049 class manifestctx(object): |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2050 """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
|
2051 contents, its parent revs, and its linkrev. |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2052 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2053 |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2054 def __init__(self, manifestlog, node): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2055 self._manifestlog = manifestlog |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2056 self._data = None |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2057 |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2058 self._node = node |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2059 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2060 # 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
|
2061 # 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
|
2062 # lazily. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2063 # self.p1, self.p2 = store.parents(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2064 # rev = store.rev(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2065 # self.linkrev = store.linkrev(rev) |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2066 |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2067 def _storage(self): |
39347
57301ba47e66
manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39344
diff
changeset
|
2068 return self._manifestlog.getstorage(b'') |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
2069 |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2070 def node(self): |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2071 return self._node |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
2072 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2073 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2074 memmf = memmanifestctx(self._manifestlog) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2075 memmf._manifestdict = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2076 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2077 |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2078 @propertycache |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2079 def parents(self): |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2080 return self._storage().parents(self._node) |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2081 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2082 def read(self): |
31114
4a1486c73fdf
manifest: check 'if x is None' instead of 'if not x'
Durham Goode <durham@fb.com>
parents:
30570
diff
changeset
|
2083 if self._data is None: |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2084 if self._node == self._manifestlog.nodeconstants.nullid: |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2085 self._data = manifestdict() |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2086 else: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2087 store = self._storage() |
39349
5886384d1ac5
manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39348
diff
changeset
|
2088 if self._node in store.fulltextcache: |
5886384d1ac5
manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39348
diff
changeset
|
2089 text = pycompat.bytestr(store.fulltextcache[self._node]) |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
2090 else: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2091 text = store.revision(self._node) |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
2092 arraytext = bytearray(text) |
39349
5886384d1ac5
manifest: use fulltextcache instead of _fulltextcache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39348
diff
changeset
|
2093 store.fulltextcache[self._node] = arraytext |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2094 self._data = manifestdict(text) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2095 return self._data |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2096 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2097 def readfast(self, shallow=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2098 """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
|
2099 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
|
2100 read quickly. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
2101 |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
2102 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
|
2103 """ |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2104 store = self._storage() |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2105 r = store.rev(self._node) |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2106 deltaparent = store.deltaparent(r) |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2107 if deltaparent != nullrev and deltaparent in store.parentrevs(r): |
29943
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
2108 return self.readdelta() |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
2109 return self.read() |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
2110 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2111 def readdelta(self, shallow=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2112 """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
|
2113 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
|
2114 if the revlog delta is already p1. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2115 |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2116 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
|
2117 """ |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2118 store = self._storage() |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2119 r = store.rev(self._node) |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2120 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) |
29942
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
2121 return manifestdict(d) |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
2122 |
30350
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
2123 def find(self, key): |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
2124 return self.read().find(key) |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
2125 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2126 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
2127 @interfaceutil.implementer(repository.imanifestrevisionwritable) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2128 class memtreemanifestctx(object): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2129 def __init__(self, manifestlog, dir=b''): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2130 self._manifestlog = manifestlog |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2131 self._dir = dir |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2132 self._treemanifest = treemanifest(manifestlog.nodeconstants) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2133 |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2134 def _storage(self): |
39347
57301ba47e66
manifest: use public API for obtaining storage object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39344
diff
changeset
|
2135 return self._manifestlog.getstorage(b'') |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
2136 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2137 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2138 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2139 memmf._treemanifest = self._treemanifest.copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2140 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2141 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2142 def read(self): |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2143 return self._treemanifest |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
2144 |
39684
24870f1be088
narrow: when writing treemanifests, skip inspecting directories outside narrow
spectral <spectral@google.com>
parents:
39539
diff
changeset
|
2145 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
|
2146 def readtree(dir, node): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2147 return self._manifestlog.get(dir, node).read() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2148 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2149 return self._storage().add( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2150 self._treemanifest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2151 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2152 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2153 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2154 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2155 added, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2156 removed, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2157 readtree=readtree, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2158 match=match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2159 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2160 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
2161 |
38532
c82ea938efbb
repository: define manifest interfaces
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38514
diff
changeset
|
2162 @interfaceutil.implementer(repository.imanifestrevisionstored) |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2163 class treemanifestctx(object): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2164 def __init__(self, manifestlog, dir, node): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2165 self._manifestlog = manifestlog |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2166 self._dir = dir |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2167 self._data = None |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2168 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2169 self._node = node |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2170 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2171 # 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
|
2172 # we can instantiate treemanifestctx objects for directories we don't |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2173 # have on disk. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2174 # self.p1, self.p2 = store.parents(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2175 # rev = store.rev(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2176 # self.linkrev = store.linkrev(rev) |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2177 |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2178 def _storage(self): |
37373
c50078fc32f3
narrow: move manifestrevlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37372
diff
changeset
|
2179 narrowmatch = self._manifestlog._narrowmatch |
c50078fc32f3
narrow: move manifestrevlog overrides to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37372
diff
changeset
|
2180 if not narrowmatch.always(): |
42363
27d6956d386b
match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41970
diff
changeset
|
2181 if not narrowmatch.visitdir(self._dir[:-1]): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2182 return excludedmanifestrevlog( |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2183 self._manifestlog.nodeconstants, self._dir |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2184 ) |
39272
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39271
diff
changeset
|
2185 return self._manifestlog.getstorage(self._dir) |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
2186 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2187 def read(self): |
31114
4a1486c73fdf
manifest: check 'if x is None' instead of 'if not x'
Durham Goode <durham@fb.com>
parents:
30570
diff
changeset
|
2188 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
|
2189 store = self._storage() |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2190 if self._node == self._manifestlog.nodeconstants.nullid: |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2191 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
|
2192 # TODO accessing non-public API |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2193 elif store._treeondisk: |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2194 m = treemanifest(self._manifestlog.nodeconstants, dir=self._dir) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2195 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2196 def gettext(): |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2197 return store.revision(self._node) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2198 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2199 def readsubtree(dir, subm): |
30414
a1beadaa4061
manifest: change treemanifestctx to construct subtrees from the manifestlog
Durham Goode <durham@fb.com>
parents:
30413
diff
changeset
|
2200 # 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
|
2201 # 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
|
2202 return self._manifestlog.get(dir, subm, verify=False).read() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2203 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2204 m.read(gettext, readsubtree) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2205 m.setnode(self._node) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2206 self._data = m |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2207 else: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2208 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
|
2209 text = pycompat.bytestr(store.fulltextcache[self._node]) |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
2210 else: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2211 text = store.revision(self._node) |
38821
0a57945aaf7f
manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents:
38657
diff
changeset
|
2212 arraytext = bytearray(text) |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2213 store.fulltextcache[self._node] = arraytext |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2214 self._data = treemanifest( |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2215 self._manifestlog.nodeconstants, dir=self._dir, text=text |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2216 ) |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2217 |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
2218 return self._data |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2219 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2220 def node(self): |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2221 return self._node |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
2222 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2223 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
2224 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2225 memmf._treemanifest = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2226 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
2227 |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2228 @propertycache |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2229 def parents(self): |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2230 return self._storage().parents(self._node) |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
2231 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2232 def readdelta(self, shallow=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2233 """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
|
2234 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
|
2235 if the revlog delta is already p1. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2236 |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2237 If `shallow` is True, this will read the delta for this directory, |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2238 without recursively reading subdirectory manifests. Instead, any |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2239 subdirectory entry will be reported as it appears in the manifest, i.e. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2240 the subdirectory will be reported among files and distinguished only by |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
2241 its 't' flag. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2242 """ |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2243 store = self._storage() |
36404
0147a4730420
cleanup: say goodbye to manifestv2 format
Augie Fackler <augie@google.com>
parents:
36334
diff
changeset
|
2244 if shallow: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2245 r = store.rev(self._node) |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2246 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2247 return manifestdict(d) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2248 else: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2249 # 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
|
2250 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
|
2251 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
|
2252 m1 = self.read() |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2253 md = treemanifest(self._manifestlog.nodeconstants, dir=self._dir) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
2254 for f, ((n0, fl0), (n1, fl1)) in pycompat.iteritems(m0.diff(m1)): |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2255 if n1: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2256 md[f] = n1 |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2257 if fl1: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2258 md.setflag(f, fl1) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2259 return md |
29942
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
2260 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2261 def readfast(self, shallow=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2262 """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
|
2263 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
|
2264 read quickly. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
2265 |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
2266 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
|
2267 and not any submanifests. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45811
diff
changeset
|
2268 """ |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2269 store = self._storage() |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2270 r = store.rev(self._node) |
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2271 deltaparent = store.deltaparent(r) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2272 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
|
2273 return self.readdelta(shallow=shallow) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2274 |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2275 if shallow: |
39344
eb9b8679c852
manifest: change terminology for storage in context classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39343
diff
changeset
|
2276 return manifestdict(store.revision(self._node)) |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2277 else: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
2278 return self.read() |
29943
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
2279 |
30350
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
2280 def find(self, key): |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
2281 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
|
2282 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2283 |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2284 class excludeddir(treemanifest): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2285 """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
|
2286 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2287 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
|
2288 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
|
2289 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
|
2290 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
|
2291 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
|
2292 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
|
2293 whose contents are unknown. |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2294 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2295 |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2296 def __init__(self, nodeconstants, dir, node): |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2297 super(excludeddir, self).__init__(nodeconstants, dir) |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2298 self._node = node |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2299 # 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
|
2300 # 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
|
2301 self._files[b''] = node |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2302 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
|
2303 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2304 # 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
|
2305 # 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
|
2306 # 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
|
2307 # 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
|
2308 # super type's copy(). |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2309 def copy(self): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2310 return self |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2311 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2312 |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2313 class excludeddirmanifestctx(treemanifestctx): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2314 """context wrapper for excludeddir - see that docstring for rationale""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2315 |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2316 def __init__(self, nodeconstants, dir, node): |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2317 self.nodeconstants = nodeconstants |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2318 self._dir = dir |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2319 self._node = node |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2320 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2321 def read(self): |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2322 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
|
2323 |
46247
a3ccbac659d8
narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46096
diff
changeset
|
2324 def readfast(self, shallow=False): |
a3ccbac659d8
narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46096
diff
changeset
|
2325 # 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
|
2326 return self.read() |
a3ccbac659d8
narrow: overwrite readfast in excludeddirmanifestctx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46096
diff
changeset
|
2327 |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2328 def write(self, *args): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2329 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2330 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
|
2331 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42824
diff
changeset
|
2332 |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2333 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2334 class excludedmanifestrevlog(manifestrevlog): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2335 """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
|
2336 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2337 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
|
2338 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
|
2339 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
|
2340 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
|
2341 outside the narrowspec. |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2342 """ |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2343 |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2344 def __init__(self, nodeconstants, dir): |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46728
diff
changeset
|
2345 self.nodeconstants = nodeconstants |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2346 self._dir = dir |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2347 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2348 def __len__(self): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2349 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2350 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
|
2351 ) |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2352 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2353 def rev(self, node): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2354 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2355 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
|
2356 ) |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2357 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2358 def linkrev(self, node): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2359 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2360 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
|
2361 ) |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2362 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2363 def node(self, rev): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2364 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2365 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
|
2366 ) |
37372
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2367 |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2368 def add(self, *args, **kwargs): |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2369 # 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
|
2370 # 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
|
2371 # _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
|
2372 # 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
|
2373 # in excludeddir instances). |
1b2fa531fd7a
narrow: move excludeddir and related classes to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
37272
diff
changeset
|
2374 pass |