Mercurial > hg-stable
annotate mercurial/manifest.py @ 32548:e70d6dbde713
bundle2: move function building obsmarker-part in the bundle2 module
We move it next to similar part building functions. We will need it for the
"writenewbundle" logic. This will allow us to easily include obsmarkers in
on-disk bundle, a necessary step before having `hg strip` also operate on
markers.
(Yes, the bundle2 module was already too large, but there any many
interdependencies between its components so it is non-trivial to split, this is
a quest for another adventure.)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 28 May 2017 11:48:18 -0700 |
parents | df448de7cf3b |
children | 260a6f715bd2 |
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 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
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 |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
11 import os |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
12 import struct |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
13 |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
14 from .i18n import _ |
31536
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
15 from .node import ( |
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
16 bin, |
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
17 hex, |
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
18 ) |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
19 from . import ( |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
20 error, |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
21 mdiff, |
32411
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
32292
diff
changeset
|
22 policy, |
27502
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
23 revlog, |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
24 util, |
2df7f5c09c34
manifest: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27466
diff
changeset
|
25 ) |
79 | 26 |
32411
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
32292
diff
changeset
|
27 parsers = policy.importmod(r'parsers') |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
28 propertycache = util.propertycache |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
29 |
24572
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
30 def _parsev1(data): |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
31 # 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
|
32 # 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
|
33 # 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
|
34 # 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
|
35 # the pure version. |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
36 if data and data[-1] != '\n': |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
37 raise ValueError('Manifest did not end in a newline.') |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
38 prev = None |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
39 for l in data.splitlines(): |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
40 if prev is not None and prev > l: |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
41 raise ValueError('Manifest lines not in sorted order.') |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
42 prev = l |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
43 f, n = l.split('\0') |
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
44 if len(n) > 40: |
31375
45347d4a4f07
manifest: now that node.bin is available, use it directly
Augie Fackler <augie@google.com>
parents:
31374
diff
changeset
|
45 yield f, bin(n[:40]), n[40:] |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
46 else: |
31375
45347d4a4f07
manifest: now that node.bin is available, use it directly
Augie Fackler <augie@google.com>
parents:
31374
diff
changeset
|
47 yield f, bin(n), '' |
24524
63b6031384fc
manifest: extract method for parsing manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24502
diff
changeset
|
48 |
24572
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
49 def _parsev2(data): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
50 metadataend = data.find('\n') |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
51 # Just ignore metadata for now |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
52 pos = metadataend + 1 |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
53 prevf = '' |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
54 while pos < len(data): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
55 end = data.find('\n', pos + 1) # +1 to skip stem length byte |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
56 if end == -1: |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
57 raise ValueError('Manifest ended with incomplete file entry.') |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
58 stemlen = ord(data[pos]) |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
59 items = data[pos + 1:end].split('\0') |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
60 f = prevf[:stemlen] + items[0] |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
61 if prevf > f: |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
62 raise ValueError('Manifest entries not in sorted order.') |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
63 fl = items[1] |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
64 # Just ignore metadata (items[2:] for now) |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
65 n = data[end + 1:end + 21] |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
66 yield f, n, fl |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
67 pos = end + 22 |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
68 prevf = f |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
69 |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
70 def _parse(data): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
71 """Generates (path, node, flags) tuples from a manifest text""" |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
72 if data.startswith('\0'): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
73 return iter(_parsev2(data)) |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
74 else: |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
75 return iter(_parsev1(data)) |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
76 |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
77 def _text(it, usemanifestv2): |
24525
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
78 """Given an iterator over (path, node, flags) tuples, returns a manifest |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
79 text""" |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
80 if usemanifestv2: |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
81 return _textv2(it) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
82 else: |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
83 return _textv1(it) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
84 |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
85 def _textv1(it): |
24525
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
86 files = [] |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
87 lines = [] |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
88 _hex = revlog.hex |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
89 for f, n, fl in it: |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
90 files.append(f) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
91 # 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
|
92 # be sure to check the templates/ dir again (especially *-raw.tmpl) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
93 lines.append("%s\0%s%s\n" % (f, _hex(n), fl)) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
94 |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
95 _checkforbidden(files) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
96 return ''.join(lines) |
e118f74d246f
manifest: extract method for creating manifest text
Martin von Zweigbergk <martinvonz@google.com>
parents:
24524
diff
changeset
|
97 |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
98 def _textv2(it): |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
99 files = [] |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
100 lines = ['\0\n'] |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
101 prevf = '' |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
102 for f, n, fl in it: |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
103 files.append(f) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
104 stem = os.path.commonprefix([prevf, f]) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
105 stemlen = min(len(stem), 255) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
106 lines.append("%c%s\0%s\n%s\n" % (stemlen, f[stemlen:], fl, n)) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
107 prevf = f |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
108 _checkforbidden(files) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
109 return ''.join(lines) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
110 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
111 class lazymanifestiter(object): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
112 def __init__(self, lm): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
113 self.pos = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
114 self.lm = lm |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
115 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
116 def __iter__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
117 return self |
24223
b4df0d0c49e7
manifest: move parsing functions up in file
Augie Fackler <augie@google.com>
parents:
24215
diff
changeset
|
118 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
119 def next(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
120 try: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
121 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
|
122 except IndexError: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
123 raise StopIteration |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
124 if pos == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
125 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
126 return data[0] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
127 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
128 zeropos = data.find('\x00', pos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
129 return data[pos:zeropos] |
24224
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
130 |
31373
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
131 __next__ = next |
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
132 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
133 class lazymanifestiterentries(object): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
134 def __init__(self, lm): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
135 self.lm = lm |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
136 self.pos = 0 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
137 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
138 def __iter__(self): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
139 return self |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
140 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
141 def next(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
142 try: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
143 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
|
144 except IndexError: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
145 raise StopIteration |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
146 if pos == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
147 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
148 return data |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
149 zeropos = data.find('\x00', pos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
150 hashval = unhexlify(data, self.lm.extrainfo[self.pos], |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
151 zeropos + 1, 40) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
152 flags = self.lm._getflags(data, self.pos, zeropos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
153 self.pos += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
154 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
|
155 |
31373
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
156 __next__ = next |
91874c247d61
manifest: add __next__ methods for Python 3
Augie Fackler <augie@google.com>
parents:
31361
diff
changeset
|
157 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
158 def unhexlify(data, extra, pos, length): |
31374
28e3471a21ef
manifest: use node.bin instead of .decode('hex')
Augie Fackler <augie@google.com>
parents:
31373
diff
changeset
|
159 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
|
160 if extra: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
161 s += chr(extra & 0xff) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
162 return s |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
163 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
164 def _cmp(a, b): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
165 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
|
166 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
167 class _lazymanifest(object): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
168 def __init__(self, data, positions=None, extrainfo=None, extradata=None): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
169 if positions is None: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
170 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
|
171 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
|
172 self.data = data |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
173 self.extradata = [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
174 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
175 self.positions = positions[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
176 self.extrainfo = extrainfo[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
177 self.extradata = extradata[:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
178 self.data = data |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
179 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
180 def findlines(self, data): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
181 if not data: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
182 return [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
183 pos = data.find("\n") |
31361
667e88568087
manifest: unbreak pure-python manifest parsing on Python 3
Augie Fackler <augie@google.com>
parents:
31355
diff
changeset
|
184 if pos == -1 or data[-1:] != '\n': |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
185 raise ValueError("Manifest did not end in a newline.") |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
186 positions = [0] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
187 prev = data[:data.find('\x00')] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
188 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
|
189 positions.append(pos + 1) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
190 nexts = data[pos + 1:data.find('\x00', pos + 1)] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
191 if nexts < prev: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
192 raise ValueError("Manifest lines not in sorted order.") |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
193 prev = nexts |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
194 pos = data.find("\n", pos + 1) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
195 return positions |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
196 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
197 def _get(self, index): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
198 # 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
|
199 # 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
|
200 # 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
|
201 pos = self.positions[index] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
202 if pos >= 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
203 return self.data, pos |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
204 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
|
205 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
206 def _getkey(self, pos): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
207 if pos >= 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
208 return self.data[pos:self.data.find('\x00', pos + 1)] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
209 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
|
210 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
211 def bsearch(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
212 first = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
213 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
|
214 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
215 while first <= last: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
216 midpoint = (first + last)//2 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
217 nextpos = self.positions[midpoint] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
218 candidate = self._getkey(nextpos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
219 r = _cmp(key, candidate) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
220 if r == 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
221 return midpoint |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
222 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
223 if r < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
224 last = midpoint - 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
225 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
226 first = midpoint + 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
227 return -1 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
228 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
229 def bsearch2(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
230 # 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
|
231 # done for performance reasons |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
232 first = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
233 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
|
234 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
235 while first <= last: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
236 midpoint = (first + last)//2 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
237 nextpos = self.positions[midpoint] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
238 candidate = self._getkey(nextpos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
239 r = _cmp(key, candidate) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
240 if r == 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
241 return (midpoint, True) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
242 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
243 if r < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
244 last = midpoint - 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
245 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
246 first = midpoint + 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
247 return (first, False) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
248 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
249 def __contains__(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
250 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
|
251 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
252 def _getflags(self, data, needle, pos): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
253 start = pos + 41 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
254 end = data.find("\n", start) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
255 if end == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
256 end = len(data) - 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
257 if start == end: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
258 return '' |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
259 return self.data[start:end] |
24297
0178f500d61e
lazymanifest: fix pure hg iterkeys()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
260 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
261 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
|
262 if not isinstance(key, bytes): |
ef50b491c17d
manifest: ensure paths are bytes (not str) in pure parser
Augie Fackler <augie@google.com>
parents:
31375
diff
changeset
|
263 raise TypeError("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
|
264 needle = self.bsearch(key) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
265 if needle == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
266 raise KeyError |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
267 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
|
268 if pos == -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
269 return (data[1], data[2]) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
270 zeropos = data.find('\x00', pos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
271 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
|
272 assert len(self.extrainfo) == len(self.positions) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
273 hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, 40) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
274 flags = self._getflags(data, needle, zeropos) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
275 return (hashval, flags) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
276 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
277 def __delitem__(self, key): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
278 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
|
279 if not found: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
280 raise KeyError |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
281 cur = self.positions[needle] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
282 self.positions = self.positions[:needle] + self.positions[needle + 1:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
283 self.extrainfo = self.extrainfo[:needle] + self.extrainfo[needle + 1:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
284 if cur >= 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
285 self.data = self.data[:cur] + '\x00' + self.data[cur + 1:] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
286 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
287 def __setitem__(self, key, value): |
31537
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
288 if not isinstance(key, bytes): |
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
289 raise TypeError("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
|
290 if not isinstance(value, tuple) or len(value) != 2: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
291 raise TypeError("Manifest values must be a tuple of (node, flags).") |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
292 hashval = value[0] |
31537
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
293 if not isinstance(hashval, bytes) or not 20 <= len(hashval) <= 22: |
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
294 raise TypeError("node must be a 20-byte byte string") |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
295 flags = value[1] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
296 if len(hashval) == 22: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
297 hashval = hashval[:-1] |
31537
326bca5477d0
manifest: refer to bytestrings as bytes, not str
Augie Fackler <augie@google.com>
parents:
31536
diff
changeset
|
298 if not isinstance(flags, bytes) or len(flags) > 1: |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
299 raise TypeError("flags must a 0 or 1 byte string, got %r", flags) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
300 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
|
301 if found: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
302 # put the item |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
303 pos = self.positions[needle] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
304 if pos < 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
305 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
|
306 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
307 # just don't bother |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
308 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
|
309 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
|
310 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
311 # 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
|
312 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
|
313 self.positions = (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
|
314 + self.positions[needle:]) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
315 self.extrainfo = (self.extrainfo[:needle] + [0] + |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
316 self.extrainfo[needle:]) |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
317 |
2831 | 318 def copy(self): |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
319 # XXX call _compact like in C? |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
320 return _lazymanifest(self.data, self.positions, self.extrainfo, |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
321 self.extradata) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
322 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
323 def _compact(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
324 # hopefully not called TOO often |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
325 if len(self.extradata) == 0: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
326 return |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
327 l = [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
328 last_cut = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
329 i = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
330 offset = 0 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 cur = self.positions[i] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
335 last_cut = cur |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
336 while True: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
337 self.positions[i] = offset |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
338 i += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
339 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
|
340 break |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
341 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
|
342 cur = self.positions[i] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
343 end_cut = self.data.find('\n', cur) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
344 if end_cut != -1: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
345 end_cut += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
346 offset += end_cut - cur |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
347 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
|
348 else: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
349 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
|
350 cur = self.positions[i] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
351 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
|
352 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
|
353 self.positions[i] = offset |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
354 if len(t[1]) > 20: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
355 self.extrainfo[i] = ord(t[1][21]) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
356 offset += len(l[-1]) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
357 i += 1 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
358 self.data = ''.join(l) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
359 self.extradata = [] |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
360 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
361 def _pack(self, d): |
31536
160e7ad941e9
manifest: use node.hex instead of .encode('hex')
Augie Fackler <augie@google.com>
parents:
31483
diff
changeset
|
362 return d[0] + '\x00' + hex(d[1][:20]) + d[2] + '\n' |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
363 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
364 def text(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
365 self._compact() |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
366 return self.data |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
367 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
368 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
|
369 '''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
|
370 # 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
|
371 diff = {} |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
372 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
373 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
|
374 if fn not in m2: |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
375 diff[fn] = (e1, flags), (None, '') |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
376 else: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
377 e2 = m2[fn] |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
378 if (e1, flags) != e2: |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
379 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
|
380 elif clean: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
381 diff[fn] = None |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
382 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
383 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
|
384 if fn not in self: |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
385 diff[fn] = (None, ''), (e2, flags) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
386 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
387 return diff |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
388 |
30042
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
389 def iterentries(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
390 return lazymanifestiterentries(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
391 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
392 def iterkeys(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
393 return lazymanifestiter(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
394 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
395 def __iter__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
396 return lazymanifestiter(self) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
397 |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
398 def __len__(self): |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
399 return len(self.positions) |
d24e03da24b5
lazymanifest: write a more efficient, pypy friendly version of lazymanifest
Maciej Fijalkowski <fijall@gmail.com>
parents:
30002
diff
changeset
|
400 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
401 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
|
402 # XXX should be optimized |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
403 c = _lazymanifest('') |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
404 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
|
405 if filterfn(f): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
406 c[f] = n, fl |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
407 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
408 |
24226
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
409 try: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
410 _lazymanifest = parsers.lazymanifest |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
411 except AttributeError: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
412 pass |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
413 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
414 class manifestdict(object): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
415 def __init__(self, data=''): |
24572
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
416 if data.startswith('\0'): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
417 #_lazymanifest can not parse v2 |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
418 self._lm = _lazymanifest('') |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
419 for f, n, fl in _parsev2(data): |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
420 self._lm[f] = n, fl |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
421 else: |
b83679eb5f86
manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24571
diff
changeset
|
422 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
|
423 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
424 def __getitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
425 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
|
426 |
24277
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
427 def find(self, key): |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
428 return self._lm[key] |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
429 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
430 def __len__(self): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
431 return len(self._lm) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
432 |
30341
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
433 def __nonzero__(self): |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
434 # 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
|
435 # makes it easier for extensions to override. |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
436 return len(self._lm) != 0 |
b19291e5d506
manifest: add __nonzero__ method
Durham Goode <durham@fb.com>
parents:
30309
diff
changeset
|
437 |
31483
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31376
diff
changeset
|
438 __bool__ = __nonzero__ |
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31376
diff
changeset
|
439 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
440 def __setitem__(self, key, node): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
441 self._lm[key] = node, self.flags(key, '') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
442 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
443 def __contains__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
444 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
|
445 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
446 def __delitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
447 del self._lm[key] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
448 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
449 def __iter__(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
450 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
|
451 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
452 def iterkeys(self): |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
453 return self._lm.iterkeys() |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
454 |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
455 def keys(self): |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
456 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
|
457 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
458 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
|
459 '''Set of files in this manifest that are not in the other''' |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
460 if match: |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
461 m1 = self.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
462 m2 = m2.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
463 return m1.filesnotin(m2) |
29056
e2178f7d17c0
manifest: improve filesnotin performance by using lazymanifest diff
Tony Tung <tonytung@merly.org>
parents:
28240
diff
changeset
|
464 diff = self.diff(m2) |
e2178f7d17c0
manifest: improve filesnotin performance by using lazymanifest diff
Tony Tung <tonytung@merly.org>
parents:
28240
diff
changeset
|
465 files = set(filepath |
e2178f7d17c0
manifest: improve filesnotin performance by using lazymanifest diff
Tony Tung <tonytung@merly.org>
parents:
28240
diff
changeset
|
466 for filepath, hashflags in diff.iteritems() |
e2178f7d17c0
manifest: improve filesnotin performance by using lazymanifest diff
Tony Tung <tonytung@merly.org>
parents:
28240
diff
changeset
|
467 if hashflags[1][0] is None) |
24184
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
468 return files |
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
469 |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
470 @propertycache |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
471 def _dirs(self): |
24635
21e1ece30f8c
util: move dirs() and finddirs() from scmutil to util
Drew Gottlieb <drgott@google.com>
parents:
24600
diff
changeset
|
472 return util.dirs(self) |
24322
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
473 |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
474 def dirs(self): |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
475 return self._dirs |
f263814c72ac
manifest: add dirs() to manifestdict
Drew Gottlieb <drgott@google.com>
parents:
24298
diff
changeset
|
476 |
24324
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
477 def hasdir(self, dir): |
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
478 return dir in self._dirs |
149cc171e4a0
manifest: add manifestdict.hasdir() method
Drew Gottlieb <drgott@google.com>
parents:
24322
diff
changeset
|
479 |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
480 def _filesfastpath(self, match): |
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
481 '''Checks whether we can correctly and quickly iterate over matcher |
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
482 files instead of over manifest files.''' |
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
483 files = match.files() |
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
484 return (len(files) < 100 and (match.isexact() or |
25276
c436ba9d6ac0
manifest: use match.prefix() instead of 'not match.anypats()'
Martin von Zweigbergk <martinvonz@google.com>
parents:
25222
diff
changeset
|
485 (match.prefix() and all(fn in self for fn in files)))) |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
486 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
487 def walk(self, match): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
488 '''Generates matching file names. |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
489 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
490 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
|
491 an entirely new manifest. |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
492 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
493 It also reports nonexistent files by marking them bad with match.bad(). |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
494 ''' |
24683
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
495 if match.always(): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
496 for f in iter(self): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
497 yield f |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
498 return |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
499 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
500 fset = set(match.files()) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
501 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
502 # 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
|
503 if self._filesfastpath(match): |
24667
19c5b0913960
manifest.walk: join nested if-conditions
Martin von Zweigbergk <martinvonz@google.com>
parents:
24666
diff
changeset
|
504 for fn in sorted(fset): |
19c5b0913960
manifest.walk: join nested if-conditions
Martin von Zweigbergk <martinvonz@google.com>
parents:
24666
diff
changeset
|
505 yield fn |
24682
aef3d1469773
manifest.walk: use return instead of StopIteration in generator
Martin von Zweigbergk <martinvonz@google.com>
parents:
24670
diff
changeset
|
506 return |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
507 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
508 for fn in self: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
509 if fn in fset: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
510 # specified pattern is the exact name |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
511 fset.remove(fn) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
512 if match(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
513 yield fn |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
514 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
515 # for dirstate.walk, files=['.'] means "walk the whole tree". |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
516 # follow that here, too |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
517 fset.discard('.') |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
518 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
519 for fn in sorted(fset): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
520 if not self.hasdir(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
521 match.bad(fn, None) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
522 |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
523 def matches(self, match): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
524 '''generate a new manifest filtered by the match argument''' |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
525 if match.always(): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
526 return self.copy() |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
527 |
24685
b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24684
diff
changeset
|
528 if self._filesfastpath(match): |
24666
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
529 m = manifestdict() |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
530 lm = self._lm |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
531 for fn in match.files(): |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
532 if fn in lm: |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
533 m._lm[fn] = lm[fn] |
3092885b5b32
manifestdict: inline _intersectfiles()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24665
diff
changeset
|
534 return m |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
535 |
24700
32b268cbff00
manifestdict: drop empty-string argument when creating empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24685
diff
changeset
|
536 m = manifestdict() |
24664
ea4a7c8909ae
manifestdict.matches: avoid name 'lm' for a not-lazymanifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24647
diff
changeset
|
537 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
|
538 return m |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
539 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
540 def diff(self, m2, match=None, clean=False): |
23756
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
541 '''Finds changes between the current manifest and m2. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
542 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
543 Args: |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 string. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
554 ''' |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
555 if match: |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
556 m1 = self.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
557 m2 = m2.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
558 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
|
559 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
|
560 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
561 def setflag(self, key, flag): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
562 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
|
563 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
564 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
|
565 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
566 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
|
567 except KeyError: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
568 return default |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
569 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
570 def flags(self, key, default=''): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
571 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
572 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
|
573 except KeyError: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
574 return default |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
575 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
576 def copy(self): |
24700
32b268cbff00
manifestdict: drop empty-string argument when creating empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
24685
diff
changeset
|
577 c = manifestdict() |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
578 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
|
579 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
580 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
581 def iteritems(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
582 return (x[:2] for x in self._lm.iterentries()) |
2831 | 583 |
28203
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
584 def iterentries(self): |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
585 return self._lm.iterentries() |
7297e9e13a8a
verify: check directory manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27502
diff
changeset
|
586 |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
587 def text(self, usemanifestv2=False): |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
588 if usemanifestv2: |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
589 return _textv2(self._lm.iterentries()) |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
590 else: |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
591 # use (probably) native version for v1 |
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
592 return self._lm.text() |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
593 |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
594 def fastdelta(self, base, changes): |
31790
6bfea18df609
manifest: update comment to be about bytearray
Martin von Zweigbergk <martinvonz@google.com>
parents:
31655
diff
changeset
|
595 """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
|
596 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
|
597 """ |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
598 delta = [] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
599 dstart = None |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
600 dend = None |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
601 dline = [""] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
602 start = 0 |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
603 # zero copy representation of base as a buffer |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
604 addbuf = util.buffer(base) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
605 |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
606 changes = list(changes) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
607 if len(changes) < 1000: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
608 # 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
|
609 # each line and creates the deltas |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
610 for f, todelete in changes: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
611 # 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
|
612 start, end = _msearch(addbuf, f, start) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
613 if not todelete: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
614 h, fl = self._lm[f] |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
615 l = "%s\0%s%s\n" % (f, revlog.hex(h), fl) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
616 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
617 if start == end: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
618 # 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
|
619 raise AssertionError( |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
620 _("failed to remove %s from manifest") % f) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
621 l = "" |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
622 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
|
623 if dend < end: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
624 dend = end |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
625 if l: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
626 dline.append(l) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
627 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
628 if dstart is not None: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
629 delta.append([dstart, dend, "".join(dline)]) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
630 dstart = start |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
631 dend = end |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
632 dline = [l] |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
633 |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
634 if dstart is not None: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
635 delta.append([dstart, dend, "".join(dline)]) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
636 # 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
|
637 deltatext, arraytext = _addlistdelta(base, delta) |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
638 else: |
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
639 # 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
|
640 # diff it. |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
641 arraytext = bytearray(self.text()) |
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
642 deltatext = mdiff.textdiff( |
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
643 util.buffer(base), util.buffer(arraytext)) |
26871
1cbf144fd8a1
manifest: skip fastdelta if the change is large
Durham Goode <durham@fb.com>
parents:
26402
diff
changeset
|
644 |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
645 return arraytext, deltatext |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
646 |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
647 def _msearch(m, s, lo=0, hi=None): |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
648 '''return a tuple (start, end) that says where to find s within m. |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
649 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 |
31655
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
654 m should be a buffer, a memoryview or a byte string. |
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
655 s is a byte string''' |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
656 def advance(i, c): |
31655
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
657 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
|
658 i += 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
659 return i |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
660 if not s: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
661 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
662 lenm = len(m) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
663 if not hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
664 hi = lenm |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
665 while lo < hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
666 mid = (lo + hi) // 2 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
667 start = mid |
31655
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
668 while start > 0 and m[start - 1:start] != '\n': |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
669 start -= 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
670 end = advance(start, '\0') |
31655
23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
Yuya Nishihara <yuya@tcha.org>
parents:
31537
diff
changeset
|
671 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
|
672 # 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
|
673 # this translates to the bisect lo = mid + 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
674 lo = advance(end + 40, '\n') + 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
675 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
676 # 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
|
677 hi = start |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
678 end = advance(lo, '\0') |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
679 found = m[lo:end] |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
680 if s == found: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
681 # 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
|
682 end = advance(end + 40, '\n') |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
683 return (lo, end + 1) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
684 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
685 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
686 |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
687 def _checkforbidden(l): |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
688 """Check filenames for illegal characters.""" |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
689 for f in l: |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
690 if '\n' in f or '\r' in f: |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
691 raise error.RevlogError( |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
692 _("'\\n' and '\\r' disallowed in filenames: %r") % f) |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
693 |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
694 |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
695 # 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
|
696 # 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
|
697 def _addlistdelta(addlist, x): |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
698 # 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
|
699 # than repeatedly modifying the existing one |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
700 currentposition = 0 |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
701 newaddlist = bytearray() |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
702 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
703 for start, end, content in x: |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
704 newaddlist += addlist[currentposition:start] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
705 if content: |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
706 newaddlist += bytearray(content) |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
707 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
708 currentposition = end |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
709 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
710 newaddlist += addlist[currentposition:] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
711 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
712 deltatext = "".join(struct.pack(">lll", start, end, len(content)) |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
713 + content for start, end, content in x) |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
714 return deltatext, newaddlist |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
715 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
716 def _splittopdir(f): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
717 if '/' in f: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
718 dir, subpath = f.split('/', 1) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
719 return dir + '/', subpath |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
720 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
721 return '', f |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
722 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
723 _noop = lambda s: None |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
724 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
725 class treemanifest(object): |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
726 def __init__(self, dir='', text=''): |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
727 self._dir = dir |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
728 self._node = revlog.nullid |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
729 self._loadfunc = _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
730 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
|
731 self._dirty = False |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
732 self._dirs = {} |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
733 # 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
|
734 self._files = {} |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
735 self._flags = {} |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
736 if text: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
737 def readsubtree(subdir, subm): |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
738 raise AssertionError('treemanifest constructor only accepts ' |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
739 'flat manifests') |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
740 self.parse(text, readsubtree) |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
741 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
|
742 |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
743 def _subpath(self, path): |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
744 return self._dir + path |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
745 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
746 def __len__(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
747 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
748 size = len(self._files) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
749 for m in self._dirs.values(): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
750 size += m.__len__() |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
751 return size |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
752 |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
753 def _isempty(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
754 self._load() # for consistency; already loaded by all callers |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
755 return (not self._files and (not self._dirs or |
25151
6eb4bdad198f
cleanup: use __builtins__.all instead of util.all
Augie Fackler <augie@google.com>
parents:
25119
diff
changeset
|
756 all(m._isempty() for m in self._dirs.values()))) |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
757 |
26400
6f9d9e2a661f
manifest: add id(self) to treemanifest __repr__
Augie Fackler <augie@google.com>
parents:
26199
diff
changeset
|
758 def __repr__(self): |
6f9d9e2a661f
manifest: add id(self) to treemanifest __repr__
Augie Fackler <augie@google.com>
parents:
26199
diff
changeset
|
759 return ('<treemanifest dir=%s, node=%s, loaded=%s, dirty=%s at 0x%x>' % |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
760 (self._dir, revlog.hex(self._node), |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
761 bool(self._loadfunc is _noop), |
26400
6f9d9e2a661f
manifest: add id(self) to treemanifest __repr__
Augie Fackler <augie@google.com>
parents:
26199
diff
changeset
|
762 self._dirty, id(self))) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
763 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
764 def dir(self): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
765 '''The directory that this tree manifest represents, including a |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
766 trailing '/'. Empty string for the repo root directory.''' |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
767 return self._dir |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
768 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
769 def node(self): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
770 '''This node of this instance. nullid for unsaved instances. Should |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
771 be updated when the instance is read or written from a revlog. |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
772 ''' |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
773 assert not self._dirty |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
774 return self._node |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
775 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
776 def setnode(self, node): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
777 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
|
778 self._dirty = False |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
779 |
28206
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
780 def iterentries(self): |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
781 self._load() |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
782 for p, n in sorted(self._dirs.items() + self._files.items()): |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
783 if p in self._files: |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
784 yield self._subpath(p), n, self._flags.get(p, '') |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
785 else: |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
786 for x in n.iterentries(): |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
787 yield x |
8ab91d9290ce
treemanifest: implement iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28203
diff
changeset
|
788 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
789 def iteritems(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
790 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
791 for p, n in sorted(self._dirs.items() + self._files.items()): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
792 if p in self._files: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
793 yield self._subpath(p), n |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
794 else: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
795 for f, sn in n.iteritems(): |
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
796 yield f, sn |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
797 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
798 def iterkeys(self): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
799 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
800 for p in sorted(self._dirs.keys() + self._files.keys()): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
801 if p in self._files: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
802 yield self._subpath(p) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
803 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
804 for f in self._dirs[p].iterkeys(): |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
805 yield f |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
806 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
807 def keys(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
808 return list(self.iterkeys()) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
809 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
810 def __iter__(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
811 return self.iterkeys() |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
812 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
813 def __contains__(self, f): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
814 if f is None: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
815 return False |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
816 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
817 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
818 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
819 if dir not in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
820 return False |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
821 return self._dirs[dir].__contains__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
822 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
823 return f in self._files |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
824 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
825 def get(self, f, default=None): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
826 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
827 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
828 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
829 if dir not in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
830 return default |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
831 return self._dirs[dir].get(subpath, default) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
832 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
833 return self._files.get(f, default) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
834 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
835 def __getitem__(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
836 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
837 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
838 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
839 return self._dirs[dir].__getitem__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
840 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
841 return self._files[f] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
842 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
843 def flags(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
844 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
845 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
846 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
847 if dir not in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
848 return '' |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
849 return self._dirs[dir].flags(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
850 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
851 if f in self._dirs: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
852 return '' |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
853 return self._flags.get(f, '') |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
854 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
855 def find(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
856 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
857 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
858 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
859 return self._dirs[dir].find(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
860 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
861 return self._files[f], self._flags.get(f, '') |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
862 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
863 def __delitem__(self, f): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
864 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
865 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
866 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
867 self._dirs[dir].__delitem__(subpath) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
868 # If the directory is now empty, remove it |
24551
4fdf5eac5b39
treemanifest: add treemanifest._isempty()
Drew Gottlieb <drgott@google.com>
parents:
24550
diff
changeset
|
869 if self._dirs[dir]._isempty(): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
870 del self._dirs[dir] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
871 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
872 del self._files[f] |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
873 if f in self._flags: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
874 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
|
875 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
876 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
877 def __setitem__(self, f, n): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
878 assert n is not None |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
879 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
880 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
881 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
882 if dir not in self._dirs: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
883 self._dirs[dir] = treemanifest(self._subpath(dir)) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
884 self._dirs[dir].__setitem__(subpath, n) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
885 else: |
24467
bfb754050ccd
treemanifest: drop 22nd byte for consistency with manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24448
diff
changeset
|
886 self._files[f] = n[:21] # to match manifestdict's behavior |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
887 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
888 |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
889 def _load(self): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
890 if self._loadfunc is not _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
891 lf, self._loadfunc = self._loadfunc, _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
892 lf(self) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
893 elif self._copyfunc is not _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
894 cf, self._copyfunc = self._copyfunc, _noop |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
895 cf(self) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
896 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
897 def setflag(self, f, flags): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
898 """Set the flags (symlink, executable) for path f.""" |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
899 self._load() |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
900 dir, subpath = _splittopdir(f) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
901 if dir: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
902 if dir not in self._dirs: |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
903 self._dirs[dir] = treemanifest(self._subpath(dir)) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
904 self._dirs[dir].setflag(subpath, flags) |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
905 else: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
906 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
|
907 self._dirty = True |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
908 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
909 def copy(self): |
24403
0e23faa1511c
treemanifest: store directory path in treemanifest nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
24402
diff
changeset
|
910 copy = treemanifest(self._dir) |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
911 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
|
912 copy._dirty = self._dirty |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
913 if self._copyfunc is _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
914 def _copyfunc(s): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
915 self._load() |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
916 for d in self._dirs: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
917 s._dirs[d] = self._dirs[d].copy() |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
918 s._files = dict.copy(self._files) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
919 s._flags = dict.copy(self._flags) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
920 if self._loadfunc is _noop: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
921 _copyfunc(copy) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
922 else: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
923 copy._copyfunc = _copyfunc |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
924 else: |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
925 copy._copyfunc = self._copyfunc |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
926 return copy |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
927 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
928 def filesnotin(self, m2, match=None): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
929 '''Set of files in this manifest that are not in the other''' |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
930 if match: |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
931 m1 = self.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
932 m2 = m2.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
933 return m1.filesnotin(m2) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
934 |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
935 files = set() |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
936 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
|
937 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
|
938 return |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
939 t1._load() |
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
940 t2._load() |
24405
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
941 for d, m1 in t1._dirs.iteritems(): |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
942 if d in t2._dirs: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
943 m2 = t2._dirs[d] |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
944 _filesnotin(m1, m2) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
945 else: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
946 files.update(m1.iterkeys()) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
947 |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
948 for fn in t1._files.iterkeys(): |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
949 if fn not in t2._files: |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
950 files.add(t1._subpath(fn)) |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
951 |
cbe9d50d9e65
treemanifest: make filesnotin() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24404
diff
changeset
|
952 _filesnotin(self, m2) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
953 return files |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
954 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
955 @propertycache |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
956 def _alldirs(self): |
24635
21e1ece30f8c
util: move dirs() and finddirs() from scmutil to util
Drew Gottlieb <drgott@google.com>
parents:
24600
diff
changeset
|
957 return util.dirs(self) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
958 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
959 def dirs(self): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
960 return self._alldirs |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
961 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
962 def hasdir(self, dir): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
963 self._load() |
24406
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
964 topdir, subdir = _splittopdir(dir) |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
965 if topdir: |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
966 if topdir in self._dirs: |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
967 return self._dirs[topdir].hasdir(subdir) |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
968 return False |
1297480ed347
treemanifest: make hasdir() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24405
diff
changeset
|
969 return (dir + '/') in self._dirs |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
970 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
971 def walk(self, match): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
972 '''Generates matching file names. |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
973 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
974 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
|
975 an entirely new manifest. |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
976 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
977 It also reports nonexistent files by marking them bad with match.bad(). |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
978 ''' |
24683
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
979 if match.always(): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
980 for f in iter(self): |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
981 yield f |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
982 return |
4eaea0ed8dc1
manifest.walk: special-case match.always() for speed
Martin von Zweigbergk <martinvonz@google.com>
parents:
24682
diff
changeset
|
983 |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
984 fset = set(match.files()) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
985 |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
986 for fn in self._walk(match): |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
987 if fn in fset: |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
988 # specified pattern is the exact name |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
989 fset.remove(fn) |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
990 yield fn |
24646
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
991 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
992 # for dirstate.walk, files=['.'] means "walk the whole tree". |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
993 # follow that here, too |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
994 fset.discard('.') |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
995 |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
996 for fn in sorted(fset): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
997 if not self.hasdir(fn): |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
998 match.bad(fn, None) |
5693c834bcb4
manifest: move changectx.walk() to manifests
Drew Gottlieb <drgott@google.com>
parents:
24636
diff
changeset
|
999 |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1000 def _walk(self, match): |
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1001 '''Recursively generates matching file names for walk().''' |
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1002 if not match.visitdir(self._dir[:-1] or '.'): |
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1003 return |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1004 |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1005 # 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
|
1006 self._load() |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1007 for p in sorted(self._dirs.keys() + self._files.keys()): |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1008 if p in self._files: |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1009 fullp = self._subpath(p) |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1010 if match(fullp): |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1011 yield fullp |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1012 else: |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1013 for f in self._dirs[p]._walk(match): |
24647
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1014 yield f |
fb446c57f8f9
treemanifest: refactor treemanifest.walk()
Drew Gottlieb <drgott@google.com>
parents:
24646
diff
changeset
|
1015 |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1016 def matches(self, match): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1017 '''generate a new manifest filtered by the match argument''' |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1018 if match.always(): |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1019 return self.copy() |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1020 |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1021 return self._matches(match) |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1022 |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1023 def _matches(self, match): |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1024 '''recursively generate a new manifest filtered by the match argument. |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1025 ''' |
27343
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1026 |
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1027 visit = match.visitdir(self._dir[:-1] or '.') |
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1028 if visit == 'all': |
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1029 return self.copy() |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1030 ret = treemanifest(self._dir) |
27343
c59647c6694d
treemanifest: don't iterate entire matching submanifests on match()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27271
diff
changeset
|
1031 if not visit: |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1032 return ret |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1033 |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1034 self._load() |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1035 for fn in self._files: |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1036 fullp = self._subpath(fn) |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1037 if not match(fullp): |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1038 continue |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1039 ret._files[fn] = self._files[fn] |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1040 if fn in self._flags: |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1041 ret._flags[fn] = self._flags[fn] |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1042 |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1043 for dir, subm in self._dirs.iteritems(): |
25188
2773540c3650
match: remove unnecessary optimization where visitdir() returns 'all'
Drew Gottlieb <drgott@google.com>
parents:
25185
diff
changeset
|
1044 m = subm._matches(match) |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1045 if not m._isempty(): |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1046 ret._dirs[dir] = m |
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1047 |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1048 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
|
1049 ret._dirty = True |
24552
a2292da6d821
treemanifest: make treemanifest.matches() faster
Drew Gottlieb <drgott@google.com>
parents:
24551
diff
changeset
|
1050 return ret |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1051 |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1052 def diff(self, m2, match=None, clean=False): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1053 '''Finds changes between the current manifest and m2. |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1054 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1055 Args: |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1056 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
|
1057 clean: if true, include files unchanged between these manifests |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1058 with a None value in the returned dictionary. |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1059 |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1060 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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 string. |
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1066 ''' |
31265
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1067 if match: |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1068 m1 = self.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1069 m2 = m2.matches(match) |
959ebff3505a
manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents:
31163
diff
changeset
|
1070 return m1.diff(m2, clean=clean) |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1071 result = {} |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1072 emptytree = treemanifest() |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1073 def _diff(t1, t2): |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1074 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
|
1075 return |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1076 t1._load() |
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1077 t2._load() |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1078 for d, m1 in t1._dirs.iteritems(): |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1079 m2 = t2._dirs.get(d, emptytree) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1080 _diff(m1, m2) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1081 |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1082 for d, m2 in t2._dirs.iteritems(): |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1083 if d not in t1._dirs: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1084 _diff(emptytree, m2) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1085 |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1086 for fn, n1 in t1._files.iteritems(): |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1087 fl1 = t1._flags.get(fn, '') |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1088 n2 = t2._files.get(fn, None) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1089 fl2 = t2._flags.get(fn, '') |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1090 if n1 != n2 or fl1 != fl2: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1091 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2)) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1092 elif clean: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1093 result[t1._subpath(fn)] = None |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1094 |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1095 for fn, n2 in t2._files.iteritems(): |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1096 if fn not in t1._files: |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1097 fl2 = t2._flags.get(fn, '') |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1098 result[t2._subpath(fn)] = ((None, ''), (n2, fl2)) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1099 |
24404
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1100 _diff(self, m2) |
96cccf1e3257
treemanifest: make diff() faster
Martin von Zweigbergk <martinvonz@google.com>
parents:
24403
diff
changeset
|
1101 return result |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1102 |
25221
eafa06e9edde
treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
25220
diff
changeset
|
1103 def unmodifiedsince(self, m2): |
eafa06e9edde
treemanifest: speed up commit using dirty flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
25220
diff
changeset
|
1104 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
|
1105 |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1106 def parse(self, text, readsubtree): |
24781
055b3cbe6c57
treemanifest: extract parse method from constructor
Martin von Zweigbergk <martinvonz@google.com>
parents:
24780
diff
changeset
|
1107 for f, n, fl in _parse(text): |
27271
2a31433a59ba
manifest: use 't' for tree manifest flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
26871
diff
changeset
|
1108 if fl == 't': |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1109 f = f + '/' |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1110 self._dirs[f] = readsubtree(self._subpath(f), n) |
25220
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1111 elif '/' in f: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1112 # 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
|
1113 # 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
|
1114 # 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
|
1115 # to nullid). |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1116 self[f] = n |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1117 if fl: |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1118 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
|
1119 else: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1120 # 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
|
1121 # 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
|
1122 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
|
1123 if fl: |
f0fbd88b21fb
treemanifest: speed up diff by keeping track of dirty nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
25188
diff
changeset
|
1124 self._flags[f] = fl |
24781
055b3cbe6c57
treemanifest: extract parse method from constructor
Martin von Zweigbergk <martinvonz@google.com>
parents:
24780
diff
changeset
|
1125 |
24573
701d3554de0e
manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents:
24572
diff
changeset
|
1126 def text(self, usemanifestv2=False): |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1127 """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
|
1128 self._load() |
28207
43edd3003456
treemanifest: rewrite text() using iterentries()
Martin von Zweigbergk <martinvonz@google.com>
parents:
28206
diff
changeset
|
1129 return _text(self.iterentries(), usemanifestv2) |
24401
e6e023d57e94
treemanifest: create treemanifest class
Martin von Zweigbergk <martinvonz@google.com>
parents:
24396
diff
changeset
|
1130 |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1131 def dirtext(self, usemanifestv2=False): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1132 """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
|
1133 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
|
1134 """ |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1135 self._load() |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1136 flags = self.flags |
27271
2a31433a59ba
manifest: use 't' for tree manifest flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
26871
diff
changeset
|
1137 dirs = [(d[:-1], self._dirs[d]._node, 't') for d in self._dirs] |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1138 files = [(f, self._files[f], flags(f)) for f in self._files] |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1139 return _text(sorted(dirs + files), usemanifestv2) |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1140 |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1141 def read(self, gettext, readsubtree): |
26402
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1142 def _load_for_read(s): |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1143 s.parse(gettext(), readsubtree) |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1144 s._dirty = False |
05871262acd5
treemanifest: rework lazy-copying code (issue4840)
Augie Fackler <augie@google.com>
parents:
26401
diff
changeset
|
1145 self._loadfunc = _load_for_read |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1146 |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1147 def writesubtrees(self, m1, m2, writesubtree): |
25222
0de132d5328a
treemanifest: lazily load manifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
25221
diff
changeset
|
1148 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
|
1149 m1._load() |
8a84347b9907
manifest: call m1.load and m2.load before writing a subtree
Durham Goode <durham@fb.com>
parents:
29837
diff
changeset
|
1150 m2._load() |
25091
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1151 emptytree = treemanifest() |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1152 for d, subm in self._dirs.iteritems(): |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1153 subp1 = m1._dirs.get(d, emptytree)._node |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1154 subp2 = m2._dirs.get(d, emptytree)._node |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1155 if subp1 == revlog.nullid: |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1156 subp1, subp2 = subp2, subp1 |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1157 writesubtree(subm, subp1, subp2) |
b5052fc73300
treemanifest: store submanifest revlog per directory
Martin von Zweigbergk <martinvonz@google.com>
parents:
24956
diff
changeset
|
1158 |
31876
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1159 def walksubtrees(self, matcher=None): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1160 """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
|
1161 manifest itself. |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1162 |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1163 If `matcher` is provided, it only returns subtrees that match. |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1164 """ |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1165 if matcher and not matcher.visitdir(self._dir[:-1] or '.'): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1166 return |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1167 if not matcher or matcher(self._dir[:-1]): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1168 yield self |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1169 |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1170 self._load() |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1171 for d, subm in self._dirs.iteritems(): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1172 for subtree in subm.walksubtrees(matcher=matcher): |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1173 yield subtree |
94c1d3c1aea2
treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents:
31790
diff
changeset
|
1174 |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1175 class manifestrevlog(revlog.revlog): |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1176 '''A revlog that stores manifest texts. This is responsible for caching the |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1177 full-text manifest contents. |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1178 ''' |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1179 def __init__(self, opener, dir='', dirlogcache=None, indexfile=None, |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1180 treemanifest=False): |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1181 """Constructs a new manifest revlog |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1182 |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1183 `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
|
1184 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
|
1185 |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1186 `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
|
1187 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
|
1188 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
|
1189 value is passed in to the constructor. |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1190 """ |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1191 # 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
|
1192 # 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
|
1193 # 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
|
1194 cachesize = 4 |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1195 optiontreemanifest = False |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1196 usemanifestv2 = False |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1197 opts = getattr(opener, 'options', None) |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1198 if opts is not None: |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1199 cachesize = opts.get('manifestcachesize', cachesize) |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1200 optiontreemanifest = opts.get('treemanifest', False) |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1201 usemanifestv2 = opts.get('manifestv2', usemanifestv2) |
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1202 |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1203 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
|
1204 self._usemanifestv2 = usemanifestv2 |
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1205 |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1206 self._fulltextcache = util.lrucachedict(cachesize) |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1207 |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1208 if dir: |
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1209 assert self._treeondisk, 'opts is %r' % opts |
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1210 if not dir.endswith('/'): |
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1211 dir = dir + '/' |
31161
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1212 |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1213 if indexfile is None: |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1214 indexfile = '00manifest.i' |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1215 if dir: |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1216 indexfile = "meta/" + dir + indexfile |
6d9f8bc2b5ea
manifest: allow specifying the revlog filename
Durham Goode <durham@fb.com>
parents:
31114
diff
changeset
|
1217 |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1218 self._dir = dir |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1219 # The dirlogcache is kept on the root manifest log |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1220 if dir: |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1221 self._dirlogcache = dirlogcache |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1222 else: |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1223 self._dirlogcache = {'': self} |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1224 |
30002
14ad8e2a4abe
manifest: specify checkambig=True to revlog.__init__, to avoid ambiguity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29966
diff
changeset
|
1225 super(manifestrevlog, self).__init__(opener, indexfile, |
14ad8e2a4abe
manifest: specify checkambig=True to revlog.__init__, to avoid ambiguity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29966
diff
changeset
|
1226 checkambig=bool(dir)) |
29944
fa145a205a7f
manifest: move revlog specific options from manifest to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29943
diff
changeset
|
1227 |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1228 @property |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1229 def fulltextcache(self): |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1230 return self._fulltextcache |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1231 |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1232 def clearcaches(self): |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1233 super(manifestrevlog, self).clearcaches() |
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1234 self._fulltextcache.clear() |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1235 self._dirlogcache = {'': self} |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1236 |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1237 def dirlog(self, dir): |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1238 if dir: |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1239 assert self._treeondisk |
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1240 if dir not in self._dirlogcache: |
32292
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1241 mfrevlog = manifestrevlog(self.opener, dir, |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1242 self._dirlogcache, |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1243 treemanifest=self._treeondisk) |
d67991c4fefe
treemanifest: allow manifestrevlog to take an explicit treemanifest arg
Durham Goode <durham@fb.com>
parents:
32240
diff
changeset
|
1244 self._dirlogcache[dir] = mfrevlog |
29945
1cc93a154723
manifest: move dirlog up to manifestrevlog
Durham Goode <durham@fb.com>
parents:
29944
diff
changeset
|
1245 return self._dirlogcache[dir] |
29835
58d4ecdc531e
manifest: make manifest derive from manifestrevlog
Durham Goode <durham@fb.com>
parents:
29834
diff
changeset
|
1246 |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1247 def add(self, m, transaction, link, p1, p2, added, removed, readtree=None): |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1248 if (p1 in self.fulltextcache and util.safehasattr(m, 'fastdelta') |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1249 and not self._usemanifestv2): |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1250 # 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
|
1251 # 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
|
1252 # 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
|
1253 # revlog layer. |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1254 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1255 _checkforbidden(added) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1256 # combine the changed lists into one sorted iterator |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1257 work = heapq.merge([(x, False) for x in added], |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1258 [(x, True) for x in removed]) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1259 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1260 arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1261 cachedelta = self.rev(p1), deltatext |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1262 text = util.buffer(arraytext) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1263 n = self.addrevision(text, transaction, link, p1, p2, cachedelta) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1264 else: |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1265 # The first parent manifest isn't already loaded, so we'll |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1266 # just encode a fulltext of the manifest and pass that |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1267 # through to the revlog layer, and let it handle the delta |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1268 # process. |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1269 if self._treeondisk: |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1270 assert readtree, "readtree must be set for treemanifest writes" |
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1271 m1 = readtree(self._dir, p1) |
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1272 m2 = readtree(self._dir, p2) |
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1273 n = self._addtree(m, transaction, link, m1, m2, readtree) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1274 arraytext = None |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1275 else: |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1276 text = m.text(self._usemanifestv2) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1277 n = self.addrevision(text, transaction, link, p1, p2) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
1278 arraytext = bytearray(text) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1279 |
30209
9d06b65c5df2
manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents:
30207
diff
changeset
|
1280 if arraytext is not None: |
9d06b65c5df2
manifest: don't store None in fulltextcache
Martin von Zweigbergk <martinvonz@google.com>
parents:
30207
diff
changeset
|
1281 self.fulltextcache[n] = arraytext |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1282 |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1283 return n |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1284 |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1285 def _addtree(self, m, transaction, link, m1, m2, readtree): |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1286 # 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
|
1287 # don't write a new revision |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1288 if self._dir != '' and (m.unmodifiedsince(m1) or m.unmodifiedsince(m2)): |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1289 return m.node() |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1290 def writesubtree(subm, subp1, subp2): |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1291 sublog = self.dirlog(subm.dir()) |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1292 sublog.add(subm, transaction, link, subp1, subp2, None, None, |
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1293 readtree=readtree) |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1294 m.writesubtrees(m1, m2, writesubtree) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1295 text = m.dirtext(self._usemanifestv2) |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1296 n = None |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1297 if self._dir != '': |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1298 # Double-check whether contents are unchanged to one parent |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1299 if text == m1.dirtext(self._usemanifestv2): |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1300 n = m1.node() |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1301 elif text == m2.dirtext(self._usemanifestv2): |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1302 n = m2.node() |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1303 |
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1304 if not n: |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1305 n = self.addrevision(text, transaction, link, m1.node(), m2.node()) |
31303
c134a33b1d73
treemanifest: make node reuse match flat manifest behavior
Durham Goode <durham@fb.com>
parents:
31265
diff
changeset
|
1306 |
29965
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1307 # 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
|
1308 m.setnode(n) |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1309 return n |
774a15b129e8
manifest: move manifest.add onto manifestrevlog
Durham Goode <durham@fb.com>
parents:
29964
diff
changeset
|
1310 |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1311 class manifestlog(object): |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1312 """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
|
1313 referenced by commits in the repository. |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1314 |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 they receive (i.e. tree or flat or lazily loaded, etc).""" |
29837
93b44aa17691
manifest: use property instead of field for manifest revlog storage
Durham Goode <durham@fb.com>
parents:
29836
diff
changeset
|
1319 def __init__(self, opener, repo): |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1320 usetreemanifest = False |
30382
7c7d845f8b64
manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents:
30381
diff
changeset
|
1321 cachesize = 4 |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1322 |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1323 opts = getattr(opener, 'options', None) |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1324 if opts is not None: |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1325 usetreemanifest = opts.get('treemanifest', usetreemanifest) |
30382
7c7d845f8b64
manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents:
30381
diff
changeset
|
1326 cachesize = opts.get('manifestcachesize', cachesize) |
29963
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1327 self._treeinmem = usetreemanifest |
483003c27938
manifest: move treeinmem onto manifestlog
Durham Goode <durham@fb.com>
parents:
29945
diff
changeset
|
1328 |
32240
9d3136638784
manifest: remove unused property _oldmanifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
32220
diff
changeset
|
1329 self._revlog = repo._constructmanifest() |
30219
3c8811efdddc
manifest: make manifestlog a storecache
Durham Goode <durham@fb.com>
parents:
30209
diff
changeset
|
1330 |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1331 # 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
|
1332 self._dirmancache = {} |
30382
7c7d845f8b64
manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents:
30381
diff
changeset
|
1333 self._dirmancache[''] = util.lrucachedict(cachesize) |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1334 |
30382
7c7d845f8b64
manifest: make manifestlog use it's own cache
Durham Goode <durham@fb.com>
parents:
30381
diff
changeset
|
1335 self.cachesize = cachesize |
29837
93b44aa17691
manifest: use property instead of field for manifest revlog storage
Durham Goode <durham@fb.com>
parents:
29836
diff
changeset
|
1336 |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1337 def __getitem__(self, node): |
30304
1a0c1ad57833
manifest: throw LookupError if node not in revlog
Durham Goode <durham@fb.com>
parents:
30221
diff
changeset
|
1338 """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
|
1339 LookupError if not found. |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1340 """ |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1341 return self.get('', node) |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1342 |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1343 def get(self, dir, node, verify=True): |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1344 """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
|
1345 LookupError if not found. |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1346 |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1347 `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
|
1348 the revlog |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1349 """ |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1350 if node in self._dirmancache.get(dir, ()): |
32220
fb9b6bfb54b5
manifest: remove check for non-contexts in _dirmancache
Martin von Zweigbergk <martinvonz@google.com>
parents:
31876
diff
changeset
|
1351 return self._dirmancache[dir][node] |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1352 |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1353 if dir: |
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1354 if self._revlog._treeondisk: |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1355 if verify: |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1356 dirlog = self._revlog.dirlog(dir) |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1357 if node not in dirlog.nodemap: |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1358 raise LookupError(node, dirlog.indexfile, |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1359 _('no node')) |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1360 m = treemanifestctx(self, dir, node) |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1361 else: |
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1362 raise error.Abort( |
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1363 _("cannot ask for manifest directory '%s' in a flat " |
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1364 "manifest") % dir) |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1365 else: |
30413
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1366 if verify: |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1367 if node not in self._revlog.nodemap: |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1368 raise LookupError(node, self._revlog.indexfile, |
a431daa93f8c
manifest: make revlog verification optional
Durham Goode <durham@fb.com>
parents:
30387
diff
changeset
|
1369 _('no node')) |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1370 if self._treeinmem: |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1371 m = treemanifestctx(self, '', node) |
30305
dc21ea3323c4
manifest: add manifestlog.get to obtain subdirectory instances
Durham Goode <durham@fb.com>
parents:
30304
diff
changeset
|
1372 else: |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1373 m = manifestctx(self, node) |
30306
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1374 |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1375 if node != revlog.nullid: |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1376 mancache = self._dirmancache.get(dir) |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1377 if not mancache: |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1378 mancache = util.lrucachedict(self.cachesize) |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1379 self._dirmancache[dir] = mancache |
d4b340bf68c5
manifest: change manifestlog mancache to be directory based
Durham Goode <durham@fb.com>
parents:
30305
diff
changeset
|
1380 mancache[node] = m |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1381 return m |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1382 |
30380
10c924596e5c
manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents:
30379
diff
changeset
|
1383 def clearcaches(self): |
10c924596e5c
manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents:
30379
diff
changeset
|
1384 self._dirmancache.clear() |
10c924596e5c
manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents:
30379
diff
changeset
|
1385 self._revlog.clearcaches() |
10c924596e5c
manifest: move clearcaches to manifestlog
Durham Goode <durham@fb.com>
parents:
30379
diff
changeset
|
1386 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1387 class memmanifestctx(object): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1388 def __init__(self, manifestlog): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1389 self._manifestlog = manifestlog |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1390 self._manifestdict = manifestdict() |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1391 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1392 def _revlog(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1393 return self._manifestlog._revlog |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1394 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1395 def new(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1396 return memmanifestctx(self._manifestlog) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1397 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1398 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1399 memmf = memmanifestctx(self._manifestlog) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1400 memmf._manifestdict = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1401 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1402 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1403 def read(self): |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1404 return self._manifestdict |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1405 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1406 def write(self, transaction, link, p1, p2, added, removed): |
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1407 return self._revlog().add(self._manifestdict, transaction, link, p1, p2, |
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1408 added, removed) |
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1409 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1410 class manifestctx(object): |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1411 """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
|
1412 contents, its parent revs, and its linkrev. |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1413 """ |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1414 def __init__(self, manifestlog, node): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1415 self._manifestlog = manifestlog |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1416 self._data = None |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1417 |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1418 self._node = node |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1419 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1420 # 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
|
1421 # 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
|
1422 # lazily. |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1423 #self.p1, self.p2 = revlog.parents(node) |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1424 #rev = revlog.rev(node) |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1425 #self.linkrev = revlog.linkrev(rev) |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1426 |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
1427 def _revlog(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1428 return self._manifestlog._revlog |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
1429 |
29836
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1430 def node(self): |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1431 return self._node |
426d931e5db2
manifest: introduce manifestlog and manifestctx classes
Durham Goode <durham@fb.com>
parents:
29835
diff
changeset
|
1432 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1433 def new(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1434 return memmanifestctx(self._manifestlog) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1435 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1436 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1437 memmf = memmanifestctx(self._manifestlog) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1438 memmf._manifestdict = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1439 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1440 |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1441 @propertycache |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1442 def parents(self): |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1443 return self._revlog().parents(self._node) |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1444 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1445 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
|
1446 if self._data is None: |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1447 if self._node == revlog.nullid: |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1448 self._data = manifestdict() |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1449 else: |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
1450 rl = self._revlog() |
30220
acc8885a6450
manifest: make manifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30219
diff
changeset
|
1451 text = rl.revision(self._node) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
1452 arraytext = bytearray(text) |
30220
acc8885a6450
manifest: make manifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30219
diff
changeset
|
1453 rl._fulltextcache[self._node] = arraytext |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1454 self._data = manifestdict(text) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1455 return self._data |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1456 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1457 def readfast(self, shallow=False): |
30308
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1458 '''Calls either readdelta or read, based on which would be less work. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1459 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
|
1460 read quickly. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1461 |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1462 If `shallow` is True, nothing changes since this is a flat manifest. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1463 ''' |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
1464 rl = self._revlog() |
29943
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1465 r = rl.rev(self._node) |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1466 deltaparent = rl.deltaparent(r) |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1467 if deltaparent != revlog.nullrev and deltaparent in rl.parentrevs(r): |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1468 return self.readdelta() |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1469 return self.read() |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1470 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1471 def readdelta(self, shallow=False): |
30309
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1472 '''Returns a manifest containing just the entries that are present |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1473 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
|
1474 if the revlog delta is already p1. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1475 |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1476 Changing the value of `shallow` has no effect on flat manifests. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1477 ''' |
30351
3dfb5a0171c9
manifestctx: add _revlog() function
Durham Goode <durham@fb.com>
parents:
30350
diff
changeset
|
1478 revlog = self._revlog() |
29942
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1479 if revlog._usemanifestv2: |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1480 # Need to perform a slow delta |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1481 r0 = revlog.deltaparent(revlog.rev(self._node)) |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1482 m0 = self._manifestlog[revlog.node(r0)].read() |
29942
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1483 m1 = self.read() |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1484 md = manifestdict() |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1485 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1486 if n1: |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1487 md[f] = n1 |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1488 if fl1: |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1489 md.setflag(f, fl1) |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1490 return md |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1491 |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1492 r = revlog.rev(self._node) |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1493 d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1494 return manifestdict(d) |
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1495 |
30350
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
1496 def find(self, key): |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
1497 return self.read().find(key) |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
1498 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1499 class memtreemanifestctx(object): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1500 def __init__(self, manifestlog, dir=''): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1501 self._manifestlog = manifestlog |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1502 self._dir = dir |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1503 self._treemanifest = treemanifest() |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1504 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1505 def _revlog(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1506 return self._manifestlog._revlog |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1507 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1508 def new(self, dir=''): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1509 return memtreemanifestctx(self._manifestlog, dir=dir) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1510 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1511 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1512 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1513 memmf._treemanifest = self._treemanifest.copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1514 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1515 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1516 def read(self): |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1517 return self._treemanifest |
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1518 |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1519 def write(self, transaction, link, p1, p2, added, removed): |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1520 def readtree(dir, node): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1521 return self._manifestlog.get(dir, node).read() |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1522 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, |
30378
ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
Durham Goode <durham@fb.com>
parents:
30355
diff
changeset
|
1523 added, removed, readtree=readtree) |
30355
fa54f7ade491
manifest: remove manifest.add and add memmfctx.write
Durham Goode <durham@fb.com>
parents:
30353
diff
changeset
|
1524 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1525 class treemanifestctx(object): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1526 def __init__(self, manifestlog, dir, node): |
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1527 self._manifestlog = manifestlog |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1528 self._dir = dir |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1529 self._data = None |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1530 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1531 self._node = node |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1532 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1533 # 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
|
1534 # we can instantiate treemanifestctx objects for directories we don't |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1535 # have on disk. |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1536 #self.p1, self.p2 = revlog.parents(node) |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1537 #rev = revlog.rev(node) |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1538 #self.linkrev = revlog.linkrev(rev) |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1539 |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1540 def _revlog(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1541 return self._manifestlog._revlog.dirlog(self._dir) |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1542 |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1543 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
|
1544 if self._data is None: |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1545 rl = self._revlog() |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1546 if self._node == revlog.nullid: |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1547 self._data = treemanifest() |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1548 elif rl._treeondisk: |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1549 m = treemanifest(dir=self._dir) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1550 def gettext(): |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1551 return rl.revision(self._node) |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1552 def readsubtree(dir, subm): |
30414
a1beadaa4061
manifest: change treemanifestctx to construct subtrees from the manifestlog
Durham Goode <durham@fb.com>
parents:
30413
diff
changeset
|
1553 # 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
|
1554 # 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
|
1555 return self._manifestlog.get(dir, subm, verify=False).read() |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1556 m.read(gettext, readsubtree) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1557 m.setnode(self._node) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1558 self._data = m |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1559 else: |
30348
b0ca939414ea
treemanifest: fix a "treeinmem" case
Martin von Zweigbergk <martinvonz@google.com>
parents:
30341
diff
changeset
|
1560 text = rl.revision(self._node) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31303
diff
changeset
|
1561 arraytext = bytearray(text) |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1562 rl.fulltextcache[self._node] = arraytext |
29930
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1563 self._data = treemanifest(dir=self._dir, text=text) |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1564 |
be16091ac14d
manifest: change manifestctx to not inherit from manifestdict
Durham Goode <durham@fb.com>
parents:
29920
diff
changeset
|
1565 return self._data |
29911
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1566 |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1567 def node(self): |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1568 return self._node |
4fb4fc331699
manifest: add treemanifestctx class
Durham Goode <durham@fb.com>
parents:
29892
diff
changeset
|
1569 |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1570 def new(self, dir=''): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1571 return memtreemanifestctx(self._manifestlog, dir=dir) |
30352
fe1ee393de78
manifest: introduce memmanifestctx and memtreemanifestctx
Durham Goode <durham@fb.com>
parents:
30351
diff
changeset
|
1572 |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1573 def copy(self): |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1574 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) |
30353
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1575 memmf._treemanifest = self.read().copy() |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1576 return memmf |
952e1916ae56
manifest: add copy to mfctx classes
Durham Goode <durham@fb.com>
parents:
30352
diff
changeset
|
1577 |
30570
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1578 @propertycache |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1579 def parents(self): |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1580 return self._revlog().parents(self._node) |
7fbc8a742b4d
manifest: expose the parents() method
Mateusz Kwapich <mitrandir@fb.com>
parents:
30452
diff
changeset
|
1581 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1582 def readdelta(self, shallow=False): |
30309
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1583 '''Returns a manifest containing just the entries that are present |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1584 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
|
1585 if the revlog delta is already p1. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1586 |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1587 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
|
1588 without recursively reading subdirectory manifests. Instead, any |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1589 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
|
1590 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
|
1591 its 't' flag. |
f65faa4422c8
manifest: remove manifest.readshallowdelta
Durham Goode <durham@fb.com>
parents:
30308
diff
changeset
|
1592 ''' |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1593 revlog = self._revlog() |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1594 if shallow and not revlog._usemanifestv2: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1595 r = revlog.rev(self._node) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1596 d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1597 return manifestdict(d) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1598 else: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1599 # Need to perform a slow delta |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1600 r0 = revlog.deltaparent(revlog.rev(self._node)) |
31163
5cab44fd1257
manifest: remove _repo from manifestctx objects
Durham Goode <durham@fb.com>
parents:
31161
diff
changeset
|
1601 m0 = self._manifestlog.get(self._dir, revlog.node(r0)).read() |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1602 m1 = self.read() |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1603 md = treemanifest(dir=self._dir) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1604 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1605 if n1: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1606 md[f] = n1 |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1607 if fl1: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1608 md.setflag(f, fl1) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1609 return md |
29942
a059b17352ef
manifest: add manifestctx.readdelta()
Durham Goode <durham@fb.com>
parents:
29930
diff
changeset
|
1610 |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1611 def readfast(self, shallow=False): |
30308
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1612 '''Calls either readdelta or read, based on which would be less work. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1613 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
|
1614 read quickly. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1615 |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1616 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
|
1617 and not any submanifests. |
bce79dfcf5e4
manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents:
30307
diff
changeset
|
1618 ''' |
30221
f2c5b9d48b29
manifest: make treemanifestctx store the repo
Durham Goode <durham@fb.com>
parents:
30220
diff
changeset
|
1619 rl = self._revlog() |
29943
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1620 r = rl.rev(self._node) |
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1621 deltaparent = rl.deltaparent(r) |
30307
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1622 if (deltaparent != revlog.nullrev and |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1623 deltaparent in rl.parentrevs(r)): |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1624 return self.readdelta(shallow=shallow) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1625 |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1626 if shallow: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1627 return manifestdict(rl.revision(self._node)) |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1628 else: |
78f3c7166f0d
manifest: add shallow option to treemanifestctx.readdelta and readfast
Durham Goode <durham@fb.com>
parents:
30306
diff
changeset
|
1629 return self.read() |
29943
80be4436e4cc
manifest: adds manifestctx.readfast
Durham Goode <durham@fb.com>
parents:
29942
diff
changeset
|
1630 |
30350
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
1631 def find(self, key): |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30348
diff
changeset
|
1632 return self.read().find(key) |