Show More
@@ -1,2060 +1,2060 b'' | |||||
1 | # repository.py - Interfaces and base classes for repositories and peers. |
|
1 | # repository.py - Interfaces and base classes for repositories and peers. | |
2 | # coding: utf-8 |
|
2 | # coding: utf-8 | |
3 | # |
|
3 | # | |
4 | # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> |
|
4 | # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | from __future__ import absolute_import |
|
9 | from __future__ import absolute_import | |
10 |
|
10 | |||
11 | from ..i18n import _ |
|
11 | from ..i18n import _ | |
12 | from .. import error |
|
12 | from .. import error | |
13 | from . import util as interfaceutil |
|
13 | from . import util as interfaceutil | |
14 |
|
14 | |||
15 | # Local repository feature string. |
|
15 | # Local repository feature string. | |
16 |
|
16 | |||
17 | # Revlogs are being used for file storage. |
|
17 | # Revlogs are being used for file storage. | |
18 | REPO_FEATURE_REVLOG_FILE_STORAGE = b'revlogfilestorage' |
|
18 | REPO_FEATURE_REVLOG_FILE_STORAGE = b'revlogfilestorage' | |
19 | # The storage part of the repository is shared from an external source. |
|
19 | # The storage part of the repository is shared from an external source. | |
20 | REPO_FEATURE_SHARED_STORAGE = b'sharedstore' |
|
20 | REPO_FEATURE_SHARED_STORAGE = b'sharedstore' | |
21 | # LFS supported for backing file storage. |
|
21 | # LFS supported for backing file storage. | |
22 | REPO_FEATURE_LFS = b'lfs' |
|
22 | REPO_FEATURE_LFS = b'lfs' | |
23 | # Repository supports being stream cloned. |
|
23 | # Repository supports being stream cloned. | |
24 | REPO_FEATURE_STREAM_CLONE = b'streamclone' |
|
24 | REPO_FEATURE_STREAM_CLONE = b'streamclone' | |
25 | # Repository supports (at least) some sidedata to be stored |
|
25 | # Repository supports (at least) some sidedata to be stored | |
26 | REPO_FEATURE_SIDE_DATA = b'side-data' |
|
26 | REPO_FEATURE_SIDE_DATA = b'side-data' | |
27 | # Files storage may lack data for all ancestors. |
|
27 | # Files storage may lack data for all ancestors. | |
28 | REPO_FEATURE_SHALLOW_FILE_STORAGE = b'shallowfilestorage' |
|
28 | REPO_FEATURE_SHALLOW_FILE_STORAGE = b'shallowfilestorage' | |
29 |
|
29 | |||
30 | REVISION_FLAG_CENSORED = 1 << 15 |
|
30 | REVISION_FLAG_CENSORED = 1 << 15 | |
31 | REVISION_FLAG_ELLIPSIS = 1 << 14 |
|
31 | REVISION_FLAG_ELLIPSIS = 1 << 14 | |
32 | REVISION_FLAG_EXTSTORED = 1 << 13 |
|
32 | REVISION_FLAG_EXTSTORED = 1 << 13 | |
33 | REVISION_FLAG_HASCOPIESINFO = 1 << 12 |
|
33 | REVISION_FLAG_HASCOPIESINFO = 1 << 12 | |
34 |
|
34 | |||
35 | REVISION_FLAGS_KNOWN = ( |
|
35 | REVISION_FLAGS_KNOWN = ( | |
36 | REVISION_FLAG_CENSORED |
|
36 | REVISION_FLAG_CENSORED | |
37 | | REVISION_FLAG_ELLIPSIS |
|
37 | | REVISION_FLAG_ELLIPSIS | |
38 | | REVISION_FLAG_EXTSTORED |
|
38 | | REVISION_FLAG_EXTSTORED | |
39 | | REVISION_FLAG_HASCOPIESINFO |
|
39 | | REVISION_FLAG_HASCOPIESINFO | |
40 | ) |
|
40 | ) | |
41 |
|
41 | |||
42 | CG_DELTAMODE_STD = b'default' |
|
42 | CG_DELTAMODE_STD = b'default' | |
43 | CG_DELTAMODE_PREV = b'previous' |
|
43 | CG_DELTAMODE_PREV = b'previous' | |
44 | CG_DELTAMODE_FULL = b'fulltext' |
|
44 | CG_DELTAMODE_FULL = b'fulltext' | |
45 | CG_DELTAMODE_P1 = b'p1' |
|
45 | CG_DELTAMODE_P1 = b'p1' | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | ## Cache related constants: |
|
48 | ## Cache related constants: | |
49 | # |
|
49 | # | |
50 | # Used to control which cache should be warmed in a repo.updatecaches(β¦) call. |
|
50 | # Used to control which cache should be warmed in a repo.updatecaches(β¦) call. | |
51 |
|
51 | |||
52 | # Warm branchmaps of all known repoview's filter-level |
|
52 | # Warm branchmaps of all known repoview's filter-level | |
53 | CACHE_BRANCHMAP_ALL = b"branchmap-all" |
|
53 | CACHE_BRANCHMAP_ALL = b"branchmap-all" | |
54 | # Warm branchmaps of repoview's filter-level used by server |
|
54 | # Warm branchmaps of repoview's filter-level used by server | |
55 | CACHE_BRANCHMAP_SERVED = b"branchmap-served" |
|
55 | CACHE_BRANCHMAP_SERVED = b"branchmap-served" | |
56 | # Warm internal changelog cache (eg: persistent nodemap) |
|
56 | # Warm internal changelog cache (eg: persistent nodemap) | |
57 | CACHE_CHANGELOG_CACHE = b"changelog-cache" |
|
57 | CACHE_CHANGELOG_CACHE = b"changelog-cache" | |
58 | # Warm full manifest cache |
|
58 | # Warm full manifest cache | |
59 | CACHE_FULL_MANIFEST = b"full-manifest" |
|
59 | CACHE_FULL_MANIFEST = b"full-manifest" | |
60 | # Warm file-node-tags cache |
|
60 | # Warm file-node-tags cache | |
61 | CACHE_FILE_NODE_TAGS = b"file-node-tags" |
|
61 | CACHE_FILE_NODE_TAGS = b"file-node-tags" | |
62 | # Warm internal manifestlog cache (eg: persistent nodemap) |
|
62 | # Warm internal manifestlog cache (eg: persistent nodemap) | |
63 | CACHE_MANIFESTLOG_CACHE = b"manifestlog-cache" |
|
63 | CACHE_MANIFESTLOG_CACHE = b"manifestlog-cache" | |
64 | # Warn rev branch cache |
|
64 | # Warn rev branch cache | |
65 | CACHE_REV_BRANCH = b"rev-branch-cache" |
|
65 | CACHE_REV_BRANCH = b"rev-branch-cache" | |
66 | # Warm tags' cache for default repoview' |
|
66 | # Warm tags' cache for default repoview' | |
67 | CACHE_TAGS_DEFAULT = b"tags-default" |
|
67 | CACHE_TAGS_DEFAULT = b"tags-default" | |
68 | # Warm tags' cache for repoview's filter-level used by server |
|
68 | # Warm tags' cache for repoview's filter-level used by server | |
69 | CACHE_TAGS_SERVED = b"tags-served" |
|
69 | CACHE_TAGS_SERVED = b"tags-served" | |
70 |
|
70 | |||
71 | # the cache to warm by default after a simple transaction |
|
71 | # the cache to warm by default after a simple transaction | |
72 | # (this is a mutable set to let extension update it) |
|
72 | # (this is a mutable set to let extension update it) | |
73 | CACHES_DEFAULT = { |
|
73 | CACHES_DEFAULT = { | |
74 | CACHE_BRANCHMAP_SERVED, |
|
74 | CACHE_BRANCHMAP_SERVED, | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | # the caches to warm when warming all of them |
|
77 | # the caches to warm when warming all of them | |
78 | # (this is a mutable set to let extension update it) |
|
78 | # (this is a mutable set to let extension update it) | |
79 | CACHES_ALL = { |
|
79 | CACHES_ALL = { | |
80 | CACHE_BRANCHMAP_SERVED, |
|
80 | CACHE_BRANCHMAP_SERVED, | |
81 | CACHE_BRANCHMAP_ALL, |
|
81 | CACHE_BRANCHMAP_ALL, | |
82 | CACHE_CHANGELOG_CACHE, |
|
82 | CACHE_CHANGELOG_CACHE, | |
83 | CACHE_FILE_NODE_TAGS, |
|
83 | CACHE_FILE_NODE_TAGS, | |
84 | CACHE_FULL_MANIFEST, |
|
84 | CACHE_FULL_MANIFEST, | |
85 | CACHE_MANIFESTLOG_CACHE, |
|
85 | CACHE_MANIFESTLOG_CACHE, | |
86 | CACHE_TAGS_DEFAULT, |
|
86 | CACHE_TAGS_DEFAULT, | |
87 | CACHE_TAGS_SERVED, |
|
87 | CACHE_TAGS_SERVED, | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | # the cache to warm by default on simple call |
|
90 | # the cache to warm by default on simple call | |
91 | # (this is a mutable set to let extension update it) |
|
91 | # (this is a mutable set to let extension update it) | |
92 | CACHES_POST_CLONE = CACHES_ALL.copy() |
|
92 | CACHES_POST_CLONE = CACHES_ALL.copy() | |
93 | CACHES_POST_CLONE.discard(CACHE_FILE_NODE_TAGS) |
|
93 | CACHES_POST_CLONE.discard(CACHE_FILE_NODE_TAGS) | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | class ipeerconnection(interfaceutil.Interface): |
|
96 | class ipeerconnection(interfaceutil.Interface): | |
97 | """Represents a "connection" to a repository. |
|
97 | """Represents a "connection" to a repository. | |
98 |
|
98 | |||
99 | This is the base interface for representing a connection to a repository. |
|
99 | This is the base interface for representing a connection to a repository. | |
100 | It holds basic properties and methods applicable to all peer types. |
|
100 | It holds basic properties and methods applicable to all peer types. | |
101 |
|
101 | |||
102 | This is not a complete interface definition and should not be used |
|
102 | This is not a complete interface definition and should not be used | |
103 | outside of this module. |
|
103 | outside of this module. | |
104 | """ |
|
104 | """ | |
105 |
|
105 | |||
106 | ui = interfaceutil.Attribute("""ui.ui instance""") |
|
106 | ui = interfaceutil.Attribute("""ui.ui instance""") | |
107 |
|
107 | |||
108 | def url(): |
|
108 | def url(): | |
109 | """Returns a URL string representing this peer. |
|
109 | """Returns a URL string representing this peer. | |
110 |
|
110 | |||
111 | Currently, implementations expose the raw URL used to construct the |
|
111 | Currently, implementations expose the raw URL used to construct the | |
112 | instance. It may contain credentials as part of the URL. The |
|
112 | instance. It may contain credentials as part of the URL. The | |
113 | expectations of the value aren't well-defined and this could lead to |
|
113 | expectations of the value aren't well-defined and this could lead to | |
114 | data leakage. |
|
114 | data leakage. | |
115 |
|
115 | |||
116 | TODO audit/clean consumers and more clearly define the contents of this |
|
116 | TODO audit/clean consumers and more clearly define the contents of this | |
117 | value. |
|
117 | value. | |
118 | """ |
|
118 | """ | |
119 |
|
119 | |||
120 | def local(): |
|
120 | def local(): | |
121 | """Returns a local repository instance. |
|
121 | """Returns a local repository instance. | |
122 |
|
122 | |||
123 | If the peer represents a local repository, returns an object that |
|
123 | If the peer represents a local repository, returns an object that | |
124 | can be used to interface with it. Otherwise returns ``None``. |
|
124 | can be used to interface with it. Otherwise returns ``None``. | |
125 | """ |
|
125 | """ | |
126 |
|
126 | |||
127 | def peer(): |
|
127 | def peer(): | |
128 | """Returns an object conforming to this interface. |
|
128 | """Returns an object conforming to this interface. | |
129 |
|
129 | |||
130 | Most implementations will ``return self``. |
|
130 | Most implementations will ``return self``. | |
131 | """ |
|
131 | """ | |
132 |
|
132 | |||
133 | def canpush(): |
|
133 | def canpush(): | |
134 | """Returns a boolean indicating if this peer can be pushed to.""" |
|
134 | """Returns a boolean indicating if this peer can be pushed to.""" | |
135 |
|
135 | |||
136 | def close(): |
|
136 | def close(): | |
137 | """Close the connection to this peer. |
|
137 | """Close the connection to this peer. | |
138 |
|
138 | |||
139 | This is called when the peer will no longer be used. Resources |
|
139 | This is called when the peer will no longer be used. Resources | |
140 | associated with the peer should be cleaned up. |
|
140 | associated with the peer should be cleaned up. | |
141 | """ |
|
141 | """ | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | class ipeercapabilities(interfaceutil.Interface): |
|
144 | class ipeercapabilities(interfaceutil.Interface): | |
145 | """Peer sub-interface related to capabilities.""" |
|
145 | """Peer sub-interface related to capabilities.""" | |
146 |
|
146 | |||
147 | def capable(name): |
|
147 | def capable(name): | |
148 | """Determine support for a named capability. |
|
148 | """Determine support for a named capability. | |
149 |
|
149 | |||
150 | Returns ``False`` if capability not supported. |
|
150 | Returns ``False`` if capability not supported. | |
151 |
|
151 | |||
152 | Returns ``True`` if boolean capability is supported. Returns a string |
|
152 | Returns ``True`` if boolean capability is supported. Returns a string | |
153 | if capability support is non-boolean. |
|
153 | if capability support is non-boolean. | |
154 |
|
154 | |||
155 | Capability strings may or may not map to wire protocol capabilities. |
|
155 | Capability strings may or may not map to wire protocol capabilities. | |
156 | """ |
|
156 | """ | |
157 |
|
157 | |||
158 | def requirecap(name, purpose): |
|
158 | def requirecap(name, purpose): | |
159 | """Require a capability to be present. |
|
159 | """Require a capability to be present. | |
160 |
|
160 | |||
161 | Raises a ``CapabilityError`` if the capability isn't present. |
|
161 | Raises a ``CapabilityError`` if the capability isn't present. | |
162 | """ |
|
162 | """ | |
163 |
|
163 | |||
164 |
|
164 | |||
165 | class ipeercommands(interfaceutil.Interface): |
|
165 | class ipeercommands(interfaceutil.Interface): | |
166 | """Client-side interface for communicating over the wire protocol. |
|
166 | """Client-side interface for communicating over the wire protocol. | |
167 |
|
167 | |||
168 | This interface is used as a gateway to the Mercurial wire protocol. |
|
168 | This interface is used as a gateway to the Mercurial wire protocol. | |
169 | methods commonly call wire protocol commands of the same name. |
|
169 | methods commonly call wire protocol commands of the same name. | |
170 | """ |
|
170 | """ | |
171 |
|
171 | |||
172 | def branchmap(): |
|
172 | def branchmap(): | |
173 | """Obtain heads in named branches. |
|
173 | """Obtain heads in named branches. | |
174 |
|
174 | |||
175 | Returns a dict mapping branch name to an iterable of nodes that are |
|
175 | Returns a dict mapping branch name to an iterable of nodes that are | |
176 | heads on that branch. |
|
176 | heads on that branch. | |
177 | """ |
|
177 | """ | |
178 |
|
178 | |||
179 | def capabilities(): |
|
179 | def capabilities(): | |
180 | """Obtain capabilities of the peer. |
|
180 | """Obtain capabilities of the peer. | |
181 |
|
181 | |||
182 | Returns a set of string capabilities. |
|
182 | Returns a set of string capabilities. | |
183 | """ |
|
183 | """ | |
184 |
|
184 | |||
185 | def clonebundles(): |
|
185 | def clonebundles(): | |
186 | """Obtains the clone bundles manifest for the repo. |
|
186 | """Obtains the clone bundles manifest for the repo. | |
187 |
|
187 | |||
188 | Returns the manifest as unparsed bytes. |
|
188 | Returns the manifest as unparsed bytes. | |
189 | """ |
|
189 | """ | |
190 |
|
190 | |||
191 | def debugwireargs(one, two, three=None, four=None, five=None): |
|
191 | def debugwireargs(one, two, three=None, four=None, five=None): | |
192 | """Used to facilitate debugging of arguments passed over the wire.""" |
|
192 | """Used to facilitate debugging of arguments passed over the wire.""" | |
193 |
|
193 | |||
194 | def getbundle(source, **kwargs): |
|
194 | def getbundle(source, **kwargs): | |
195 | """Obtain remote repository data as a bundle. |
|
195 | """Obtain remote repository data as a bundle. | |
196 |
|
196 | |||
197 | This command is how the bulk of repository data is transferred from |
|
197 | This command is how the bulk of repository data is transferred from | |
198 | the peer to the local repository |
|
198 | the peer to the local repository | |
199 |
|
199 | |||
200 | Returns a generator of bundle data. |
|
200 | Returns a generator of bundle data. | |
201 | """ |
|
201 | """ | |
202 |
|
202 | |||
203 | def heads(): |
|
203 | def heads(): | |
204 | """Determine all known head revisions in the peer. |
|
204 | """Determine all known head revisions in the peer. | |
205 |
|
205 | |||
206 | Returns an iterable of binary nodes. |
|
206 | Returns an iterable of binary nodes. | |
207 | """ |
|
207 | """ | |
208 |
|
208 | |||
209 | def known(nodes): |
|
209 | def known(nodes): | |
210 | """Determine whether multiple nodes are known. |
|
210 | """Determine whether multiple nodes are known. | |
211 |
|
211 | |||
212 | Accepts an iterable of nodes whose presence to check for. |
|
212 | Accepts an iterable of nodes whose presence to check for. | |
213 |
|
213 | |||
214 | Returns an iterable of booleans indicating of the corresponding node |
|
214 | Returns an iterable of booleans indicating of the corresponding node | |
215 | at that index is known to the peer. |
|
215 | at that index is known to the peer. | |
216 | """ |
|
216 | """ | |
217 |
|
217 | |||
218 | def listkeys(namespace): |
|
218 | def listkeys(namespace): | |
219 | """Obtain all keys in a pushkey namespace. |
|
219 | """Obtain all keys in a pushkey namespace. | |
220 |
|
220 | |||
221 | Returns an iterable of key names. |
|
221 | Returns an iterable of key names. | |
222 | """ |
|
222 | """ | |
223 |
|
223 | |||
224 | def lookup(key): |
|
224 | def lookup(key): | |
225 | """Resolve a value to a known revision. |
|
225 | """Resolve a value to a known revision. | |
226 |
|
226 | |||
227 | Returns a binary node of the resolved revision on success. |
|
227 | Returns a binary node of the resolved revision on success. | |
228 | """ |
|
228 | """ | |
229 |
|
229 | |||
230 | def pushkey(namespace, key, old, new): |
|
230 | def pushkey(namespace, key, old, new): | |
231 | """Set a value using the ``pushkey`` protocol. |
|
231 | """Set a value using the ``pushkey`` protocol. | |
232 |
|
232 | |||
233 | Arguments correspond to the pushkey namespace and key to operate on and |
|
233 | Arguments correspond to the pushkey namespace and key to operate on and | |
234 | the old and new values for that key. |
|
234 | the old and new values for that key. | |
235 |
|
235 | |||
236 | Returns a string with the peer result. The value inside varies by the |
|
236 | Returns a string with the peer result. The value inside varies by the | |
237 | namespace. |
|
237 | namespace. | |
238 | """ |
|
238 | """ | |
239 |
|
239 | |||
240 | def stream_out(): |
|
240 | def stream_out(): | |
241 | """Obtain streaming clone data. |
|
241 | """Obtain streaming clone data. | |
242 |
|
242 | |||
243 | Successful result should be a generator of data chunks. |
|
243 | Successful result should be a generator of data chunks. | |
244 | """ |
|
244 | """ | |
245 |
|
245 | |||
246 | def unbundle(bundle, heads, url): |
|
246 | def unbundle(bundle, heads, url): | |
247 | """Transfer repository data to the peer. |
|
247 | """Transfer repository data to the peer. | |
248 |
|
248 | |||
249 | This is how the bulk of data during a push is transferred. |
|
249 | This is how the bulk of data during a push is transferred. | |
250 |
|
250 | |||
251 | Returns the integer number of heads added to the peer. |
|
251 | Returns the integer number of heads added to the peer. | |
252 | """ |
|
252 | """ | |
253 |
|
253 | |||
254 |
|
254 | |||
255 | class ipeerlegacycommands(interfaceutil.Interface): |
|
255 | class ipeerlegacycommands(interfaceutil.Interface): | |
256 | """Interface for implementing support for legacy wire protocol commands. |
|
256 | """Interface for implementing support for legacy wire protocol commands. | |
257 |
|
257 | |||
258 | Wire protocol commands transition to legacy status when they are no longer |
|
258 | Wire protocol commands transition to legacy status when they are no longer | |
259 | used by modern clients. To facilitate identifying which commands are |
|
259 | used by modern clients. To facilitate identifying which commands are | |
260 | legacy, the interfaces are split. |
|
260 | legacy, the interfaces are split. | |
261 | """ |
|
261 | """ | |
262 |
|
262 | |||
263 | def between(pairs): |
|
263 | def between(pairs): | |
264 | """Obtain nodes between pairs of nodes. |
|
264 | """Obtain nodes between pairs of nodes. | |
265 |
|
265 | |||
266 | ``pairs`` is an iterable of node pairs. |
|
266 | ``pairs`` is an iterable of node pairs. | |
267 |
|
267 | |||
268 | Returns an iterable of iterables of nodes corresponding to each |
|
268 | Returns an iterable of iterables of nodes corresponding to each | |
269 | requested pair. |
|
269 | requested pair. | |
270 | """ |
|
270 | """ | |
271 |
|
271 | |||
272 | def branches(nodes): |
|
272 | def branches(nodes): | |
273 | """Obtain ancestor changesets of specific nodes back to a branch point. |
|
273 | """Obtain ancestor changesets of specific nodes back to a branch point. | |
274 |
|
274 | |||
275 | For each requested node, the peer finds the first ancestor node that is |
|
275 | For each requested node, the peer finds the first ancestor node that is | |
276 | a DAG root or is a merge. |
|
276 | a DAG root or is a merge. | |
277 |
|
277 | |||
278 | Returns an iterable of iterables with the resolved values for each node. |
|
278 | Returns an iterable of iterables with the resolved values for each node. | |
279 | """ |
|
279 | """ | |
280 |
|
280 | |||
281 | def changegroup(nodes, source): |
|
281 | def changegroup(nodes, source): | |
282 | """Obtain a changegroup with data for descendants of specified nodes.""" |
|
282 | """Obtain a changegroup with data for descendants of specified nodes.""" | |
283 |
|
283 | |||
284 | def changegroupsubset(bases, heads, source): |
|
284 | def changegroupsubset(bases, heads, source): | |
285 | pass |
|
285 | pass | |
286 |
|
286 | |||
287 |
|
287 | |||
288 | class ipeercommandexecutor(interfaceutil.Interface): |
|
288 | class ipeercommandexecutor(interfaceutil.Interface): | |
289 | """Represents a mechanism to execute remote commands. |
|
289 | """Represents a mechanism to execute remote commands. | |
290 |
|
290 | |||
291 | This is the primary interface for requesting that wire protocol commands |
|
291 | This is the primary interface for requesting that wire protocol commands | |
292 | be executed. Instances of this interface are active in a context manager |
|
292 | be executed. Instances of this interface are active in a context manager | |
293 | and have a well-defined lifetime. When the context manager exits, all |
|
293 | and have a well-defined lifetime. When the context manager exits, all | |
294 | outstanding requests are waited on. |
|
294 | outstanding requests are waited on. | |
295 | """ |
|
295 | """ | |
296 |
|
296 | |||
297 | def callcommand(name, args): |
|
297 | def callcommand(name, args): | |
298 | """Request that a named command be executed. |
|
298 | """Request that a named command be executed. | |
299 |
|
299 | |||
300 | Receives the command name and a dictionary of command arguments. |
|
300 | Receives the command name and a dictionary of command arguments. | |
301 |
|
301 | |||
302 | Returns a ``concurrent.futures.Future`` that will resolve to the |
|
302 | Returns a ``concurrent.futures.Future`` that will resolve to the | |
303 | result of that command request. That exact value is left up to |
|
303 | result of that command request. That exact value is left up to | |
304 | the implementation and possibly varies by command. |
|
304 | the implementation and possibly varies by command. | |
305 |
|
305 | |||
306 | Not all commands can coexist with other commands in an executor |
|
306 | Not all commands can coexist with other commands in an executor | |
307 | instance: it depends on the underlying wire protocol transport being |
|
307 | instance: it depends on the underlying wire protocol transport being | |
308 | used and the command itself. |
|
308 | used and the command itself. | |
309 |
|
309 | |||
310 | Implementations MAY call ``sendcommands()`` automatically if the |
|
310 | Implementations MAY call ``sendcommands()`` automatically if the | |
311 | requested command can not coexist with other commands in this executor. |
|
311 | requested command can not coexist with other commands in this executor. | |
312 |
|
312 | |||
313 | Implementations MAY call ``sendcommands()`` automatically when the |
|
313 | Implementations MAY call ``sendcommands()`` automatically when the | |
314 | future's ``result()`` is called. So, consumers using multiple |
|
314 | future's ``result()`` is called. So, consumers using multiple | |
315 | commands with an executor MUST ensure that ``result()`` is not called |
|
315 | commands with an executor MUST ensure that ``result()`` is not called | |
316 | until all command requests have been issued. |
|
316 | until all command requests have been issued. | |
317 | """ |
|
317 | """ | |
318 |
|
318 | |||
319 | def sendcommands(): |
|
319 | def sendcommands(): | |
320 | """Trigger submission of queued command requests. |
|
320 | """Trigger submission of queued command requests. | |
321 |
|
321 | |||
322 | Not all transports submit commands as soon as they are requested to |
|
322 | Not all transports submit commands as soon as they are requested to | |
323 | run. When called, this method forces queued command requests to be |
|
323 | run. When called, this method forces queued command requests to be | |
324 | issued. It will no-op if all commands have already been sent. |
|
324 | issued. It will no-op if all commands have already been sent. | |
325 |
|
325 | |||
326 | When called, no more new commands may be issued with this executor. |
|
326 | When called, no more new commands may be issued with this executor. | |
327 | """ |
|
327 | """ | |
328 |
|
328 | |||
329 | def close(): |
|
329 | def close(): | |
330 | """Signal that this command request is finished. |
|
330 | """Signal that this command request is finished. | |
331 |
|
331 | |||
332 | When called, no more new commands may be issued. All outstanding |
|
332 | When called, no more new commands may be issued. All outstanding | |
333 | commands that have previously been issued are waited on before |
|
333 | commands that have previously been issued are waited on before | |
334 | returning. This not only includes waiting for the futures to resolve, |
|
334 | returning. This not only includes waiting for the futures to resolve, | |
335 | but also waiting for all response data to arrive. In other words, |
|
335 | but also waiting for all response data to arrive. In other words, | |
336 | calling this waits for all on-wire state for issued command requests |
|
336 | calling this waits for all on-wire state for issued command requests | |
337 | to finish. |
|
337 | to finish. | |
338 |
|
338 | |||
339 | When used as a context manager, this method is called when exiting the |
|
339 | When used as a context manager, this method is called when exiting the | |
340 | context manager. |
|
340 | context manager. | |
341 |
|
341 | |||
342 | This method may call ``sendcommands()`` if there are buffered commands. |
|
342 | This method may call ``sendcommands()`` if there are buffered commands. | |
343 | """ |
|
343 | """ | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | class ipeerrequests(interfaceutil.Interface): |
|
346 | class ipeerrequests(interfaceutil.Interface): | |
347 | """Interface for executing commands on a peer.""" |
|
347 | """Interface for executing commands on a peer.""" | |
348 |
|
348 | |||
349 | limitedarguments = interfaceutil.Attribute( |
|
349 | limitedarguments = interfaceutil.Attribute( | |
350 | """True if the peer cannot receive large argument value for commands.""" |
|
350 | """True if the peer cannot receive large argument value for commands.""" | |
351 | ) |
|
351 | ) | |
352 |
|
352 | |||
353 | def commandexecutor(): |
|
353 | def commandexecutor(): | |
354 | """A context manager that resolves to an ipeercommandexecutor. |
|
354 | """A context manager that resolves to an ipeercommandexecutor. | |
355 |
|
355 | |||
356 | The object this resolves to can be used to issue command requests |
|
356 | The object this resolves to can be used to issue command requests | |
357 | to the peer. |
|
357 | to the peer. | |
358 |
|
358 | |||
359 | Callers should call its ``callcommand`` method to issue command |
|
359 | Callers should call its ``callcommand`` method to issue command | |
360 | requests. |
|
360 | requests. | |
361 |
|
361 | |||
362 | A new executor should be obtained for each distinct set of commands |
|
362 | A new executor should be obtained for each distinct set of commands | |
363 | (possibly just a single command) that the consumer wants to execute |
|
363 | (possibly just a single command) that the consumer wants to execute | |
364 | as part of a single operation or round trip. This is because some |
|
364 | as part of a single operation or round trip. This is because some | |
365 | peers are half-duplex and/or don't support persistent connections. |
|
365 | peers are half-duplex and/or don't support persistent connections. | |
366 | e.g. in the case of HTTP peers, commands sent to an executor represent |
|
366 | e.g. in the case of HTTP peers, commands sent to an executor represent | |
367 | a single HTTP request. While some peers may support multiple command |
|
367 | a single HTTP request. While some peers may support multiple command | |
368 | sends over the wire per executor, consumers need to code to the least |
|
368 | sends over the wire per executor, consumers need to code to the least | |
369 | capable peer. So it should be assumed that command executors buffer |
|
369 | capable peer. So it should be assumed that command executors buffer | |
370 | called commands until they are told to send them and that each |
|
370 | called commands until they are told to send them and that each | |
371 | command executor could result in a new connection or wire-level request |
|
371 | command executor could result in a new connection or wire-level request | |
372 | being issued. |
|
372 | being issued. | |
373 | """ |
|
373 | """ | |
374 |
|
374 | |||
375 |
|
375 | |||
376 | class ipeerbase(ipeerconnection, ipeercapabilities, ipeerrequests): |
|
376 | class ipeerbase(ipeerconnection, ipeercapabilities, ipeerrequests): | |
377 | """Unified interface for peer repositories. |
|
377 | """Unified interface for peer repositories. | |
378 |
|
378 | |||
379 | All peer instances must conform to this interface. |
|
379 | All peer instances must conform to this interface. | |
380 | """ |
|
380 | """ | |
381 |
|
381 | |||
382 |
|
382 | |||
383 | class ipeerv2(ipeerconnection, ipeercapabilities, ipeerrequests): |
|
383 | class ipeerv2(ipeerconnection, ipeercapabilities, ipeerrequests): | |
384 | """Unified peer interface for wire protocol version 2 peers.""" |
|
384 | """Unified peer interface for wire protocol version 2 peers.""" | |
385 |
|
385 | |||
386 | apidescriptor = interfaceutil.Attribute( |
|
386 | apidescriptor = interfaceutil.Attribute( | |
387 | """Data structure holding description of server API.""" |
|
387 | """Data structure holding description of server API.""" | |
388 | ) |
|
388 | ) | |
389 |
|
389 | |||
390 |
|
390 | |||
391 | @interfaceutil.implementer(ipeerbase) |
|
391 | @interfaceutil.implementer(ipeerbase) | |
392 | class peer(object): |
|
392 | class peer(object): | |
393 | """Base class for peer repositories.""" |
|
393 | """Base class for peer repositories.""" | |
394 |
|
394 | |||
395 | limitedarguments = False |
|
395 | limitedarguments = False | |
396 |
|
396 | |||
397 | def capable(self, name): |
|
397 | def capable(self, name): | |
398 | caps = self.capabilities() |
|
398 | caps = self.capabilities() | |
399 | if name in caps: |
|
399 | if name in caps: | |
400 | return True |
|
400 | return True | |
401 |
|
401 | |||
402 | name = b'%s=' % name |
|
402 | name = b'%s=' % name | |
403 | for cap in caps: |
|
403 | for cap in caps: | |
404 | if cap.startswith(name): |
|
404 | if cap.startswith(name): | |
405 | return cap[len(name) :] |
|
405 | return cap[len(name) :] | |
406 |
|
406 | |||
407 | return False |
|
407 | return False | |
408 |
|
408 | |||
409 | def requirecap(self, name, purpose): |
|
409 | def requirecap(self, name, purpose): | |
410 | if self.capable(name): |
|
410 | if self.capable(name): | |
411 | return |
|
411 | return | |
412 |
|
412 | |||
413 | raise error.CapabilityError( |
|
413 | raise error.CapabilityError( | |
414 | _( |
|
414 | _( | |
415 | b'cannot %s; remote repository does not support the ' |
|
415 | b'cannot %s; remote repository does not support the ' | |
416 | b'\'%s\' capability' |
|
416 | b'\'%s\' capability' | |
417 | ) |
|
417 | ) | |
418 | % (purpose, name) |
|
418 | % (purpose, name) | |
419 | ) |
|
419 | ) | |
420 |
|
420 | |||
421 |
|
421 | |||
422 | class iverifyproblem(interfaceutil.Interface): |
|
422 | class iverifyproblem(interfaceutil.Interface): | |
423 | """Represents a problem with the integrity of the repository. |
|
423 | """Represents a problem with the integrity of the repository. | |
424 |
|
424 | |||
425 | Instances of this interface are emitted to describe an integrity issue |
|
425 | Instances of this interface are emitted to describe an integrity issue | |
426 | with a repository (e.g. corrupt storage, missing data, etc). |
|
426 | with a repository (e.g. corrupt storage, missing data, etc). | |
427 |
|
427 | |||
428 | Instances are essentially messages associated with severity. |
|
428 | Instances are essentially messages associated with severity. | |
429 | """ |
|
429 | """ | |
430 |
|
430 | |||
431 | warning = interfaceutil.Attribute( |
|
431 | warning = interfaceutil.Attribute( | |
432 | """Message indicating a non-fatal problem.""" |
|
432 | """Message indicating a non-fatal problem.""" | |
433 | ) |
|
433 | ) | |
434 |
|
434 | |||
435 | error = interfaceutil.Attribute("""Message indicating a fatal problem.""") |
|
435 | error = interfaceutil.Attribute("""Message indicating a fatal problem.""") | |
436 |
|
436 | |||
437 | node = interfaceutil.Attribute( |
|
437 | node = interfaceutil.Attribute( | |
438 | """Revision encountering the problem. |
|
438 | """Revision encountering the problem. | |
439 |
|
439 | |||
440 | ``None`` means the problem doesn't apply to a single revision. |
|
440 | ``None`` means the problem doesn't apply to a single revision. | |
441 | """ |
|
441 | """ | |
442 | ) |
|
442 | ) | |
443 |
|
443 | |||
444 |
|
444 | |||
445 | class irevisiondelta(interfaceutil.Interface): |
|
445 | class irevisiondelta(interfaceutil.Interface): | |
446 | """Represents a delta between one revision and another. |
|
446 | """Represents a delta between one revision and another. | |
447 |
|
447 | |||
448 | Instances convey enough information to allow a revision to be exchanged |
|
448 | Instances convey enough information to allow a revision to be exchanged | |
449 | with another repository. |
|
449 | with another repository. | |
450 |
|
450 | |||
451 | Instances represent the fulltext revision data or a delta against |
|
451 | Instances represent the fulltext revision data or a delta against | |
452 | another revision. Therefore the ``revision`` and ``delta`` attributes |
|
452 | another revision. Therefore the ``revision`` and ``delta`` attributes | |
453 | are mutually exclusive. |
|
453 | are mutually exclusive. | |
454 |
|
454 | |||
455 | Typically used for changegroup generation. |
|
455 | Typically used for changegroup generation. | |
456 | """ |
|
456 | """ | |
457 |
|
457 | |||
458 | node = interfaceutil.Attribute("""20 byte node of this revision.""") |
|
458 | node = interfaceutil.Attribute("""20 byte node of this revision.""") | |
459 |
|
459 | |||
460 | p1node = interfaceutil.Attribute( |
|
460 | p1node = interfaceutil.Attribute( | |
461 | """20 byte node of 1st parent of this revision.""" |
|
461 | """20 byte node of 1st parent of this revision.""" | |
462 | ) |
|
462 | ) | |
463 |
|
463 | |||
464 | p2node = interfaceutil.Attribute( |
|
464 | p2node = interfaceutil.Attribute( | |
465 | """20 byte node of 2nd parent of this revision.""" |
|
465 | """20 byte node of 2nd parent of this revision.""" | |
466 | ) |
|
466 | ) | |
467 |
|
467 | |||
468 | linknode = interfaceutil.Attribute( |
|
468 | linknode = interfaceutil.Attribute( | |
469 | """20 byte node of the changelog revision this node is linked to.""" |
|
469 | """20 byte node of the changelog revision this node is linked to.""" | |
470 | ) |
|
470 | ) | |
471 |
|
471 | |||
472 | flags = interfaceutil.Attribute( |
|
472 | flags = interfaceutil.Attribute( | |
473 | """2 bytes of integer flags that apply to this revision. |
|
473 | """2 bytes of integer flags that apply to this revision. | |
474 |
|
474 | |||
475 | This is a bitwise composition of the ``REVISION_FLAG_*`` constants. |
|
475 | This is a bitwise composition of the ``REVISION_FLAG_*`` constants. | |
476 | """ |
|
476 | """ | |
477 | ) |
|
477 | ) | |
478 |
|
478 | |||
479 | basenode = interfaceutil.Attribute( |
|
479 | basenode = interfaceutil.Attribute( | |
480 | """20 byte node of the revision this data is a delta against. |
|
480 | """20 byte node of the revision this data is a delta against. | |
481 |
|
481 | |||
482 | ``nullid`` indicates that the revision is a full revision and not |
|
482 | ``nullid`` indicates that the revision is a full revision and not | |
483 | a delta. |
|
483 | a delta. | |
484 | """ |
|
484 | """ | |
485 | ) |
|
485 | ) | |
486 |
|
486 | |||
487 | baserevisionsize = interfaceutil.Attribute( |
|
487 | baserevisionsize = interfaceutil.Attribute( | |
488 | """Size of base revision this delta is against. |
|
488 | """Size of base revision this delta is against. | |
489 |
|
489 | |||
490 | May be ``None`` if ``basenode`` is ``nullid``. |
|
490 | May be ``None`` if ``basenode`` is ``nullid``. | |
491 | """ |
|
491 | """ | |
492 | ) |
|
492 | ) | |
493 |
|
493 | |||
494 | revision = interfaceutil.Attribute( |
|
494 | revision = interfaceutil.Attribute( | |
495 | """Raw fulltext of revision data for this node.""" |
|
495 | """Raw fulltext of revision data for this node.""" | |
496 | ) |
|
496 | ) | |
497 |
|
497 | |||
498 | delta = interfaceutil.Attribute( |
|
498 | delta = interfaceutil.Attribute( | |
499 | """Delta between ``basenode`` and ``node``. |
|
499 | """Delta between ``basenode`` and ``node``. | |
500 |
|
500 | |||
501 | Stored in the bdiff delta format. |
|
501 | Stored in the bdiff delta format. | |
502 | """ |
|
502 | """ | |
503 | ) |
|
503 | ) | |
504 |
|
504 | |||
505 | sidedata = interfaceutil.Attribute( |
|
505 | sidedata = interfaceutil.Attribute( | |
506 | """Raw sidedata bytes for the given revision.""" |
|
506 | """Raw sidedata bytes for the given revision.""" | |
507 | ) |
|
507 | ) | |
508 |
|
508 | |||
509 | protocol_flags = interfaceutil.Attribute( |
|
509 | protocol_flags = interfaceutil.Attribute( | |
510 | """Single byte of integer flags that can influence the protocol. |
|
510 | """Single byte of integer flags that can influence the protocol. | |
511 |
|
511 | |||
512 | This is a bitwise composition of the ``storageutil.CG_FLAG*`` constants. |
|
512 | This is a bitwise composition of the ``storageutil.CG_FLAG*`` constants. | |
513 | """ |
|
513 | """ | |
514 | ) |
|
514 | ) | |
515 |
|
515 | |||
516 |
|
516 | |||
517 | class ifilerevisionssequence(interfaceutil.Interface): |
|
517 | class ifilerevisionssequence(interfaceutil.Interface): | |
518 | """Contains index data for all revisions of a file. |
|
518 | """Contains index data for all revisions of a file. | |
519 |
|
519 | |||
520 | Types implementing this behave like lists of tuples. The index |
|
520 | Types implementing this behave like lists of tuples. The index | |
521 | in the list corresponds to the revision number. The values contain |
|
521 | in the list corresponds to the revision number. The values contain | |
522 | index metadata. |
|
522 | index metadata. | |
523 |
|
523 | |||
524 | The *null* revision (revision number -1) is always the last item |
|
524 | The *null* revision (revision number -1) is always the last item | |
525 | in the index. |
|
525 | in the index. | |
526 | """ |
|
526 | """ | |
527 |
|
527 | |||
528 | def __len__(): |
|
528 | def __len__(): | |
529 | """The total number of revisions.""" |
|
529 | """The total number of revisions.""" | |
530 |
|
530 | |||
531 | def __getitem__(rev): |
|
531 | def __getitem__(rev): | |
532 | """Returns the object having a specific revision number. |
|
532 | """Returns the object having a specific revision number. | |
533 |
|
533 | |||
534 | Returns an 8-tuple with the following fields: |
|
534 | Returns an 8-tuple with the following fields: | |
535 |
|
535 | |||
536 | offset+flags |
|
536 | offset+flags | |
537 | Contains the offset and flags for the revision. 64-bit unsigned |
|
537 | Contains the offset and flags for the revision. 64-bit unsigned | |
538 | integer where first 6 bytes are the offset and the next 2 bytes |
|
538 | integer where first 6 bytes are the offset and the next 2 bytes | |
539 | are flags. The offset can be 0 if it is not used by the store. |
|
539 | are flags. The offset can be 0 if it is not used by the store. | |
540 | compressed size |
|
540 | compressed size | |
541 | Size of the revision data in the store. It can be 0 if it isn't |
|
541 | Size of the revision data in the store. It can be 0 if it isn't | |
542 | needed by the store. |
|
542 | needed by the store. | |
543 | uncompressed size |
|
543 | uncompressed size | |
544 | Fulltext size. It can be 0 if it isn't needed by the store. |
|
544 | Fulltext size. It can be 0 if it isn't needed by the store. | |
545 | base revision |
|
545 | base revision | |
546 | Revision number of revision the delta for storage is encoded |
|
546 | Revision number of revision the delta for storage is encoded | |
547 | against. -1 indicates not encoded against a base revision. |
|
547 | against. -1 indicates not encoded against a base revision. | |
548 | link revision |
|
548 | link revision | |
549 | Revision number of changelog revision this entry is related to. |
|
549 | Revision number of changelog revision this entry is related to. | |
550 | p1 revision |
|
550 | p1 revision | |
551 | Revision number of 1st parent. -1 if no 1st parent. |
|
551 | Revision number of 1st parent. -1 if no 1st parent. | |
552 | p2 revision |
|
552 | p2 revision | |
553 | Revision number of 2nd parent. -1 if no 1st parent. |
|
553 | Revision number of 2nd parent. -1 if no 1st parent. | |
554 | node |
|
554 | node | |
555 | Binary node value for this revision number. |
|
555 | Binary node value for this revision number. | |
556 |
|
556 | |||
557 | Negative values should index off the end of the sequence. ``-1`` |
|
557 | Negative values should index off the end of the sequence. ``-1`` | |
558 | should return the null revision. ``-2`` should return the most |
|
558 | should return the null revision. ``-2`` should return the most | |
559 | recent revision. |
|
559 | recent revision. | |
560 | """ |
|
560 | """ | |
561 |
|
561 | |||
562 | def __contains__(rev): |
|
562 | def __contains__(rev): | |
563 | """Whether a revision number exists.""" |
|
563 | """Whether a revision number exists.""" | |
564 |
|
564 | |||
565 | def insert(self, i, entry): |
|
565 | def insert(self, i, entry): | |
566 | """Add an item to the index at specific revision.""" |
|
566 | """Add an item to the index at specific revision.""" | |
567 |
|
567 | |||
568 |
|
568 | |||
569 | class ifileindex(interfaceutil.Interface): |
|
569 | class ifileindex(interfaceutil.Interface): | |
570 | """Storage interface for index data of a single file. |
|
570 | """Storage interface for index data of a single file. | |
571 |
|
571 | |||
572 | File storage data is divided into index metadata and data storage. |
|
572 | File storage data is divided into index metadata and data storage. | |
573 | This interface defines the index portion of the interface. |
|
573 | This interface defines the index portion of the interface. | |
574 |
|
574 | |||
575 | The index logically consists of: |
|
575 | The index logically consists of: | |
576 |
|
576 | |||
577 | * A mapping between revision numbers and nodes. |
|
577 | * A mapping between revision numbers and nodes. | |
578 | * DAG data (storing and querying the relationship between nodes). |
|
578 | * DAG data (storing and querying the relationship between nodes). | |
579 | * Metadata to facilitate storage. |
|
579 | * Metadata to facilitate storage. | |
580 | """ |
|
580 | """ | |
581 |
|
581 | |||
582 | nullid = interfaceutil.Attribute( |
|
582 | nullid = interfaceutil.Attribute( | |
583 | """node for the null revision for use as delta base.""" |
|
583 | """node for the null revision for use as delta base.""" | |
584 | ) |
|
584 | ) | |
585 |
|
585 | |||
586 | def __len__(): |
|
586 | def __len__(): | |
587 | """Obtain the number of revisions stored for this file.""" |
|
587 | """Obtain the number of revisions stored for this file.""" | |
588 |
|
588 | |||
589 | def __iter__(): |
|
589 | def __iter__(): | |
590 | """Iterate over revision numbers for this file.""" |
|
590 | """Iterate over revision numbers for this file.""" | |
591 |
|
591 | |||
592 | def hasnode(node): |
|
592 | def hasnode(node): | |
593 | """Returns a bool indicating if a node is known to this store. |
|
593 | """Returns a bool indicating if a node is known to this store. | |
594 |
|
594 | |||
595 | Implementations must only return True for full, binary node values: |
|
595 | Implementations must only return True for full, binary node values: | |
596 | hex nodes, revision numbers, and partial node matches must be |
|
596 | hex nodes, revision numbers, and partial node matches must be | |
597 | rejected. |
|
597 | rejected. | |
598 |
|
598 | |||
599 | The null node is never present. |
|
599 | The null node is never present. | |
600 | """ |
|
600 | """ | |
601 |
|
601 | |||
602 | def revs(start=0, stop=None): |
|
602 | def revs(start=0, stop=None): | |
603 | """Iterate over revision numbers for this file, with control.""" |
|
603 | """Iterate over revision numbers for this file, with control.""" | |
604 |
|
604 | |||
605 | def parents(node): |
|
605 | def parents(node): | |
606 | """Returns a 2-tuple of parent nodes for a revision. |
|
606 | """Returns a 2-tuple of parent nodes for a revision. | |
607 |
|
607 | |||
608 | Values will be ``nullid`` if the parent is empty. |
|
608 | Values will be ``nullid`` if the parent is empty. | |
609 | """ |
|
609 | """ | |
610 |
|
610 | |||
611 | def parentrevs(rev): |
|
611 | def parentrevs(rev): | |
612 | """Like parents() but operates on revision numbers.""" |
|
612 | """Like parents() but operates on revision numbers.""" | |
613 |
|
613 | |||
614 | def rev(node): |
|
614 | def rev(node): | |
615 | """Obtain the revision number given a node. |
|
615 | """Obtain the revision number given a node. | |
616 |
|
616 | |||
617 | Raises ``error.LookupError`` if the node is not known. |
|
617 | Raises ``error.LookupError`` if the node is not known. | |
618 | """ |
|
618 | """ | |
619 |
|
619 | |||
620 | def node(rev): |
|
620 | def node(rev): | |
621 | """Obtain the node value given a revision number. |
|
621 | """Obtain the node value given a revision number. | |
622 |
|
622 | |||
623 | Raises ``IndexError`` if the node is not known. |
|
623 | Raises ``IndexError`` if the node is not known. | |
624 | """ |
|
624 | """ | |
625 |
|
625 | |||
626 | def lookup(node): |
|
626 | def lookup(node): | |
627 | """Attempt to resolve a value to a node. |
|
627 | """Attempt to resolve a value to a node. | |
628 |
|
628 | |||
629 | Value can be a binary node, hex node, revision number, or a string |
|
629 | Value can be a binary node, hex node, revision number, or a string | |
630 | that can be converted to an integer. |
|
630 | that can be converted to an integer. | |
631 |
|
631 | |||
632 | Raises ``error.LookupError`` if a node could not be resolved. |
|
632 | Raises ``error.LookupError`` if a node could not be resolved. | |
633 | """ |
|
633 | """ | |
634 |
|
634 | |||
635 | def linkrev(rev): |
|
635 | def linkrev(rev): | |
636 | """Obtain the changeset revision number a revision is linked to.""" |
|
636 | """Obtain the changeset revision number a revision is linked to.""" | |
637 |
|
637 | |||
638 | def iscensored(rev): |
|
638 | def iscensored(rev): | |
639 | """Return whether a revision's content has been censored.""" |
|
639 | """Return whether a revision's content has been censored.""" | |
640 |
|
640 | |||
641 | def commonancestorsheads(node1, node2): |
|
641 | def commonancestorsheads(node1, node2): | |
642 | """Obtain an iterable of nodes containing heads of common ancestors. |
|
642 | """Obtain an iterable of nodes containing heads of common ancestors. | |
643 |
|
643 | |||
644 | See ``ancestor.commonancestorsheads()``. |
|
644 | See ``ancestor.commonancestorsheads()``. | |
645 | """ |
|
645 | """ | |
646 |
|
646 | |||
647 | def descendants(revs): |
|
647 | def descendants(revs): | |
648 | """Obtain descendant revision numbers for a set of revision numbers. |
|
648 | """Obtain descendant revision numbers for a set of revision numbers. | |
649 |
|
649 | |||
650 | If ``nullrev`` is in the set, this is equivalent to ``revs()``. |
|
650 | If ``nullrev`` is in the set, this is equivalent to ``revs()``. | |
651 | """ |
|
651 | """ | |
652 |
|
652 | |||
653 | def heads(start=None, stop=None): |
|
653 | def heads(start=None, stop=None): | |
654 | """Obtain a list of nodes that are DAG heads, with control. |
|
654 | """Obtain a list of nodes that are DAG heads, with control. | |
655 |
|
655 | |||
656 | The set of revisions examined can be limited by specifying |
|
656 | The set of revisions examined can be limited by specifying | |
657 | ``start`` and ``stop``. ``start`` is a node. ``stop`` is an |
|
657 | ``start`` and ``stop``. ``start`` is a node. ``stop`` is an | |
658 | iterable of nodes. DAG traversal starts at earlier revision |
|
658 | iterable of nodes. DAG traversal starts at earlier revision | |
659 | ``start`` and iterates forward until any node in ``stop`` is |
|
659 | ``start`` and iterates forward until any node in ``stop`` is | |
660 | encountered. |
|
660 | encountered. | |
661 | """ |
|
661 | """ | |
662 |
|
662 | |||
663 | def children(node): |
|
663 | def children(node): | |
664 | """Obtain nodes that are children of a node. |
|
664 | """Obtain nodes that are children of a node. | |
665 |
|
665 | |||
666 | Returns a list of nodes. |
|
666 | Returns a list of nodes. | |
667 | """ |
|
667 | """ | |
668 |
|
668 | |||
669 |
|
669 | |||
670 | class ifiledata(interfaceutil.Interface): |
|
670 | class ifiledata(interfaceutil.Interface): | |
671 | """Storage interface for data storage of a specific file. |
|
671 | """Storage interface for data storage of a specific file. | |
672 |
|
672 | |||
673 | This complements ``ifileindex`` and provides an interface for accessing |
|
673 | This complements ``ifileindex`` and provides an interface for accessing | |
674 | data for a tracked file. |
|
674 | data for a tracked file. | |
675 | """ |
|
675 | """ | |
676 |
|
676 | |||
677 | def size(rev): |
|
677 | def size(rev): | |
678 | """Obtain the fulltext size of file data. |
|
678 | """Obtain the fulltext size of file data. | |
679 |
|
679 | |||
680 | Any metadata is excluded from size measurements. |
|
680 | Any metadata is excluded from size measurements. | |
681 | """ |
|
681 | """ | |
682 |
|
682 | |||
683 | def revision(node, raw=False): |
|
683 | def revision(node, raw=False): | |
684 | """Obtain fulltext data for a node. |
|
684 | """Obtain fulltext data for a node. | |
685 |
|
685 | |||
686 | By default, any storage transformations are applied before the data |
|
686 | By default, any storage transformations are applied before the data | |
687 | is returned. If ``raw`` is True, non-raw storage transformations |
|
687 | is returned. If ``raw`` is True, non-raw storage transformations | |
688 | are not applied. |
|
688 | are not applied. | |
689 |
|
689 | |||
690 | The fulltext data may contain a header containing metadata. Most |
|
690 | The fulltext data may contain a header containing metadata. Most | |
691 | consumers should use ``read()`` to obtain the actual file data. |
|
691 | consumers should use ``read()`` to obtain the actual file data. | |
692 | """ |
|
692 | """ | |
693 |
|
693 | |||
694 | def rawdata(node): |
|
694 | def rawdata(node): | |
695 | """Obtain raw data for a node.""" |
|
695 | """Obtain raw data for a node.""" | |
696 |
|
696 | |||
697 | def read(node): |
|
697 | def read(node): | |
698 | """Resolve file fulltext data. |
|
698 | """Resolve file fulltext data. | |
699 |
|
699 | |||
700 | This is similar to ``revision()`` except any metadata in the data |
|
700 | This is similar to ``revision()`` except any metadata in the data | |
701 | headers is stripped. |
|
701 | headers is stripped. | |
702 | """ |
|
702 | """ | |
703 |
|
703 | |||
704 | def renamed(node): |
|
704 | def renamed(node): | |
705 | """Obtain copy metadata for a node. |
|
705 | """Obtain copy metadata for a node. | |
706 |
|
706 | |||
707 | Returns ``False`` if no copy metadata is stored or a 2-tuple of |
|
707 | Returns ``False`` if no copy metadata is stored or a 2-tuple of | |
708 | (path, node) from which this revision was copied. |
|
708 | (path, node) from which this revision was copied. | |
709 | """ |
|
709 | """ | |
710 |
|
710 | |||
711 | def cmp(node, fulltext): |
|
711 | def cmp(node, fulltext): | |
712 | """Compare fulltext to another revision. |
|
712 | """Compare fulltext to another revision. | |
713 |
|
713 | |||
714 | Returns True if the fulltext is different from what is stored. |
|
714 | Returns True if the fulltext is different from what is stored. | |
715 |
|
715 | |||
716 | This takes copy metadata into account. |
|
716 | This takes copy metadata into account. | |
717 |
|
717 | |||
718 | TODO better document the copy metadata and censoring logic. |
|
718 | TODO better document the copy metadata and censoring logic. | |
719 | """ |
|
719 | """ | |
720 |
|
720 | |||
721 | def emitrevisions( |
|
721 | def emitrevisions( | |
722 | nodes, |
|
722 | nodes, | |
723 | nodesorder=None, |
|
723 | nodesorder=None, | |
724 | revisiondata=False, |
|
724 | revisiondata=False, | |
725 | assumehaveparentrevisions=False, |
|
725 | assumehaveparentrevisions=False, | |
726 | deltamode=CG_DELTAMODE_STD, |
|
726 | deltamode=CG_DELTAMODE_STD, | |
727 | ): |
|
727 | ): | |
728 | """Produce ``irevisiondelta`` for revisions. |
|
728 | """Produce ``irevisiondelta`` for revisions. | |
729 |
|
729 | |||
730 | Given an iterable of nodes, emits objects conforming to the |
|
730 | Given an iterable of nodes, emits objects conforming to the | |
731 | ``irevisiondelta`` interface that describe revisions in storage. |
|
731 | ``irevisiondelta`` interface that describe revisions in storage. | |
732 |
|
732 | |||
733 | This method is a generator. |
|
733 | This method is a generator. | |
734 |
|
734 | |||
735 | The input nodes may be unordered. Implementations must ensure that a |
|
735 | The input nodes may be unordered. Implementations must ensure that a | |
736 | node's parents are emitted before the node itself. Transitively, this |
|
736 | node's parents are emitted before the node itself. Transitively, this | |
737 | means that a node may only be emitted once all its ancestors in |
|
737 | means that a node may only be emitted once all its ancestors in | |
738 | ``nodes`` have also been emitted. |
|
738 | ``nodes`` have also been emitted. | |
739 |
|
739 | |||
740 | By default, emits "index" data (the ``node``, ``p1node``, and |
|
740 | By default, emits "index" data (the ``node``, ``p1node``, and | |
741 | ``p2node`` attributes). If ``revisiondata`` is set, revision data |
|
741 | ``p2node`` attributes). If ``revisiondata`` is set, revision data | |
742 | will also be present on the emitted objects. |
|
742 | will also be present on the emitted objects. | |
743 |
|
743 | |||
744 | With default argument values, implementations can choose to emit |
|
744 | With default argument values, implementations can choose to emit | |
745 | either fulltext revision data or a delta. When emitting deltas, |
|
745 | either fulltext revision data or a delta. When emitting deltas, | |
746 | implementations must consider whether the delta's base revision |
|
746 | implementations must consider whether the delta's base revision | |
747 | fulltext is available to the receiver. |
|
747 | fulltext is available to the receiver. | |
748 |
|
748 | |||
749 | The base revision fulltext is guaranteed to be available if any of |
|
749 | The base revision fulltext is guaranteed to be available if any of | |
750 | the following are met: |
|
750 | the following are met: | |
751 |
|
751 | |||
752 | * Its fulltext revision was emitted by this method call. |
|
752 | * Its fulltext revision was emitted by this method call. | |
753 | * A delta for that revision was emitted by this method call. |
|
753 | * A delta for that revision was emitted by this method call. | |
754 | * ``assumehaveparentrevisions`` is True and the base revision is a |
|
754 | * ``assumehaveparentrevisions`` is True and the base revision is a | |
755 | parent of the node. |
|
755 | parent of the node. | |
756 |
|
756 | |||
757 | ``nodesorder`` can be used to control the order that revisions are |
|
757 | ``nodesorder`` can be used to control the order that revisions are | |
758 | emitted. By default, revisions can be reordered as long as they are |
|
758 | emitted. By default, revisions can be reordered as long as they are | |
759 | in DAG topological order (see above). If the value is ``nodes``, |
|
759 | in DAG topological order (see above). If the value is ``nodes``, | |
760 | the iteration order from ``nodes`` should be used. If the value is |
|
760 | the iteration order from ``nodes`` should be used. If the value is | |
761 | ``storage``, then the native order from the backing storage layer |
|
761 | ``storage``, then the native order from the backing storage layer | |
762 | is used. (Not all storage layers will have strong ordering and behavior |
|
762 | is used. (Not all storage layers will have strong ordering and behavior | |
763 | of this mode is storage-dependent.) ``nodes`` ordering can force |
|
763 | of this mode is storage-dependent.) ``nodes`` ordering can force | |
764 | revisions to be emitted before their ancestors, so consumers should |
|
764 | revisions to be emitted before their ancestors, so consumers should | |
765 | use it with care. |
|
765 | use it with care. | |
766 |
|
766 | |||
767 | The ``linknode`` attribute on the returned ``irevisiondelta`` may not |
|
767 | The ``linknode`` attribute on the returned ``irevisiondelta`` may not | |
768 | be set and it is the caller's responsibility to resolve it, if needed. |
|
768 | be set and it is the caller's responsibility to resolve it, if needed. | |
769 |
|
769 | |||
770 | If ``deltamode`` is CG_DELTAMODE_PREV and revision data is requested, |
|
770 | If ``deltamode`` is CG_DELTAMODE_PREV and revision data is requested, | |
771 | all revision data should be emitted as deltas against the revision |
|
771 | all revision data should be emitted as deltas against the revision | |
772 | emitted just prior. The initial revision should be a delta against its |
|
772 | emitted just prior. The initial revision should be a delta against its | |
773 | 1st parent. |
|
773 | 1st parent. | |
774 | """ |
|
774 | """ | |
775 |
|
775 | |||
776 |
|
776 | |||
777 | class ifilemutation(interfaceutil.Interface): |
|
777 | class ifilemutation(interfaceutil.Interface): | |
778 | """Storage interface for mutation events of a tracked file.""" |
|
778 | """Storage interface for mutation events of a tracked file.""" | |
779 |
|
779 | |||
780 | def add(filedata, meta, transaction, linkrev, p1, p2): |
|
780 | def add(filedata, meta, transaction, linkrev, p1, p2): | |
781 | """Add a new revision to the store. |
|
781 | """Add a new revision to the store. | |
782 |
|
782 | |||
783 | Takes file data, dictionary of metadata, a transaction, linkrev, |
|
783 | Takes file data, dictionary of metadata, a transaction, linkrev, | |
784 | and parent nodes. |
|
784 | and parent nodes. | |
785 |
|
785 | |||
786 | Returns the node that was added. |
|
786 | Returns the node that was added. | |
787 |
|
787 | |||
788 | May no-op if a revision matching the supplied data is already stored. |
|
788 | May no-op if a revision matching the supplied data is already stored. | |
789 | """ |
|
789 | """ | |
790 |
|
790 | |||
791 | def addrevision( |
|
791 | def addrevision( | |
792 | revisiondata, |
|
792 | revisiondata, | |
793 | transaction, |
|
793 | transaction, | |
794 | linkrev, |
|
794 | linkrev, | |
795 | p1, |
|
795 | p1, | |
796 | p2, |
|
796 | p2, | |
797 | node=None, |
|
797 | node=None, | |
798 | flags=0, |
|
798 | flags=0, | |
799 | cachedelta=None, |
|
799 | cachedelta=None, | |
800 | ): |
|
800 | ): | |
801 | """Add a new revision to the store and return its number. |
|
801 | """Add a new revision to the store and return its number. | |
802 |
|
802 | |||
803 | This is similar to ``add()`` except it operates at a lower level. |
|
803 | This is similar to ``add()`` except it operates at a lower level. | |
804 |
|
804 | |||
805 | The data passed in already contains a metadata header, if any. |
|
805 | The data passed in already contains a metadata header, if any. | |
806 |
|
806 | |||
807 | ``node`` and ``flags`` can be used to define the expected node and |
|
807 | ``node`` and ``flags`` can be used to define the expected node and | |
808 | the flags to use with storage. ``flags`` is a bitwise value composed |
|
808 | the flags to use with storage. ``flags`` is a bitwise value composed | |
809 | of the various ``REVISION_FLAG_*`` constants. |
|
809 | of the various ``REVISION_FLAG_*`` constants. | |
810 |
|
810 | |||
811 | ``add()`` is usually called when adding files from e.g. the working |
|
811 | ``add()`` is usually called when adding files from e.g. the working | |
812 | directory. ``addrevision()`` is often called by ``add()`` and for |
|
812 | directory. ``addrevision()`` is often called by ``add()`` and for | |
813 | scenarios where revision data has already been computed, such as when |
|
813 | scenarios where revision data has already been computed, such as when | |
814 | applying raw data from a peer repo. |
|
814 | applying raw data from a peer repo. | |
815 | """ |
|
815 | """ | |
816 |
|
816 | |||
817 | def addgroup( |
|
817 | def addgroup( | |
818 | deltas, |
|
818 | deltas, | |
819 | linkmapper, |
|
819 | linkmapper, | |
820 | transaction, |
|
820 | transaction, | |
821 | addrevisioncb=None, |
|
821 | addrevisioncb=None, | |
822 | duplicaterevisioncb=None, |
|
822 | duplicaterevisioncb=None, | |
823 | maybemissingparents=False, |
|
823 | maybemissingparents=False, | |
824 | ): |
|
824 | ): | |
825 | """Process a series of deltas for storage. |
|
825 | """Process a series of deltas for storage. | |
826 |
|
826 | |||
827 | ``deltas`` is an iterable of 7-tuples of |
|
827 | ``deltas`` is an iterable of 7-tuples of | |
828 | (node, p1, p2, linknode, deltabase, delta, flags) defining revisions |
|
828 | (node, p1, p2, linknode, deltabase, delta, flags) defining revisions | |
829 | to add. |
|
829 | to add. | |
830 |
|
830 | |||
831 | The ``delta`` field contains ``mpatch`` data to apply to a base |
|
831 | The ``delta`` field contains ``mpatch`` data to apply to a base | |
832 | revision, identified by ``deltabase``. The base node can be |
|
832 | revision, identified by ``deltabase``. The base node can be | |
833 | ``nullid``, in which case the header from the delta can be ignored |
|
833 | ``nullid``, in which case the header from the delta can be ignored | |
834 | and the delta used as the fulltext. |
|
834 | and the delta used as the fulltext. | |
835 |
|
835 | |||
836 | ``alwayscache`` instructs the lower layers to cache the content of the |
|
836 | ``alwayscache`` instructs the lower layers to cache the content of the | |
837 | newly added revision, even if it needs to be explicitly computed. |
|
837 | newly added revision, even if it needs to be explicitly computed. | |
838 | This used to be the default when ``addrevisioncb`` was provided up to |
|
838 | This used to be the default when ``addrevisioncb`` was provided up to | |
839 | Mercurial 5.8. |
|
839 | Mercurial 5.8. | |
840 |
|
840 | |||
841 | ``addrevisioncb`` should be called for each new rev as it is committed. |
|
841 | ``addrevisioncb`` should be called for each new rev as it is committed. | |
842 | ``duplicaterevisioncb`` should be called for all revs with a |
|
842 | ``duplicaterevisioncb`` should be called for all revs with a | |
843 | pre-existing node. |
|
843 | pre-existing node. | |
844 |
|
844 | |||
845 | ``maybemissingparents`` is a bool indicating whether the incoming |
|
845 | ``maybemissingparents`` is a bool indicating whether the incoming | |
846 | data may reference parents/ancestor revisions that aren't present. |
|
846 | data may reference parents/ancestor revisions that aren't present. | |
847 | This flag is set when receiving data into a "shallow" store that |
|
847 | This flag is set when receiving data into a "shallow" store that | |
848 | doesn't hold all history. |
|
848 | doesn't hold all history. | |
849 |
|
849 | |||
850 | Returns a list of nodes that were processed. A node will be in the list |
|
850 | Returns a list of nodes that were processed. A node will be in the list | |
851 | even if it existed in the store previously. |
|
851 | even if it existed in the store previously. | |
852 | """ |
|
852 | """ | |
853 |
|
853 | |||
854 | def censorrevision(tr, node, tombstone=b''): |
|
854 | def censorrevision(tr, node, tombstone=b''): | |
855 | """Remove the content of a single revision. |
|
855 | """Remove the content of a single revision. | |
856 |
|
856 | |||
857 | The specified ``node`` will have its content purged from storage. |
|
857 | The specified ``node`` will have its content purged from storage. | |
858 | Future attempts to access the revision data for this node will |
|
858 | Future attempts to access the revision data for this node will | |
859 | result in failure. |
|
859 | result in failure. | |
860 |
|
860 | |||
861 | A ``tombstone`` message can optionally be stored. This message may be |
|
861 | A ``tombstone`` message can optionally be stored. This message may be | |
862 | displayed to users when they attempt to access the missing revision |
|
862 | displayed to users when they attempt to access the missing revision | |
863 | data. |
|
863 | data. | |
864 |
|
864 | |||
865 | Storage backends may have stored deltas against the previous content |
|
865 | Storage backends may have stored deltas against the previous content | |
866 | in this revision. As part of censoring a revision, these storage |
|
866 | in this revision. As part of censoring a revision, these storage | |
867 | backends are expected to rewrite any internally stored deltas such |
|
867 | backends are expected to rewrite any internally stored deltas such | |
868 | that they no longer reference the deleted content. |
|
868 | that they no longer reference the deleted content. | |
869 | """ |
|
869 | """ | |
870 |
|
870 | |||
871 | def getstrippoint(minlink): |
|
871 | def getstrippoint(minlink): | |
872 | """Find the minimum revision that must be stripped to strip a linkrev. |
|
872 | """Find the minimum revision that must be stripped to strip a linkrev. | |
873 |
|
873 | |||
874 | Returns a 2-tuple containing the minimum revision number and a set |
|
874 | Returns a 2-tuple containing the minimum revision number and a set | |
875 | of all revisions numbers that would be broken by this strip. |
|
875 | of all revisions numbers that would be broken by this strip. | |
876 |
|
876 | |||
877 | TODO this is highly revlog centric and should be abstracted into |
|
877 | TODO this is highly revlog centric and should be abstracted into | |
878 | a higher-level deletion API. ``repair.strip()`` relies on this. |
|
878 | a higher-level deletion API. ``repair.strip()`` relies on this. | |
879 | """ |
|
879 | """ | |
880 |
|
880 | |||
881 | def strip(minlink, transaction): |
|
881 | def strip(minlink, transaction): | |
882 | """Remove storage of items starting at a linkrev. |
|
882 | """Remove storage of items starting at a linkrev. | |
883 |
|
883 | |||
884 | This uses ``getstrippoint()`` to determine the first node to remove. |
|
884 | This uses ``getstrippoint()`` to determine the first node to remove. | |
885 | Then it effectively truncates storage for all revisions after that. |
|
885 | Then it effectively truncates storage for all revisions after that. | |
886 |
|
886 | |||
887 | TODO this is highly revlog centric and should be abstracted into a |
|
887 | TODO this is highly revlog centric and should be abstracted into a | |
888 | higher-level deletion API. |
|
888 | higher-level deletion API. | |
889 | """ |
|
889 | """ | |
890 |
|
890 | |||
891 |
|
891 | |||
892 | class ifilestorage(ifileindex, ifiledata, ifilemutation): |
|
892 | class ifilestorage(ifileindex, ifiledata, ifilemutation): | |
893 | """Complete storage interface for a single tracked file.""" |
|
893 | """Complete storage interface for a single tracked file.""" | |
894 |
|
894 | |||
895 | def files(): |
|
895 | def files(): | |
896 | """Obtain paths that are backing storage for this file. |
|
896 | """Obtain paths that are backing storage for this file. | |
897 |
|
897 | |||
898 | TODO this is used heavily by verify code and there should probably |
|
898 | TODO this is used heavily by verify code and there should probably | |
899 | be a better API for that. |
|
899 | be a better API for that. | |
900 | """ |
|
900 | """ | |
901 |
|
901 | |||
902 | def storageinfo( |
|
902 | def storageinfo( | |
903 | exclusivefiles=False, |
|
903 | exclusivefiles=False, | |
904 | sharedfiles=False, |
|
904 | sharedfiles=False, | |
905 | revisionscount=False, |
|
905 | revisionscount=False, | |
906 | trackedsize=False, |
|
906 | trackedsize=False, | |
907 | storedsize=False, |
|
907 | storedsize=False, | |
908 | ): |
|
908 | ): | |
909 | """Obtain information about storage for this file's data. |
|
909 | """Obtain information about storage for this file's data. | |
910 |
|
910 | |||
911 | Returns a dict describing storage for this tracked path. The keys |
|
911 | Returns a dict describing storage for this tracked path. The keys | |
912 | in the dict map to arguments of the same. The arguments are bools |
|
912 | in the dict map to arguments of the same. The arguments are bools | |
913 | indicating whether to calculate and obtain that data. |
|
913 | indicating whether to calculate and obtain that data. | |
914 |
|
914 | |||
915 | exclusivefiles |
|
915 | exclusivefiles | |
916 | Iterable of (vfs, path) describing files that are exclusively |
|
916 | Iterable of (vfs, path) describing files that are exclusively | |
917 | used to back storage for this tracked path. |
|
917 | used to back storage for this tracked path. | |
918 |
|
918 | |||
919 | sharedfiles |
|
919 | sharedfiles | |
920 | Iterable of (vfs, path) describing files that are used to back |
|
920 | Iterable of (vfs, path) describing files that are used to back | |
921 | storage for this tracked path. Those files may also provide storage |
|
921 | storage for this tracked path. Those files may also provide storage | |
922 | for other stored entities. |
|
922 | for other stored entities. | |
923 |
|
923 | |||
924 | revisionscount |
|
924 | revisionscount | |
925 | Number of revisions available for retrieval. |
|
925 | Number of revisions available for retrieval. | |
926 |
|
926 | |||
927 | trackedsize |
|
927 | trackedsize | |
928 | Total size in bytes of all tracked revisions. This is a sum of the |
|
928 | Total size in bytes of all tracked revisions. This is a sum of the | |
929 | length of the fulltext of all revisions. |
|
929 | length of the fulltext of all revisions. | |
930 |
|
930 | |||
931 | storedsize |
|
931 | storedsize | |
932 | Total size in bytes used to store data for all tracked revisions. |
|
932 | Total size in bytes used to store data for all tracked revisions. | |
933 | This is commonly less than ``trackedsize`` due to internal usage |
|
933 | This is commonly less than ``trackedsize`` due to internal usage | |
934 | of deltas rather than fulltext revisions. |
|
934 | of deltas rather than fulltext revisions. | |
935 |
|
935 | |||
936 | Not all storage backends may support all queries are have a reasonable |
|
936 | Not all storage backends may support all queries are have a reasonable | |
937 | value to use. In that case, the value should be set to ``None`` and |
|
937 | value to use. In that case, the value should be set to ``None`` and | |
938 | callers are expected to handle this special value. |
|
938 | callers are expected to handle this special value. | |
939 | """ |
|
939 | """ | |
940 |
|
940 | |||
941 | def verifyintegrity(state): |
|
941 | def verifyintegrity(state): | |
942 | """Verifies the integrity of file storage. |
|
942 | """Verifies the integrity of file storage. | |
943 |
|
943 | |||
944 | ``state`` is a dict holding state of the verifier process. It can be |
|
944 | ``state`` is a dict holding state of the verifier process. It can be | |
945 | used to communicate data between invocations of multiple storage |
|
945 | used to communicate data between invocations of multiple storage | |
946 | primitives. |
|
946 | primitives. | |
947 |
|
947 | |||
948 | If individual revisions cannot have their revision content resolved, |
|
948 | If individual revisions cannot have their revision content resolved, | |
949 | the method is expected to set the ``skipread`` key to a set of nodes |
|
949 | the method is expected to set the ``skipread`` key to a set of nodes | |
950 | that encountered problems. If set, the method can also add the node(s) |
|
950 | that encountered problems. If set, the method can also add the node(s) | |
951 | to ``safe_renamed`` in order to indicate nodes that may perform the |
|
951 | to ``safe_renamed`` in order to indicate nodes that may perform the | |
952 | rename checks with currently accessible data. |
|
952 | rename checks with currently accessible data. | |
953 |
|
953 | |||
954 | The method yields objects conforming to the ``iverifyproblem`` |
|
954 | The method yields objects conforming to the ``iverifyproblem`` | |
955 | interface. |
|
955 | interface. | |
956 | """ |
|
956 | """ | |
957 |
|
957 | |||
958 |
|
958 | |||
959 | class idirs(interfaceutil.Interface): |
|
959 | class idirs(interfaceutil.Interface): | |
960 | """Interface representing a collection of directories from paths. |
|
960 | """Interface representing a collection of directories from paths. | |
961 |
|
961 | |||
962 | This interface is essentially a derived data structure representing |
|
962 | This interface is essentially a derived data structure representing | |
963 | directories from a collection of paths. |
|
963 | directories from a collection of paths. | |
964 | """ |
|
964 | """ | |
965 |
|
965 | |||
966 | def addpath(path): |
|
966 | def addpath(path): | |
967 | """Add a path to the collection. |
|
967 | """Add a path to the collection. | |
968 |
|
968 | |||
969 | All directories in the path will be added to the collection. |
|
969 | All directories in the path will be added to the collection. | |
970 | """ |
|
970 | """ | |
971 |
|
971 | |||
972 | def delpath(path): |
|
972 | def delpath(path): | |
973 | """Remove a path from the collection. |
|
973 | """Remove a path from the collection. | |
974 |
|
974 | |||
975 | If the removal was the last path in a particular directory, the |
|
975 | If the removal was the last path in a particular directory, the | |
976 | directory is removed from the collection. |
|
976 | directory is removed from the collection. | |
977 | """ |
|
977 | """ | |
978 |
|
978 | |||
979 | def __iter__(): |
|
979 | def __iter__(): | |
980 | """Iterate over the directories in this collection of paths.""" |
|
980 | """Iterate over the directories in this collection of paths.""" | |
981 |
|
981 | |||
982 | def __contains__(path): |
|
982 | def __contains__(path): | |
983 | """Whether a specific directory is in this collection.""" |
|
983 | """Whether a specific directory is in this collection.""" | |
984 |
|
984 | |||
985 |
|
985 | |||
986 | class imanifestdict(interfaceutil.Interface): |
|
986 | class imanifestdict(interfaceutil.Interface): | |
987 | """Interface representing a manifest data structure. |
|
987 | """Interface representing a manifest data structure. | |
988 |
|
988 | |||
989 | A manifest is effectively a dict mapping paths to entries. Each entry |
|
989 | A manifest is effectively a dict mapping paths to entries. Each entry | |
990 | consists of a binary node and extra flags affecting that entry. |
|
990 | consists of a binary node and extra flags affecting that entry. | |
991 | """ |
|
991 | """ | |
992 |
|
992 | |||
993 | def __getitem__(path): |
|
993 | def __getitem__(path): | |
994 | """Returns the binary node value for a path in the manifest. |
|
994 | """Returns the binary node value for a path in the manifest. | |
995 |
|
995 | |||
996 | Raises ``KeyError`` if the path does not exist in the manifest. |
|
996 | Raises ``KeyError`` if the path does not exist in the manifest. | |
997 |
|
997 | |||
998 | Equivalent to ``self.find(path)[0]``. |
|
998 | Equivalent to ``self.find(path)[0]``. | |
999 | """ |
|
999 | """ | |
1000 |
|
1000 | |||
1001 | def find(path): |
|
1001 | def find(path): | |
1002 | """Returns the entry for a path in the manifest. |
|
1002 | """Returns the entry for a path in the manifest. | |
1003 |
|
1003 | |||
1004 | Returns a 2-tuple of (node, flags). |
|
1004 | Returns a 2-tuple of (node, flags). | |
1005 |
|
1005 | |||
1006 | Raises ``KeyError`` if the path does not exist in the manifest. |
|
1006 | Raises ``KeyError`` if the path does not exist in the manifest. | |
1007 | """ |
|
1007 | """ | |
1008 |
|
1008 | |||
1009 | def __len__(): |
|
1009 | def __len__(): | |
1010 | """Return the number of entries in the manifest.""" |
|
1010 | """Return the number of entries in the manifest.""" | |
1011 |
|
1011 | |||
1012 | def __nonzero__(): |
|
1012 | def __nonzero__(): | |
1013 | """Returns True if the manifest has entries, False otherwise.""" |
|
1013 | """Returns True if the manifest has entries, False otherwise.""" | |
1014 |
|
1014 | |||
1015 | __bool__ = __nonzero__ |
|
1015 | __bool__ = __nonzero__ | |
1016 |
|
1016 | |||
1017 | def __setitem__(path, node): |
|
1017 | def __setitem__(path, node): | |
1018 | """Define the node value for a path in the manifest. |
|
1018 | """Define the node value for a path in the manifest. | |
1019 |
|
1019 | |||
1020 | If the path is already in the manifest, its flags will be copied to |
|
1020 | If the path is already in the manifest, its flags will be copied to | |
1021 | the new entry. |
|
1021 | the new entry. | |
1022 | """ |
|
1022 | """ | |
1023 |
|
1023 | |||
1024 | def __contains__(path): |
|
1024 | def __contains__(path): | |
1025 | """Whether a path exists in the manifest.""" |
|
1025 | """Whether a path exists in the manifest.""" | |
1026 |
|
1026 | |||
1027 | def __delitem__(path): |
|
1027 | def __delitem__(path): | |
1028 | """Remove a path from the manifest. |
|
1028 | """Remove a path from the manifest. | |
1029 |
|
1029 | |||
1030 | Raises ``KeyError`` if the path is not in the manifest. |
|
1030 | Raises ``KeyError`` if the path is not in the manifest. | |
1031 | """ |
|
1031 | """ | |
1032 |
|
1032 | |||
1033 | def __iter__(): |
|
1033 | def __iter__(): | |
1034 | """Iterate over paths in the manifest.""" |
|
1034 | """Iterate over paths in the manifest.""" | |
1035 |
|
1035 | |||
1036 | def iterkeys(): |
|
1036 | def iterkeys(): | |
1037 | """Iterate over paths in the manifest.""" |
|
1037 | """Iterate over paths in the manifest.""" | |
1038 |
|
1038 | |||
1039 | def keys(): |
|
1039 | def keys(): | |
1040 | """Obtain a list of paths in the manifest.""" |
|
1040 | """Obtain a list of paths in the manifest.""" | |
1041 |
|
1041 | |||
1042 | def filesnotin(other, match=None): |
|
1042 | def filesnotin(other, match=None): | |
1043 | """Obtain the set of paths in this manifest but not in another. |
|
1043 | """Obtain the set of paths in this manifest but not in another. | |
1044 |
|
1044 | |||
1045 | ``match`` is an optional matcher function to be applied to both |
|
1045 | ``match`` is an optional matcher function to be applied to both | |
1046 | manifests. |
|
1046 | manifests. | |
1047 |
|
1047 | |||
1048 | Returns a set of paths. |
|
1048 | Returns a set of paths. | |
1049 | """ |
|
1049 | """ | |
1050 |
|
1050 | |||
1051 | def dirs(): |
|
1051 | def dirs(): | |
1052 | """Returns an object implementing the ``idirs`` interface.""" |
|
1052 | """Returns an object implementing the ``idirs`` interface.""" | |
1053 |
|
1053 | |||
1054 | def hasdir(dir): |
|
1054 | def hasdir(dir): | |
1055 | """Returns a bool indicating if a directory is in this manifest.""" |
|
1055 | """Returns a bool indicating if a directory is in this manifest.""" | |
1056 |
|
1056 | |||
1057 | def walk(match): |
|
1057 | def walk(match): | |
1058 | """Generator of paths in manifest satisfying a matcher. |
|
1058 | """Generator of paths in manifest satisfying a matcher. | |
1059 |
|
1059 | |||
1060 | If the matcher has explicit files listed and they don't exist in |
|
1060 | If the matcher has explicit files listed and they don't exist in | |
1061 | the manifest, ``match.bad()`` is called for each missing file. |
|
1061 | the manifest, ``match.bad()`` is called for each missing file. | |
1062 | """ |
|
1062 | """ | |
1063 |
|
1063 | |||
1064 | def diff(other, match=None, clean=False): |
|
1064 | def diff(other, match=None, clean=False): | |
1065 | """Find differences between this manifest and another. |
|
1065 | """Find differences between this manifest and another. | |
1066 |
|
1066 | |||
1067 | This manifest is compared to ``other``. |
|
1067 | This manifest is compared to ``other``. | |
1068 |
|
1068 | |||
1069 | If ``match`` is provided, the two manifests are filtered against this |
|
1069 | If ``match`` is provided, the two manifests are filtered against this | |
1070 | matcher and only entries satisfying the matcher are compared. |
|
1070 | matcher and only entries satisfying the matcher are compared. | |
1071 |
|
1071 | |||
1072 | If ``clean`` is True, unchanged files are included in the returned |
|
1072 | If ``clean`` is True, unchanged files are included in the returned | |
1073 | object. |
|
1073 | object. | |
1074 |
|
1074 | |||
1075 | Returns a dict with paths as keys and values of 2-tuples of 2-tuples of |
|
1075 | Returns a dict with paths as keys and values of 2-tuples of 2-tuples of | |
1076 | the form ``((node1, flag1), (node2, flag2))`` where ``(node1, flag1)`` |
|
1076 | the form ``((node1, flag1), (node2, flag2))`` where ``(node1, flag1)`` | |
1077 | represents the node and flags for this manifest and ``(node2, flag2)`` |
|
1077 | represents the node and flags for this manifest and ``(node2, flag2)`` | |
1078 | are the same for the other manifest. |
|
1078 | are the same for the other manifest. | |
1079 | """ |
|
1079 | """ | |
1080 |
|
1080 | |||
1081 | def setflag(path, flag): |
|
1081 | def setflag(path, flag): | |
1082 | """Set the flag value for a given path. |
|
1082 | """Set the flag value for a given path. | |
1083 |
|
1083 | |||
1084 | Raises ``KeyError`` if the path is not already in the manifest. |
|
1084 | Raises ``KeyError`` if the path is not already in the manifest. | |
1085 | """ |
|
1085 | """ | |
1086 |
|
1086 | |||
1087 | def get(path, default=None): |
|
1087 | def get(path, default=None): | |
1088 | """Obtain the node value for a path or a default value if missing.""" |
|
1088 | """Obtain the node value for a path or a default value if missing.""" | |
1089 |
|
1089 | |||
1090 | def flags(path): |
|
1090 | def flags(path): | |
1091 | """Return the flags value for a path (default: empty bytestring).""" |
|
1091 | """Return the flags value for a path (default: empty bytestring).""" | |
1092 |
|
1092 | |||
1093 | def copy(): |
|
1093 | def copy(): | |
1094 | """Return a copy of this manifest.""" |
|
1094 | """Return a copy of this manifest.""" | |
1095 |
|
1095 | |||
1096 | def items(): |
|
1096 | def items(): | |
1097 | """Returns an iterable of (path, node) for items in this manifest.""" |
|
1097 | """Returns an iterable of (path, node) for items in this manifest.""" | |
1098 |
|
1098 | |||
1099 | def iteritems(): |
|
1099 | def iteritems(): | |
1100 | """Identical to items().""" |
|
1100 | """Identical to items().""" | |
1101 |
|
1101 | |||
1102 | def iterentries(): |
|
1102 | def iterentries(): | |
1103 | """Returns an iterable of (path, node, flags) for this manifest. |
|
1103 | """Returns an iterable of (path, node, flags) for this manifest. | |
1104 |
|
1104 | |||
1105 | Similar to ``iteritems()`` except items are a 3-tuple and include |
|
1105 | Similar to ``iteritems()`` except items are a 3-tuple and include | |
1106 | flags. |
|
1106 | flags. | |
1107 | """ |
|
1107 | """ | |
1108 |
|
1108 | |||
1109 | def text(): |
|
1109 | def text(): | |
1110 | """Obtain the raw data representation for this manifest. |
|
1110 | """Obtain the raw data representation for this manifest. | |
1111 |
|
1111 | |||
1112 | Result is used to create a manifest revision. |
|
1112 | Result is used to create a manifest revision. | |
1113 | """ |
|
1113 | """ | |
1114 |
|
1114 | |||
1115 | def fastdelta(base, changes): |
|
1115 | def fastdelta(base, changes): | |
1116 | """Obtain a delta between this manifest and another given changes. |
|
1116 | """Obtain a delta between this manifest and another given changes. | |
1117 |
|
1117 | |||
1118 | ``base`` in the raw data representation for another manifest. |
|
1118 | ``base`` in the raw data representation for another manifest. | |
1119 |
|
1119 | |||
1120 | ``changes`` is an iterable of ``(path, to_delete)``. |
|
1120 | ``changes`` is an iterable of ``(path, to_delete)``. | |
1121 |
|
1121 | |||
1122 | Returns a 2-tuple containing ``bytearray(self.text())`` and the |
|
1122 | Returns a 2-tuple containing ``bytearray(self.text())`` and the | |
1123 | delta between ``base`` and this manifest. |
|
1123 | delta between ``base`` and this manifest. | |
1124 |
|
1124 | |||
1125 | If this manifest implementation can't support ``fastdelta()``, |
|
1125 | If this manifest implementation can't support ``fastdelta()``, | |
1126 | raise ``mercurial.manifest.FastdeltaUnavailable``. |
|
1126 | raise ``mercurial.manifest.FastdeltaUnavailable``. | |
1127 | """ |
|
1127 | """ | |
1128 |
|
1128 | |||
1129 |
|
1129 | |||
1130 | class imanifestrevisionbase(interfaceutil.Interface): |
|
1130 | class imanifestrevisionbase(interfaceutil.Interface): | |
1131 | """Base interface representing a single revision of a manifest. |
|
1131 | """Base interface representing a single revision of a manifest. | |
1132 |
|
1132 | |||
1133 | Should not be used as a primary interface: should always be inherited |
|
1133 | Should not be used as a primary interface: should always be inherited | |
1134 | as part of a larger interface. |
|
1134 | as part of a larger interface. | |
1135 | """ |
|
1135 | """ | |
1136 |
|
1136 | |||
1137 | def copy(): |
|
1137 | def copy(): | |
1138 | """Obtain a copy of this manifest instance. |
|
1138 | """Obtain a copy of this manifest instance. | |
1139 |
|
1139 | |||
1140 | Returns an object conforming to the ``imanifestrevisionwritable`` |
|
1140 | Returns an object conforming to the ``imanifestrevisionwritable`` | |
1141 | interface. The instance will be associated with the same |
|
1141 | interface. The instance will be associated with the same | |
1142 | ``imanifestlog`` collection as this instance. |
|
1142 | ``imanifestlog`` collection as this instance. | |
1143 | """ |
|
1143 | """ | |
1144 |
|
1144 | |||
1145 | def read(): |
|
1145 | def read(): | |
1146 | """Obtain the parsed manifest data structure. |
|
1146 | """Obtain the parsed manifest data structure. | |
1147 |
|
1147 | |||
1148 | The returned object conforms to the ``imanifestdict`` interface. |
|
1148 | The returned object conforms to the ``imanifestdict`` interface. | |
1149 | """ |
|
1149 | """ | |
1150 |
|
1150 | |||
1151 |
|
1151 | |||
1152 | class imanifestrevisionstored(imanifestrevisionbase): |
|
1152 | class imanifestrevisionstored(imanifestrevisionbase): | |
1153 | """Interface representing a manifest revision committed to storage.""" |
|
1153 | """Interface representing a manifest revision committed to storage.""" | |
1154 |
|
1154 | |||
1155 | def node(): |
|
1155 | def node(): | |
1156 | """The binary node for this manifest.""" |
|
1156 | """The binary node for this manifest.""" | |
1157 |
|
1157 | |||
1158 | parents = interfaceutil.Attribute( |
|
1158 | parents = interfaceutil.Attribute( | |
1159 | """List of binary nodes that are parents for this manifest revision.""" |
|
1159 | """List of binary nodes that are parents for this manifest revision.""" | |
1160 | ) |
|
1160 | ) | |
1161 |
|
1161 | |||
1162 | def readdelta(shallow=False): |
|
1162 | def readdelta(shallow=False): | |
1163 | """Obtain the manifest data structure representing changes from parent. |
|
1163 | """Obtain the manifest data structure representing changes from parent. | |
1164 |
|
1164 | |||
1165 | This manifest is compared to its 1st parent. A new manifest representing |
|
1165 | This manifest is compared to its 1st parent. A new manifest representing | |
1166 | those differences is constructed. |
|
1166 | those differences is constructed. | |
1167 |
|
1167 | |||
1168 | The returned object conforms to the ``imanifestdict`` interface. |
|
1168 | The returned object conforms to the ``imanifestdict`` interface. | |
1169 | """ |
|
1169 | """ | |
1170 |
|
1170 | |||
1171 | def readfast(shallow=False): |
|
1171 | def readfast(shallow=False): | |
1172 | """Calls either ``read()`` or ``readdelta()``. |
|
1172 | """Calls either ``read()`` or ``readdelta()``. | |
1173 |
|
1173 | |||
1174 | The faster of the two options is called. |
|
1174 | The faster of the two options is called. | |
1175 | """ |
|
1175 | """ | |
1176 |
|
1176 | |||
1177 | def find(key): |
|
1177 | def find(key): | |
1178 | """Calls self.read().find(key)``. |
|
1178 | """Calls self.read().find(key)``. | |
1179 |
|
1179 | |||
1180 | Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``. |
|
1180 | Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``. | |
1181 | """ |
|
1181 | """ | |
1182 |
|
1182 | |||
1183 |
|
1183 | |||
1184 | class imanifestrevisionwritable(imanifestrevisionbase): |
|
1184 | class imanifestrevisionwritable(imanifestrevisionbase): | |
1185 | """Interface representing a manifest revision that can be committed.""" |
|
1185 | """Interface representing a manifest revision that can be committed.""" | |
1186 |
|
1186 | |||
1187 | def write(transaction, linkrev, p1node, p2node, added, removed, match=None): |
|
1187 | def write(transaction, linkrev, p1node, p2node, added, removed, match=None): | |
1188 | """Add this revision to storage. |
|
1188 | """Add this revision to storage. | |
1189 |
|
1189 | |||
1190 | Takes a transaction object, the changeset revision number it will |
|
1190 | Takes a transaction object, the changeset revision number it will | |
1191 | be associated with, its parent nodes, and lists of added and |
|
1191 | be associated with, its parent nodes, and lists of added and | |
1192 | removed paths. |
|
1192 | removed paths. | |
1193 |
|
1193 | |||
1194 | If match is provided, storage can choose not to inspect or write out |
|
1194 | If match is provided, storage can choose not to inspect or write out | |
1195 | items that do not match. Storage is still required to be able to provide |
|
1195 | items that do not match. Storage is still required to be able to provide | |
1196 | the full manifest in the future for any directories written (these |
|
1196 | the full manifest in the future for any directories written (these | |
1197 | manifests should not be "narrowed on disk"). |
|
1197 | manifests should not be "narrowed on disk"). | |
1198 |
|
1198 | |||
1199 | Returns the binary node of the created revision. |
|
1199 | Returns the binary node of the created revision. | |
1200 | """ |
|
1200 | """ | |
1201 |
|
1201 | |||
1202 |
|
1202 | |||
1203 | class imanifeststorage(interfaceutil.Interface): |
|
1203 | class imanifeststorage(interfaceutil.Interface): | |
1204 | """Storage interface for manifest data.""" |
|
1204 | """Storage interface for manifest data.""" | |
1205 |
|
1205 | |||
1206 | nodeconstants = interfaceutil.Attribute( |
|
1206 | nodeconstants = interfaceutil.Attribute( | |
1207 | """nodeconstants used by the current repository.""" |
|
1207 | """nodeconstants used by the current repository.""" | |
1208 | ) |
|
1208 | ) | |
1209 |
|
1209 | |||
1210 | tree = interfaceutil.Attribute( |
|
1210 | tree = interfaceutil.Attribute( | |
1211 | """The path to the directory this manifest tracks. |
|
1211 | """The path to the directory this manifest tracks. | |
1212 |
|
1212 | |||
1213 | The empty bytestring represents the root manifest. |
|
1213 | The empty bytestring represents the root manifest. | |
1214 | """ |
|
1214 | """ | |
1215 | ) |
|
1215 | ) | |
1216 |
|
1216 | |||
1217 | index = interfaceutil.Attribute( |
|
1217 | index = interfaceutil.Attribute( | |
1218 | """An ``ifilerevisionssequence`` instance.""" |
|
1218 | """An ``ifilerevisionssequence`` instance.""" | |
1219 | ) |
|
1219 | ) | |
1220 |
|
1220 | |||
1221 | opener = interfaceutil.Attribute( |
|
1221 | opener = interfaceutil.Attribute( | |
1222 | """VFS opener to use to access underlying files used for storage. |
|
1222 | """VFS opener to use to access underlying files used for storage. | |
1223 |
|
1223 | |||
1224 | TODO this is revlog specific and should not be exposed. |
|
1224 | TODO this is revlog specific and should not be exposed. | |
1225 | """ |
|
1225 | """ | |
1226 | ) |
|
1226 | ) | |
1227 |
|
1227 | |||
1228 | _generaldelta = interfaceutil.Attribute( |
|
1228 | _generaldelta = interfaceutil.Attribute( | |
1229 | """Whether generaldelta storage is being used. |
|
1229 | """Whether generaldelta storage is being used. | |
1230 |
|
1230 | |||
1231 | TODO this is revlog specific and should not be exposed. |
|
1231 | TODO this is revlog specific and should not be exposed. | |
1232 | """ |
|
1232 | """ | |
1233 | ) |
|
1233 | ) | |
1234 |
|
1234 | |||
1235 | fulltextcache = interfaceutil.Attribute( |
|
1235 | fulltextcache = interfaceutil.Attribute( | |
1236 | """Dict with cache of fulltexts. |
|
1236 | """Dict with cache of fulltexts. | |
1237 |
|
1237 | |||
1238 | TODO this doesn't feel appropriate for the storage interface. |
|
1238 | TODO this doesn't feel appropriate for the storage interface. | |
1239 | """ |
|
1239 | """ | |
1240 | ) |
|
1240 | ) | |
1241 |
|
1241 | |||
1242 | def __len__(): |
|
1242 | def __len__(): | |
1243 | """Obtain the number of revisions stored for this manifest.""" |
|
1243 | """Obtain the number of revisions stored for this manifest.""" | |
1244 |
|
1244 | |||
1245 | def __iter__(): |
|
1245 | def __iter__(): | |
1246 | """Iterate over revision numbers for this manifest.""" |
|
1246 | """Iterate over revision numbers for this manifest.""" | |
1247 |
|
1247 | |||
1248 | def rev(node): |
|
1248 | def rev(node): | |
1249 | """Obtain the revision number given a binary node. |
|
1249 | """Obtain the revision number given a binary node. | |
1250 |
|
1250 | |||
1251 | Raises ``error.LookupError`` if the node is not known. |
|
1251 | Raises ``error.LookupError`` if the node is not known. | |
1252 | """ |
|
1252 | """ | |
1253 |
|
1253 | |||
1254 | def node(rev): |
|
1254 | def node(rev): | |
1255 | """Obtain the node value given a revision number. |
|
1255 | """Obtain the node value given a revision number. | |
1256 |
|
1256 | |||
1257 | Raises ``error.LookupError`` if the revision is not known. |
|
1257 | Raises ``error.LookupError`` if the revision is not known. | |
1258 | """ |
|
1258 | """ | |
1259 |
|
1259 | |||
1260 | def lookup(value): |
|
1260 | def lookup(value): | |
1261 | """Attempt to resolve a value to a node. |
|
1261 | """Attempt to resolve a value to a node. | |
1262 |
|
1262 | |||
1263 | Value can be a binary node, hex node, revision number, or a bytes |
|
1263 | Value can be a binary node, hex node, revision number, or a bytes | |
1264 | that can be converted to an integer. |
|
1264 | that can be converted to an integer. | |
1265 |
|
1265 | |||
1266 | Raises ``error.LookupError`` if a ndoe could not be resolved. |
|
1266 | Raises ``error.LookupError`` if a ndoe could not be resolved. | |
1267 | """ |
|
1267 | """ | |
1268 |
|
1268 | |||
1269 | def parents(node): |
|
1269 | def parents(node): | |
1270 | """Returns a 2-tuple of parent nodes for a node. |
|
1270 | """Returns a 2-tuple of parent nodes for a node. | |
1271 |
|
1271 | |||
1272 | Values will be ``nullid`` if the parent is empty. |
|
1272 | Values will be ``nullid`` if the parent is empty. | |
1273 | """ |
|
1273 | """ | |
1274 |
|
1274 | |||
1275 | def parentrevs(rev): |
|
1275 | def parentrevs(rev): | |
1276 | """Like parents() but operates on revision numbers.""" |
|
1276 | """Like parents() but operates on revision numbers.""" | |
1277 |
|
1277 | |||
1278 | def linkrev(rev): |
|
1278 | def linkrev(rev): | |
1279 | """Obtain the changeset revision number a revision is linked to.""" |
|
1279 | """Obtain the changeset revision number a revision is linked to.""" | |
1280 |
|
1280 | |||
1281 | def revision(node, _df=None): |
|
1281 | def revision(node, _df=None): | |
1282 | """Obtain fulltext data for a node.""" |
|
1282 | """Obtain fulltext data for a node.""" | |
1283 |
|
1283 | |||
1284 | def rawdata(node, _df=None): |
|
1284 | def rawdata(node, _df=None): | |
1285 | """Obtain raw data for a node.""" |
|
1285 | """Obtain raw data for a node.""" | |
1286 |
|
1286 | |||
1287 | def revdiff(rev1, rev2): |
|
1287 | def revdiff(rev1, rev2): | |
1288 | """Obtain a delta between two revision numbers. |
|
1288 | """Obtain a delta between two revision numbers. | |
1289 |
|
1289 | |||
1290 | The returned data is the result of ``bdiff.bdiff()`` on the raw |
|
1290 | The returned data is the result of ``bdiff.bdiff()`` on the raw | |
1291 | revision data. |
|
1291 | revision data. | |
1292 | """ |
|
1292 | """ | |
1293 |
|
1293 | |||
1294 | def cmp(node, fulltext): |
|
1294 | def cmp(node, fulltext): | |
1295 | """Compare fulltext to another revision. |
|
1295 | """Compare fulltext to another revision. | |
1296 |
|
1296 | |||
1297 | Returns True if the fulltext is different from what is stored. |
|
1297 | Returns True if the fulltext is different from what is stored. | |
1298 | """ |
|
1298 | """ | |
1299 |
|
1299 | |||
1300 | def emitrevisions( |
|
1300 | def emitrevisions( | |
1301 | nodes, |
|
1301 | nodes, | |
1302 | nodesorder=None, |
|
1302 | nodesorder=None, | |
1303 | revisiondata=False, |
|
1303 | revisiondata=False, | |
1304 | assumehaveparentrevisions=False, |
|
1304 | assumehaveparentrevisions=False, | |
1305 | ): |
|
1305 | ): | |
1306 | """Produce ``irevisiondelta`` describing revisions. |
|
1306 | """Produce ``irevisiondelta`` describing revisions. | |
1307 |
|
1307 | |||
1308 | See the documentation for ``ifiledata`` for more. |
|
1308 | See the documentation for ``ifiledata`` for more. | |
1309 | """ |
|
1309 | """ | |
1310 |
|
1310 | |||
1311 | def addgroup( |
|
1311 | def addgroup( | |
1312 | deltas, |
|
1312 | deltas, | |
1313 | linkmapper, |
|
1313 | linkmapper, | |
1314 | transaction, |
|
1314 | transaction, | |
1315 | addrevisioncb=None, |
|
1315 | addrevisioncb=None, | |
1316 | duplicaterevisioncb=None, |
|
1316 | duplicaterevisioncb=None, | |
1317 | ): |
|
1317 | ): | |
1318 | """Process a series of deltas for storage. |
|
1318 | """Process a series of deltas for storage. | |
1319 |
|
1319 | |||
1320 | See the documentation in ``ifilemutation`` for more. |
|
1320 | See the documentation in ``ifilemutation`` for more. | |
1321 | """ |
|
1321 | """ | |
1322 |
|
1322 | |||
1323 | def rawsize(rev): |
|
1323 | def rawsize(rev): | |
1324 | """Obtain the size of tracked data. |
|
1324 | """Obtain the size of tracked data. | |
1325 |
|
1325 | |||
1326 | Is equivalent to ``len(m.rawdata(node))``. |
|
1326 | Is equivalent to ``len(m.rawdata(node))``. | |
1327 |
|
1327 | |||
1328 | TODO this method is only used by upgrade code and may be removed. |
|
1328 | TODO this method is only used by upgrade code and may be removed. | |
1329 | """ |
|
1329 | """ | |
1330 |
|
1330 | |||
1331 | def getstrippoint(minlink): |
|
1331 | def getstrippoint(minlink): | |
1332 | """Find minimum revision that must be stripped to strip a linkrev. |
|
1332 | """Find minimum revision that must be stripped to strip a linkrev. | |
1333 |
|
1333 | |||
1334 | See the documentation in ``ifilemutation`` for more. |
|
1334 | See the documentation in ``ifilemutation`` for more. | |
1335 | """ |
|
1335 | """ | |
1336 |
|
1336 | |||
1337 | def strip(minlink, transaction): |
|
1337 | def strip(minlink, transaction): | |
1338 | """Remove storage of items starting at a linkrev. |
|
1338 | """Remove storage of items starting at a linkrev. | |
1339 |
|
1339 | |||
1340 | See the documentation in ``ifilemutation`` for more. |
|
1340 | See the documentation in ``ifilemutation`` for more. | |
1341 | """ |
|
1341 | """ | |
1342 |
|
1342 | |||
1343 | def checksize(): |
|
1343 | def checksize(): | |
1344 | """Obtain the expected sizes of backing files. |
|
1344 | """Obtain the expected sizes of backing files. | |
1345 |
|
1345 | |||
1346 | TODO this is used by verify and it should not be part of the interface. |
|
1346 | TODO this is used by verify and it should not be part of the interface. | |
1347 | """ |
|
1347 | """ | |
1348 |
|
1348 | |||
1349 | def files(): |
|
1349 | def files(): | |
1350 | """Obtain paths that are backing storage for this manifest. |
|
1350 | """Obtain paths that are backing storage for this manifest. | |
1351 |
|
1351 | |||
1352 | TODO this is used by verify and there should probably be a better API |
|
1352 | TODO this is used by verify and there should probably be a better API | |
1353 | for this functionality. |
|
1353 | for this functionality. | |
1354 | """ |
|
1354 | """ | |
1355 |
|
1355 | |||
1356 | def deltaparent(rev): |
|
1356 | def deltaparent(rev): | |
1357 | """Obtain the revision that a revision is delta'd against. |
|
1357 | """Obtain the revision that a revision is delta'd against. | |
1358 |
|
1358 | |||
1359 | TODO delta encoding is an implementation detail of storage and should |
|
1359 | TODO delta encoding is an implementation detail of storage and should | |
1360 | not be exposed to the storage interface. |
|
1360 | not be exposed to the storage interface. | |
1361 | """ |
|
1361 | """ | |
1362 |
|
1362 | |||
1363 | def clone(tr, dest, **kwargs): |
|
1363 | def clone(tr, dest, **kwargs): | |
1364 | """Clone this instance to another.""" |
|
1364 | """Clone this instance to another.""" | |
1365 |
|
1365 | |||
1366 | def clearcaches(clear_persisted_data=False): |
|
1366 | def clearcaches(clear_persisted_data=False): | |
1367 | """Clear any caches associated with this instance.""" |
|
1367 | """Clear any caches associated with this instance.""" | |
1368 |
|
1368 | |||
1369 | def dirlog(d): |
|
1369 | def dirlog(d): | |
1370 | """Obtain a manifest storage instance for a tree.""" |
|
1370 | """Obtain a manifest storage instance for a tree.""" | |
1371 |
|
1371 | |||
1372 | def add( |
|
1372 | def add( | |
1373 | m, transaction, link, p1, p2, added, removed, readtree=None, match=None |
|
1373 | m, transaction, link, p1, p2, added, removed, readtree=None, match=None | |
1374 | ): |
|
1374 | ): | |
1375 | """Add a revision to storage. |
|
1375 | """Add a revision to storage. | |
1376 |
|
1376 | |||
1377 | ``m`` is an object conforming to ``imanifestdict``. |
|
1377 | ``m`` is an object conforming to ``imanifestdict``. | |
1378 |
|
1378 | |||
1379 | ``link`` is the linkrev revision number. |
|
1379 | ``link`` is the linkrev revision number. | |
1380 |
|
1380 | |||
1381 | ``p1`` and ``p2`` are the parent revision numbers. |
|
1381 | ``p1`` and ``p2`` are the parent revision numbers. | |
1382 |
|
1382 | |||
1383 | ``added`` and ``removed`` are iterables of added and removed paths, |
|
1383 | ``added`` and ``removed`` are iterables of added and removed paths, | |
1384 | respectively. |
|
1384 | respectively. | |
1385 |
|
1385 | |||
1386 | ``readtree`` is a function that can be used to read the child tree(s) |
|
1386 | ``readtree`` is a function that can be used to read the child tree(s) | |
1387 | when recursively writing the full tree structure when using |
|
1387 | when recursively writing the full tree structure when using | |
1388 | treemanifets. |
|
1388 | treemanifets. | |
1389 |
|
1389 | |||
1390 | ``match`` is a matcher that can be used to hint to storage that not all |
|
1390 | ``match`` is a matcher that can be used to hint to storage that not all | |
1391 | paths must be inspected; this is an optimization and can be safely |
|
1391 | paths must be inspected; this is an optimization and can be safely | |
1392 | ignored. Note that the storage must still be able to reproduce a full |
|
1392 | ignored. Note that the storage must still be able to reproduce a full | |
1393 | manifest including files that did not match. |
|
1393 | manifest including files that did not match. | |
1394 | """ |
|
1394 | """ | |
1395 |
|
1395 | |||
1396 | def storageinfo( |
|
1396 | def storageinfo( | |
1397 | exclusivefiles=False, |
|
1397 | exclusivefiles=False, | |
1398 | sharedfiles=False, |
|
1398 | sharedfiles=False, | |
1399 | revisionscount=False, |
|
1399 | revisionscount=False, | |
1400 | trackedsize=False, |
|
1400 | trackedsize=False, | |
1401 | storedsize=False, |
|
1401 | storedsize=False, | |
1402 | ): |
|
1402 | ): | |
1403 | """Obtain information about storage for this manifest's data. |
|
1403 | """Obtain information about storage for this manifest's data. | |
1404 |
|
1404 | |||
1405 | See ``ifilestorage.storageinfo()`` for a description of this method. |
|
1405 | See ``ifilestorage.storageinfo()`` for a description of this method. | |
1406 | This one behaves the same way, except for manifest data. |
|
1406 | This one behaves the same way, except for manifest data. | |
1407 | """ |
|
1407 | """ | |
1408 |
|
1408 | |||
1409 |
|
1409 | |||
1410 | class imanifestlog(interfaceutil.Interface): |
|
1410 | class imanifestlog(interfaceutil.Interface): | |
1411 | """Interface representing a collection of manifest snapshots. |
|
1411 | """Interface representing a collection of manifest snapshots. | |
1412 |
|
1412 | |||
1413 | Represents the root manifest in a repository. |
|
1413 | Represents the root manifest in a repository. | |
1414 |
|
1414 | |||
1415 | Also serves as a means to access nested tree manifests and to cache |
|
1415 | Also serves as a means to access nested tree manifests and to cache | |
1416 | tree manifests. |
|
1416 | tree manifests. | |
1417 | """ |
|
1417 | """ | |
1418 |
|
1418 | |||
1419 | nodeconstants = interfaceutil.Attribute( |
|
1419 | nodeconstants = interfaceutil.Attribute( | |
1420 | """nodeconstants used by the current repository.""" |
|
1420 | """nodeconstants used by the current repository.""" | |
1421 | ) |
|
1421 | ) | |
1422 |
|
1422 | |||
1423 | def __getitem__(node): |
|
1423 | def __getitem__(node): | |
1424 | """Obtain a manifest instance for a given binary node. |
|
1424 | """Obtain a manifest instance for a given binary node. | |
1425 |
|
1425 | |||
1426 | Equivalent to calling ``self.get('', node)``. |
|
1426 | Equivalent to calling ``self.get('', node)``. | |
1427 |
|
1427 | |||
1428 | The returned object conforms to the ``imanifestrevisionstored`` |
|
1428 | The returned object conforms to the ``imanifestrevisionstored`` | |
1429 | interface. |
|
1429 | interface. | |
1430 | """ |
|
1430 | """ | |
1431 |
|
1431 | |||
1432 | def get(tree, node, verify=True): |
|
1432 | def get(tree, node, verify=True): | |
1433 | """Retrieve the manifest instance for a given directory and binary node. |
|
1433 | """Retrieve the manifest instance for a given directory and binary node. | |
1434 |
|
1434 | |||
1435 | ``node`` always refers to the node of the root manifest (which will be |
|
1435 | ``node`` always refers to the node of the root manifest (which will be | |
1436 | the only manifest if flat manifests are being used). |
|
1436 | the only manifest if flat manifests are being used). | |
1437 |
|
1437 | |||
1438 | If ``tree`` is the empty string, the root manifest is returned. |
|
1438 | If ``tree`` is the empty string, the root manifest is returned. | |
1439 | Otherwise the manifest for the specified directory will be returned |
|
1439 | Otherwise the manifest for the specified directory will be returned | |
1440 | (requires tree manifests). |
|
1440 | (requires tree manifests). | |
1441 |
|
1441 | |||
1442 | If ``verify`` is True, ``LookupError`` is raised if the node is not |
|
1442 | If ``verify`` is True, ``LookupError`` is raised if the node is not | |
1443 | known. |
|
1443 | known. | |
1444 |
|
1444 | |||
1445 | The returned object conforms to the ``imanifestrevisionstored`` |
|
1445 | The returned object conforms to the ``imanifestrevisionstored`` | |
1446 | interface. |
|
1446 | interface. | |
1447 | """ |
|
1447 | """ | |
1448 |
|
1448 | |||
1449 | def getstorage(tree): |
|
1449 | def getstorage(tree): | |
1450 | """Retrieve an interface to storage for a particular tree. |
|
1450 | """Retrieve an interface to storage for a particular tree. | |
1451 |
|
1451 | |||
1452 | If ``tree`` is the empty bytestring, storage for the root manifest will |
|
1452 | If ``tree`` is the empty bytestring, storage for the root manifest will | |
1453 | be returned. Otherwise storage for a tree manifest is returned. |
|
1453 | be returned. Otherwise storage for a tree manifest is returned. | |
1454 |
|
1454 | |||
1455 | TODO formalize interface for returned object. |
|
1455 | TODO formalize interface for returned object. | |
1456 | """ |
|
1456 | """ | |
1457 |
|
1457 | |||
1458 | def clearcaches(): |
|
1458 | def clearcaches(): | |
1459 | """Clear caches associated with this collection.""" |
|
1459 | """Clear caches associated with this collection.""" | |
1460 |
|
1460 | |||
1461 | def rev(node): |
|
1461 | def rev(node): | |
1462 | """Obtain the revision number for a binary node. |
|
1462 | """Obtain the revision number for a binary node. | |
1463 |
|
1463 | |||
1464 | Raises ``error.LookupError`` if the node is not known. |
|
1464 | Raises ``error.LookupError`` if the node is not known. | |
1465 | """ |
|
1465 | """ | |
1466 |
|
1466 | |||
1467 | def update_caches(transaction): |
|
1467 | def update_caches(transaction): | |
1468 | """update whatever cache are relevant for the used storage.""" |
|
1468 | """update whatever cache are relevant for the used storage.""" | |
1469 |
|
1469 | |||
1470 |
|
1470 | |||
1471 | class ilocalrepositoryfilestorage(interfaceutil.Interface): |
|
1471 | class ilocalrepositoryfilestorage(interfaceutil.Interface): | |
1472 | """Local repository sub-interface providing access to tracked file storage. |
|
1472 | """Local repository sub-interface providing access to tracked file storage. | |
1473 |
|
1473 | |||
1474 | This interface defines how a repository accesses storage for a single |
|
1474 | This interface defines how a repository accesses storage for a single | |
1475 | tracked file path. |
|
1475 | tracked file path. | |
1476 | """ |
|
1476 | """ | |
1477 |
|
1477 | |||
1478 | def file(f): |
|
1478 | def file(f): | |
1479 | """Obtain a filelog for a tracked path. |
|
1479 | """Obtain a filelog for a tracked path. | |
1480 |
|
1480 | |||
1481 | The returned type conforms to the ``ifilestorage`` interface. |
|
1481 | The returned type conforms to the ``ifilestorage`` interface. | |
1482 | """ |
|
1482 | """ | |
1483 |
|
1483 | |||
1484 |
|
1484 | |||
1485 | class ilocalrepositorymain(interfaceutil.Interface): |
|
1485 | class ilocalrepositorymain(interfaceutil.Interface): | |
1486 | """Main interface for local repositories. |
|
1486 | """Main interface for local repositories. | |
1487 |
|
1487 | |||
1488 | This currently captures the reality of things - not how things should be. |
|
1488 | This currently captures the reality of things - not how things should be. | |
1489 | """ |
|
1489 | """ | |
1490 |
|
1490 | |||
1491 | nodeconstants = interfaceutil.Attribute( |
|
1491 | nodeconstants = interfaceutil.Attribute( | |
1492 | """Constant nodes matching the hash function used by the repository.""" |
|
1492 | """Constant nodes matching the hash function used by the repository.""" | |
1493 | ) |
|
1493 | ) | |
1494 | nullid = interfaceutil.Attribute( |
|
1494 | nullid = interfaceutil.Attribute( | |
1495 | """null revision for the hash function used by the repository.""" |
|
1495 | """null revision for the hash function used by the repository.""" | |
1496 | ) |
|
1496 | ) | |
1497 |
|
1497 | |||
1498 | supported = interfaceutil.Attribute( |
|
1498 | supported = interfaceutil.Attribute( | |
1499 | """Set of requirements that this repo is capable of opening.""" |
|
1499 | """Set of requirements that this repo is capable of opening.""" | |
1500 | ) |
|
1500 | ) | |
1501 |
|
1501 | |||
1502 | requirements = interfaceutil.Attribute( |
|
1502 | requirements = interfaceutil.Attribute( | |
1503 | """Set of requirements this repo uses.""" |
|
1503 | """Set of requirements this repo uses.""" | |
1504 | ) |
|
1504 | ) | |
1505 |
|
1505 | |||
1506 | features = interfaceutil.Attribute( |
|
1506 | features = interfaceutil.Attribute( | |
1507 | """Set of "features" this repository supports. |
|
1507 | """Set of "features" this repository supports. | |
1508 |
|
1508 | |||
1509 | A "feature" is a loosely-defined term. It can refer to a feature |
|
1509 | A "feature" is a loosely-defined term. It can refer to a feature | |
1510 | in the classical sense or can describe an implementation detail |
|
1510 | in the classical sense or can describe an implementation detail | |
1511 | of the repository. For example, a ``readonly`` feature may denote |
|
1511 | of the repository. For example, a ``readonly`` feature may denote | |
1512 | the repository as read-only. Or a ``revlogfilestore`` feature may |
|
1512 | the repository as read-only. Or a ``revlogfilestore`` feature may | |
1513 | denote that the repository is using revlogs for file storage. |
|
1513 | denote that the repository is using revlogs for file storage. | |
1514 |
|
1514 | |||
1515 | The intent of features is to provide a machine-queryable mechanism |
|
1515 | The intent of features is to provide a machine-queryable mechanism | |
1516 | for repo consumers to test for various repository characteristics. |
|
1516 | for repo consumers to test for various repository characteristics. | |
1517 |
|
1517 | |||
1518 | Features are similar to ``requirements``. The main difference is that |
|
1518 | Features are similar to ``requirements``. The main difference is that | |
1519 | requirements are stored on-disk and represent requirements to open the |
|
1519 | requirements are stored on-disk and represent requirements to open the | |
1520 | repository. Features are more run-time capabilities of the repository |
|
1520 | repository. Features are more run-time capabilities of the repository | |
1521 | and more granular capabilities (which may be derived from requirements). |
|
1521 | and more granular capabilities (which may be derived from requirements). | |
1522 | """ |
|
1522 | """ | |
1523 | ) |
|
1523 | ) | |
1524 |
|
1524 | |||
1525 | filtername = interfaceutil.Attribute( |
|
1525 | filtername = interfaceutil.Attribute( | |
1526 | """Name of the repoview that is active on this repo.""" |
|
1526 | """Name of the repoview that is active on this repo.""" | |
1527 | ) |
|
1527 | ) | |
1528 |
|
1528 | |||
1529 | wvfs = interfaceutil.Attribute( |
|
1529 | wvfs = interfaceutil.Attribute( | |
1530 | """VFS used to access the working directory.""" |
|
1530 | """VFS used to access the working directory.""" | |
1531 | ) |
|
1531 | ) | |
1532 |
|
1532 | |||
1533 | vfs = interfaceutil.Attribute( |
|
1533 | vfs = interfaceutil.Attribute( | |
1534 | """VFS rooted at the .hg directory. |
|
1534 | """VFS rooted at the .hg directory. | |
1535 |
|
1535 | |||
1536 | Used to access repository data not in the store. |
|
1536 | Used to access repository data not in the store. | |
1537 | """ |
|
1537 | """ | |
1538 | ) |
|
1538 | ) | |
1539 |
|
1539 | |||
1540 | svfs = interfaceutil.Attribute( |
|
1540 | svfs = interfaceutil.Attribute( | |
1541 | """VFS rooted at the store. |
|
1541 | """VFS rooted at the store. | |
1542 |
|
1542 | |||
1543 | Used to access repository data in the store. Typically .hg/store. |
|
1543 | Used to access repository data in the store. Typically .hg/store. | |
1544 | But can point elsewhere if the store is shared. |
|
1544 | But can point elsewhere if the store is shared. | |
1545 | """ |
|
1545 | """ | |
1546 | ) |
|
1546 | ) | |
1547 |
|
1547 | |||
1548 | root = interfaceutil.Attribute( |
|
1548 | root = interfaceutil.Attribute( | |
1549 | """Path to the root of the working directory.""" |
|
1549 | """Path to the root of the working directory.""" | |
1550 | ) |
|
1550 | ) | |
1551 |
|
1551 | |||
1552 | path = interfaceutil.Attribute("""Path to the .hg directory.""") |
|
1552 | path = interfaceutil.Attribute("""Path to the .hg directory.""") | |
1553 |
|
1553 | |||
1554 | origroot = interfaceutil.Attribute( |
|
1554 | origroot = interfaceutil.Attribute( | |
1555 | """The filesystem path that was used to construct the repo.""" |
|
1555 | """The filesystem path that was used to construct the repo.""" | |
1556 | ) |
|
1556 | ) | |
1557 |
|
1557 | |||
1558 | auditor = interfaceutil.Attribute( |
|
1558 | auditor = interfaceutil.Attribute( | |
1559 | """A pathauditor for the working directory. |
|
1559 | """A pathauditor for the working directory. | |
1560 |
|
1560 | |||
1561 | This checks if a path refers to a nested repository. |
|
1561 | This checks if a path refers to a nested repository. | |
1562 |
|
1562 | |||
1563 | Operates on the filesystem. |
|
1563 | Operates on the filesystem. | |
1564 | """ |
|
1564 | """ | |
1565 | ) |
|
1565 | ) | |
1566 |
|
1566 | |||
1567 | nofsauditor = interfaceutil.Attribute( |
|
1567 | nofsauditor = interfaceutil.Attribute( | |
1568 | """A pathauditor for the working directory. |
|
1568 | """A pathauditor for the working directory. | |
1569 |
|
1569 | |||
1570 | This is like ``auditor`` except it doesn't do filesystem checks. |
|
1570 | This is like ``auditor`` except it doesn't do filesystem checks. | |
1571 | """ |
|
1571 | """ | |
1572 | ) |
|
1572 | ) | |
1573 |
|
1573 | |||
1574 | baseui = interfaceutil.Attribute( |
|
1574 | baseui = interfaceutil.Attribute( | |
1575 | """Original ui instance passed into constructor.""" |
|
1575 | """Original ui instance passed into constructor.""" | |
1576 | ) |
|
1576 | ) | |
1577 |
|
1577 | |||
1578 | ui = interfaceutil.Attribute("""Main ui instance for this instance.""") |
|
1578 | ui = interfaceutil.Attribute("""Main ui instance for this instance.""") | |
1579 |
|
1579 | |||
1580 | sharedpath = interfaceutil.Attribute( |
|
1580 | sharedpath = interfaceutil.Attribute( | |
1581 | """Path to the .hg directory of the repo this repo was shared from.""" |
|
1581 | """Path to the .hg directory of the repo this repo was shared from.""" | |
1582 | ) |
|
1582 | ) | |
1583 |
|
1583 | |||
1584 | store = interfaceutil.Attribute("""A store instance.""") |
|
1584 | store = interfaceutil.Attribute("""A store instance.""") | |
1585 |
|
1585 | |||
1586 | spath = interfaceutil.Attribute("""Path to the store.""") |
|
1586 | spath = interfaceutil.Attribute("""Path to the store.""") | |
1587 |
|
1587 | |||
1588 | sjoin = interfaceutil.Attribute("""Alias to self.store.join.""") |
|
1588 | sjoin = interfaceutil.Attribute("""Alias to self.store.join.""") | |
1589 |
|
1589 | |||
1590 | cachevfs = interfaceutil.Attribute( |
|
1590 | cachevfs = interfaceutil.Attribute( | |
1591 | """A VFS used to access the cache directory. |
|
1591 | """A VFS used to access the cache directory. | |
1592 |
|
1592 | |||
1593 | Typically .hg/cache. |
|
1593 | Typically .hg/cache. | |
1594 | """ |
|
1594 | """ | |
1595 | ) |
|
1595 | ) | |
1596 |
|
1596 | |||
1597 | wcachevfs = interfaceutil.Attribute( |
|
1597 | wcachevfs = interfaceutil.Attribute( | |
1598 | """A VFS used to access the cache directory dedicated to working copy |
|
1598 | """A VFS used to access the cache directory dedicated to working copy | |
1599 |
|
1599 | |||
1600 | Typically .hg/wcache. |
|
1600 | Typically .hg/wcache. | |
1601 | """ |
|
1601 | """ | |
1602 | ) |
|
1602 | ) | |
1603 |
|
1603 | |||
1604 | filteredrevcache = interfaceutil.Attribute( |
|
1604 | filteredrevcache = interfaceutil.Attribute( | |
1605 | """Holds sets of revisions to be filtered.""" |
|
1605 | """Holds sets of revisions to be filtered.""" | |
1606 | ) |
|
1606 | ) | |
1607 |
|
1607 | |||
1608 | names = interfaceutil.Attribute("""A ``namespaces`` instance.""") |
|
1608 | names = interfaceutil.Attribute("""A ``namespaces`` instance.""") | |
1609 |
|
1609 | |||
1610 | filecopiesmode = interfaceutil.Attribute( |
|
1610 | filecopiesmode = interfaceutil.Attribute( | |
1611 | """The way files copies should be dealt with in this repo.""" |
|
1611 | """The way files copies should be dealt with in this repo.""" | |
1612 | ) |
|
1612 | ) | |
1613 |
|
1613 | |||
1614 | def close(): |
|
1614 | def close(): | |
1615 | """Close the handle on this repository.""" |
|
1615 | """Close the handle on this repository.""" | |
1616 |
|
1616 | |||
1617 | def peer(): |
|
1617 | def peer(): | |
1618 | """Obtain an object conforming to the ``peer`` interface.""" |
|
1618 | """Obtain an object conforming to the ``peer`` interface.""" | |
1619 |
|
1619 | |||
1620 | def unfiltered(): |
|
1620 | def unfiltered(): | |
1621 | """Obtain an unfiltered/raw view of this repo.""" |
|
1621 | """Obtain an unfiltered/raw view of this repo.""" | |
1622 |
|
1622 | |||
1623 | def filtered(name, visibilityexceptions=None): |
|
1623 | def filtered(name, visibilityexceptions=None): | |
1624 | """Obtain a named view of this repository.""" |
|
1624 | """Obtain a named view of this repository.""" | |
1625 |
|
1625 | |||
1626 | obsstore = interfaceutil.Attribute("""A store of obsolescence data.""") |
|
1626 | obsstore = interfaceutil.Attribute("""A store of obsolescence data.""") | |
1627 |
|
1627 | |||
1628 | changelog = interfaceutil.Attribute("""A handle on the changelog revlog.""") |
|
1628 | changelog = interfaceutil.Attribute("""A handle on the changelog revlog.""") | |
1629 |
|
1629 | |||
1630 | manifestlog = interfaceutil.Attribute( |
|
1630 | manifestlog = interfaceutil.Attribute( | |
1631 | """An instance conforming to the ``imanifestlog`` interface. |
|
1631 | """An instance conforming to the ``imanifestlog`` interface. | |
1632 |
|
1632 | |||
1633 | Provides access to manifests for the repository. |
|
1633 | Provides access to manifests for the repository. | |
1634 | """ |
|
1634 | """ | |
1635 | ) |
|
1635 | ) | |
1636 |
|
1636 | |||
1637 | dirstate = interfaceutil.Attribute("""Working directory state.""") |
|
1637 | dirstate = interfaceutil.Attribute("""Working directory state.""") | |
1638 |
|
1638 | |||
1639 | narrowpats = interfaceutil.Attribute( |
|
1639 | narrowpats = interfaceutil.Attribute( | |
1640 | """Matcher patterns for this repository's narrowspec.""" |
|
1640 | """Matcher patterns for this repository's narrowspec.""" | |
1641 | ) |
|
1641 | ) | |
1642 |
|
1642 | |||
1643 | def narrowmatch(match=None, includeexact=False): |
|
1643 | def narrowmatch(match=None, includeexact=False): | |
1644 | """Obtain a matcher for the narrowspec.""" |
|
1644 | """Obtain a matcher for the narrowspec.""" | |
1645 |
|
1645 | |||
1646 | def setnarrowpats(newincludes, newexcludes): |
|
1646 | def setnarrowpats(newincludes, newexcludes): | |
1647 | """Define the narrowspec for this repository.""" |
|
1647 | """Define the narrowspec for this repository.""" | |
1648 |
|
1648 | |||
1649 | def __getitem__(changeid): |
|
1649 | def __getitem__(changeid): | |
1650 | """Try to resolve a changectx.""" |
|
1650 | """Try to resolve a changectx.""" | |
1651 |
|
1651 | |||
1652 | def __contains__(changeid): |
|
1652 | def __contains__(changeid): | |
1653 | """Whether a changeset exists.""" |
|
1653 | """Whether a changeset exists.""" | |
1654 |
|
1654 | |||
1655 | def __nonzero__(): |
|
1655 | def __nonzero__(): | |
1656 | """Always returns True.""" |
|
1656 | """Always returns True.""" | |
1657 | return True |
|
1657 | return True | |
1658 |
|
1658 | |||
1659 | __bool__ = __nonzero__ |
|
1659 | __bool__ = __nonzero__ | |
1660 |
|
1660 | |||
1661 | def __len__(): |
|
1661 | def __len__(): | |
1662 | """Returns the number of changesets in the repo.""" |
|
1662 | """Returns the number of changesets in the repo.""" | |
1663 |
|
1663 | |||
1664 | def __iter__(): |
|
1664 | def __iter__(): | |
1665 | """Iterate over revisions in the changelog.""" |
|
1665 | """Iterate over revisions in the changelog.""" | |
1666 |
|
1666 | |||
1667 | def revs(expr, *args): |
|
1667 | def revs(expr, *args): | |
1668 | """Evaluate a revset. |
|
1668 | """Evaluate a revset. | |
1669 |
|
1669 | |||
1670 | Emits revisions. |
|
1670 | Emits revisions. | |
1671 | """ |
|
1671 | """ | |
1672 |
|
1672 | |||
1673 | def set(expr, *args): |
|
1673 | def set(expr, *args): | |
1674 | """Evaluate a revset. |
|
1674 | """Evaluate a revset. | |
1675 |
|
1675 | |||
1676 | Emits changectx instances. |
|
1676 | Emits changectx instances. | |
1677 | """ |
|
1677 | """ | |
1678 |
|
1678 | |||
1679 | def anyrevs(specs, user=False, localalias=None): |
|
1679 | def anyrevs(specs, user=False, localalias=None): | |
1680 | """Find revisions matching one of the given revsets.""" |
|
1680 | """Find revisions matching one of the given revsets.""" | |
1681 |
|
1681 | |||
1682 | def url(): |
|
1682 | def url(): | |
1683 | """Returns a string representing the location of this repo.""" |
|
1683 | """Returns a string representing the location of this repo.""" | |
1684 |
|
1684 | |||
1685 | def hook(name, throw=False, **args): |
|
1685 | def hook(name, throw=False, **args): | |
1686 | """Call a hook.""" |
|
1686 | """Call a hook.""" | |
1687 |
|
1687 | |||
1688 | def tags(): |
|
1688 | def tags(): | |
1689 | """Return a mapping of tag to node.""" |
|
1689 | """Return a mapping of tag to node.""" | |
1690 |
|
1690 | |||
1691 | def tagtype(tagname): |
|
1691 | def tagtype(tagname): | |
1692 | """Return the type of a given tag.""" |
|
1692 | """Return the type of a given tag.""" | |
1693 |
|
1693 | |||
1694 | def tagslist(): |
|
1694 | def tagslist(): | |
1695 | """Return a list of tags ordered by revision.""" |
|
1695 | """Return a list of tags ordered by revision.""" | |
1696 |
|
1696 | |||
1697 | def nodetags(node): |
|
1697 | def nodetags(node): | |
1698 | """Return the tags associated with a node.""" |
|
1698 | """Return the tags associated with a node.""" | |
1699 |
|
1699 | |||
1700 | def nodebookmarks(node): |
|
1700 | def nodebookmarks(node): | |
1701 | """Return the list of bookmarks pointing to the specified node.""" |
|
1701 | """Return the list of bookmarks pointing to the specified node.""" | |
1702 |
|
1702 | |||
1703 | def branchmap(): |
|
1703 | def branchmap(): | |
1704 | """Return a mapping of branch to heads in that branch.""" |
|
1704 | """Return a mapping of branch to heads in that branch.""" | |
1705 |
|
1705 | |||
1706 | def revbranchcache(): |
|
1706 | def revbranchcache(): | |
1707 | pass |
|
1707 | pass | |
1708 |
|
1708 | |||
1709 | def register_changeset(rev, changelogrevision): |
|
1709 | def register_changeset(rev, changelogrevision): | |
1710 | """Extension point for caches for new nodes. |
|
1710 | """Extension point for caches for new nodes. | |
1711 |
|
1711 | |||
1712 | Multiple consumers are expected to need parts of the changelogrevision, |
|
1712 | Multiple consumers are expected to need parts of the changelogrevision, | |
1713 | so it is provided as optimization to avoid duplicate lookups. A simple |
|
1713 | so it is provided as optimization to avoid duplicate lookups. A simple | |
1714 | cache would be fragile when other revisions are accessed, too.""" |
|
1714 | cache would be fragile when other revisions are accessed, too.""" | |
1715 | pass |
|
1715 | pass | |
1716 |
|
1716 | |||
1717 | def branchtip(branchtip, ignoremissing=False): |
|
1717 | def branchtip(branchtip, ignoremissing=False): | |
1718 | """Return the tip node for a given branch.""" |
|
1718 | """Return the tip node for a given branch.""" | |
1719 |
|
1719 | |||
1720 | def lookup(key): |
|
1720 | def lookup(key): | |
1721 | """Resolve the node for a revision.""" |
|
1721 | """Resolve the node for a revision.""" | |
1722 |
|
1722 | |||
1723 | def lookupbranch(key): |
|
1723 | def lookupbranch(key): | |
1724 | """Look up the branch name of the given revision or branch name.""" |
|
1724 | """Look up the branch name of the given revision or branch name.""" | |
1725 |
|
1725 | |||
1726 | def known(nodes): |
|
1726 | def known(nodes): | |
1727 | """Determine whether a series of nodes is known. |
|
1727 | """Determine whether a series of nodes is known. | |
1728 |
|
1728 | |||
1729 | Returns a list of bools. |
|
1729 | Returns a list of bools. | |
1730 | """ |
|
1730 | """ | |
1731 |
|
1731 | |||
1732 | def local(): |
|
1732 | def local(): | |
1733 | """Whether the repository is local.""" |
|
1733 | """Whether the repository is local.""" | |
1734 | return True |
|
1734 | return True | |
1735 |
|
1735 | |||
1736 | def publishing(): |
|
1736 | def publishing(): | |
1737 | """Whether the repository is a publishing repository.""" |
|
1737 | """Whether the repository is a publishing repository.""" | |
1738 |
|
1738 | |||
1739 | def cancopy(): |
|
1739 | def cancopy(): | |
1740 | pass |
|
1740 | pass | |
1741 |
|
1741 | |||
1742 | def shared(): |
|
1742 | def shared(): | |
1743 | """The type of shared repository or None.""" |
|
1743 | """The type of shared repository or None.""" | |
1744 |
|
1744 | |||
1745 | def wjoin(f, *insidef): |
|
1745 | def wjoin(f, *insidef): | |
1746 | """Calls self.vfs.reljoin(self.root, f, *insidef)""" |
|
1746 | """Calls self.vfs.reljoin(self.root, f, *insidef)""" | |
1747 |
|
1747 | |||
1748 | def setparents(p1, p2): |
|
1748 | def setparents(p1, p2): | |
1749 | """Set the parent nodes of the working directory.""" |
|
1749 | """Set the parent nodes of the working directory.""" | |
1750 |
|
1750 | |||
1751 | def filectx(path, changeid=None, fileid=None): |
|
1751 | def filectx(path, changeid=None, fileid=None): | |
1752 | """Obtain a filectx for the given file revision.""" |
|
1752 | """Obtain a filectx for the given file revision.""" | |
1753 |
|
1753 | |||
1754 | def getcwd(): |
|
1754 | def getcwd(): | |
1755 | """Obtain the current working directory from the dirstate.""" |
|
1755 | """Obtain the current working directory from the dirstate.""" | |
1756 |
|
1756 | |||
1757 | def pathto(f, cwd=None): |
|
1757 | def pathto(f, cwd=None): | |
1758 | """Obtain the relative path to a file.""" |
|
1758 | """Obtain the relative path to a file.""" | |
1759 |
|
1759 | |||
1760 | def adddatafilter(name, fltr): |
|
1760 | def adddatafilter(name, fltr): | |
1761 | pass |
|
1761 | pass | |
1762 |
|
1762 | |||
1763 | def wread(filename): |
|
1763 | def wread(filename): | |
1764 | """Read a file from wvfs, using data filters.""" |
|
1764 | """Read a file from wvfs, using data filters.""" | |
1765 |
|
1765 | |||
1766 | def wwrite(filename, data, flags, backgroundclose=False, **kwargs): |
|
1766 | def wwrite(filename, data, flags, backgroundclose=False, **kwargs): | |
1767 | """Write data to a file in the wvfs, using data filters.""" |
|
1767 | """Write data to a file in the wvfs, using data filters.""" | |
1768 |
|
1768 | |||
1769 | def wwritedata(filename, data): |
|
1769 | def wwritedata(filename, data): | |
1770 | """Resolve data for writing to the wvfs, using data filters.""" |
|
1770 | """Resolve data for writing to the wvfs, using data filters.""" | |
1771 |
|
1771 | |||
1772 | def currenttransaction(): |
|
1772 | def currenttransaction(): | |
1773 | """Obtain the current transaction instance or None.""" |
|
1773 | """Obtain the current transaction instance or None.""" | |
1774 |
|
1774 | |||
1775 | def transaction(desc, report=None): |
|
1775 | def transaction(desc, report=None): | |
1776 | """Open a new transaction to write to the repository.""" |
|
1776 | """Open a new transaction to write to the repository.""" | |
1777 |
|
1777 | |||
1778 | def undofiles(): |
|
1778 | def undofiles(): | |
1779 | """Returns a list of (vfs, path) for files to undo transactions.""" |
|
1779 | """Returns a list of (vfs, path) for files to undo transactions.""" | |
1780 |
|
1780 | |||
1781 | def recover(): |
|
1781 | def recover(): | |
1782 | """Roll back an interrupted transaction.""" |
|
1782 | """Roll back an interrupted transaction.""" | |
1783 |
|
1783 | |||
1784 | def rollback(dryrun=False, force=False): |
|
1784 | def rollback(dryrun=False, force=False): | |
1785 | """Undo the last transaction. |
|
1785 | """Undo the last transaction. | |
1786 |
|
1786 | |||
1787 | DANGEROUS. |
|
1787 | DANGEROUS. | |
1788 | """ |
|
1788 | """ | |
1789 |
|
1789 | |||
1790 | def updatecaches(tr=None, full=False): |
|
1790 | def updatecaches(tr=None, full=False, caches=None): | |
1791 | """Warm repo caches.""" |
|
1791 | """Warm repo caches.""" | |
1792 |
|
1792 | |||
1793 | def invalidatecaches(): |
|
1793 | def invalidatecaches(): | |
1794 | """Invalidate cached data due to the repository mutating.""" |
|
1794 | """Invalidate cached data due to the repository mutating.""" | |
1795 |
|
1795 | |||
1796 | def invalidatevolatilesets(): |
|
1796 | def invalidatevolatilesets(): | |
1797 | pass |
|
1797 | pass | |
1798 |
|
1798 | |||
1799 | def invalidatedirstate(): |
|
1799 | def invalidatedirstate(): | |
1800 | """Invalidate the dirstate.""" |
|
1800 | """Invalidate the dirstate.""" | |
1801 |
|
1801 | |||
1802 | def invalidate(clearfilecache=False): |
|
1802 | def invalidate(clearfilecache=False): | |
1803 | pass |
|
1803 | pass | |
1804 |
|
1804 | |||
1805 | def invalidateall(): |
|
1805 | def invalidateall(): | |
1806 | pass |
|
1806 | pass | |
1807 |
|
1807 | |||
1808 | def lock(wait=True): |
|
1808 | def lock(wait=True): | |
1809 | """Lock the repository store and return a lock instance.""" |
|
1809 | """Lock the repository store and return a lock instance.""" | |
1810 |
|
1810 | |||
1811 | def wlock(wait=True): |
|
1811 | def wlock(wait=True): | |
1812 | """Lock the non-store parts of the repository.""" |
|
1812 | """Lock the non-store parts of the repository.""" | |
1813 |
|
1813 | |||
1814 | def currentwlock(): |
|
1814 | def currentwlock(): | |
1815 | """Return the wlock if it's held or None.""" |
|
1815 | """Return the wlock if it's held or None.""" | |
1816 |
|
1816 | |||
1817 | def checkcommitpatterns(wctx, match, status, fail): |
|
1817 | def checkcommitpatterns(wctx, match, status, fail): | |
1818 | pass |
|
1818 | pass | |
1819 |
|
1819 | |||
1820 | def commit( |
|
1820 | def commit( | |
1821 | text=b'', |
|
1821 | text=b'', | |
1822 | user=None, |
|
1822 | user=None, | |
1823 | date=None, |
|
1823 | date=None, | |
1824 | match=None, |
|
1824 | match=None, | |
1825 | force=False, |
|
1825 | force=False, | |
1826 | editor=False, |
|
1826 | editor=False, | |
1827 | extra=None, |
|
1827 | extra=None, | |
1828 | ): |
|
1828 | ): | |
1829 | """Add a new revision to the repository.""" |
|
1829 | """Add a new revision to the repository.""" | |
1830 |
|
1830 | |||
1831 | def commitctx(ctx, error=False, origctx=None): |
|
1831 | def commitctx(ctx, error=False, origctx=None): | |
1832 | """Commit a commitctx instance to the repository.""" |
|
1832 | """Commit a commitctx instance to the repository.""" | |
1833 |
|
1833 | |||
1834 | def destroying(): |
|
1834 | def destroying(): | |
1835 | """Inform the repository that nodes are about to be destroyed.""" |
|
1835 | """Inform the repository that nodes are about to be destroyed.""" | |
1836 |
|
1836 | |||
1837 | def destroyed(): |
|
1837 | def destroyed(): | |
1838 | """Inform the repository that nodes have been destroyed.""" |
|
1838 | """Inform the repository that nodes have been destroyed.""" | |
1839 |
|
1839 | |||
1840 | def status( |
|
1840 | def status( | |
1841 | node1=b'.', |
|
1841 | node1=b'.', | |
1842 | node2=None, |
|
1842 | node2=None, | |
1843 | match=None, |
|
1843 | match=None, | |
1844 | ignored=False, |
|
1844 | ignored=False, | |
1845 | clean=False, |
|
1845 | clean=False, | |
1846 | unknown=False, |
|
1846 | unknown=False, | |
1847 | listsubrepos=False, |
|
1847 | listsubrepos=False, | |
1848 | ): |
|
1848 | ): | |
1849 | """Convenience method to call repo[x].status().""" |
|
1849 | """Convenience method to call repo[x].status().""" | |
1850 |
|
1850 | |||
1851 | def addpostdsstatus(ps): |
|
1851 | def addpostdsstatus(ps): | |
1852 | pass |
|
1852 | pass | |
1853 |
|
1853 | |||
1854 | def postdsstatus(): |
|
1854 | def postdsstatus(): | |
1855 | pass |
|
1855 | pass | |
1856 |
|
1856 | |||
1857 | def clearpostdsstatus(): |
|
1857 | def clearpostdsstatus(): | |
1858 | pass |
|
1858 | pass | |
1859 |
|
1859 | |||
1860 | def heads(start=None): |
|
1860 | def heads(start=None): | |
1861 | """Obtain list of nodes that are DAG heads.""" |
|
1861 | """Obtain list of nodes that are DAG heads.""" | |
1862 |
|
1862 | |||
1863 | def branchheads(branch=None, start=None, closed=False): |
|
1863 | def branchheads(branch=None, start=None, closed=False): | |
1864 | pass |
|
1864 | pass | |
1865 |
|
1865 | |||
1866 | def branches(nodes): |
|
1866 | def branches(nodes): | |
1867 | pass |
|
1867 | pass | |
1868 |
|
1868 | |||
1869 | def between(pairs): |
|
1869 | def between(pairs): | |
1870 | pass |
|
1870 | pass | |
1871 |
|
1871 | |||
1872 | def checkpush(pushop): |
|
1872 | def checkpush(pushop): | |
1873 | pass |
|
1873 | pass | |
1874 |
|
1874 | |||
1875 | prepushoutgoinghooks = interfaceutil.Attribute("""util.hooks instance.""") |
|
1875 | prepushoutgoinghooks = interfaceutil.Attribute("""util.hooks instance.""") | |
1876 |
|
1876 | |||
1877 | def pushkey(namespace, key, old, new): |
|
1877 | def pushkey(namespace, key, old, new): | |
1878 | pass |
|
1878 | pass | |
1879 |
|
1879 | |||
1880 | def listkeys(namespace): |
|
1880 | def listkeys(namespace): | |
1881 | pass |
|
1881 | pass | |
1882 |
|
1882 | |||
1883 | def debugwireargs(one, two, three=None, four=None, five=None): |
|
1883 | def debugwireargs(one, two, three=None, four=None, five=None): | |
1884 | pass |
|
1884 | pass | |
1885 |
|
1885 | |||
1886 | def savecommitmessage(text): |
|
1886 | def savecommitmessage(text): | |
1887 | pass |
|
1887 | pass | |
1888 |
|
1888 | |||
1889 | def register_sidedata_computer( |
|
1889 | def register_sidedata_computer( | |
1890 | kind, category, keys, computer, flags, replace=False |
|
1890 | kind, category, keys, computer, flags, replace=False | |
1891 | ): |
|
1891 | ): | |
1892 | pass |
|
1892 | pass | |
1893 |
|
1893 | |||
1894 | def register_wanted_sidedata(category): |
|
1894 | def register_wanted_sidedata(category): | |
1895 | pass |
|
1895 | pass | |
1896 |
|
1896 | |||
1897 |
|
1897 | |||
1898 | class completelocalrepository( |
|
1898 | class completelocalrepository( | |
1899 | ilocalrepositorymain, ilocalrepositoryfilestorage |
|
1899 | ilocalrepositorymain, ilocalrepositoryfilestorage | |
1900 | ): |
|
1900 | ): | |
1901 | """Complete interface for a local repository.""" |
|
1901 | """Complete interface for a local repository.""" | |
1902 |
|
1902 | |||
1903 |
|
1903 | |||
1904 | class iwireprotocolcommandcacher(interfaceutil.Interface): |
|
1904 | class iwireprotocolcommandcacher(interfaceutil.Interface): | |
1905 | """Represents a caching backend for wire protocol commands. |
|
1905 | """Represents a caching backend for wire protocol commands. | |
1906 |
|
1906 | |||
1907 | Wire protocol version 2 supports transparent caching of many commands. |
|
1907 | Wire protocol version 2 supports transparent caching of many commands. | |
1908 | To leverage this caching, servers can activate objects that cache |
|
1908 | To leverage this caching, servers can activate objects that cache | |
1909 | command responses. Objects handle both cache writing and reading. |
|
1909 | command responses. Objects handle both cache writing and reading. | |
1910 | This interface defines how that response caching mechanism works. |
|
1910 | This interface defines how that response caching mechanism works. | |
1911 |
|
1911 | |||
1912 | Wire protocol version 2 commands emit a series of objects that are |
|
1912 | Wire protocol version 2 commands emit a series of objects that are | |
1913 | serialized and sent to the client. The caching layer exists between |
|
1913 | serialized and sent to the client. The caching layer exists between | |
1914 | the invocation of the command function and the sending of its output |
|
1914 | the invocation of the command function and the sending of its output | |
1915 | objects to an output layer. |
|
1915 | objects to an output layer. | |
1916 |
|
1916 | |||
1917 | Instances of this interface represent a binding to a cache that |
|
1917 | Instances of this interface represent a binding to a cache that | |
1918 | can serve a response (in place of calling a command function) and/or |
|
1918 | can serve a response (in place of calling a command function) and/or | |
1919 | write responses to a cache for subsequent use. |
|
1919 | write responses to a cache for subsequent use. | |
1920 |
|
1920 | |||
1921 | When a command request arrives, the following happens with regards |
|
1921 | When a command request arrives, the following happens with regards | |
1922 | to this interface: |
|
1922 | to this interface: | |
1923 |
|
1923 | |||
1924 | 1. The server determines whether the command request is cacheable. |
|
1924 | 1. The server determines whether the command request is cacheable. | |
1925 | 2. If it is, an instance of this interface is spawned. |
|
1925 | 2. If it is, an instance of this interface is spawned. | |
1926 | 3. The cacher is activated in a context manager (``__enter__`` is called). |
|
1926 | 3. The cacher is activated in a context manager (``__enter__`` is called). | |
1927 | 4. A cache *key* for that request is derived. This will call the |
|
1927 | 4. A cache *key* for that request is derived. This will call the | |
1928 | instance's ``adjustcachekeystate()`` method so the derivation |
|
1928 | instance's ``adjustcachekeystate()`` method so the derivation | |
1929 | can be influenced. |
|
1929 | can be influenced. | |
1930 | 5. The cacher is informed of the derived cache key via a call to |
|
1930 | 5. The cacher is informed of the derived cache key via a call to | |
1931 | ``setcachekey()``. |
|
1931 | ``setcachekey()``. | |
1932 | 6. The cacher's ``lookup()`` method is called to test for presence of |
|
1932 | 6. The cacher's ``lookup()`` method is called to test for presence of | |
1933 | the derived key in the cache. |
|
1933 | the derived key in the cache. | |
1934 | 7. If ``lookup()`` returns a hit, that cached result is used in place |
|
1934 | 7. If ``lookup()`` returns a hit, that cached result is used in place | |
1935 | of invoking the command function. ``__exit__`` is called and the instance |
|
1935 | of invoking the command function. ``__exit__`` is called and the instance | |
1936 | is discarded. |
|
1936 | is discarded. | |
1937 | 8. The command function is invoked. |
|
1937 | 8. The command function is invoked. | |
1938 | 9. ``onobject()`` is called for each object emitted by the command |
|
1938 | 9. ``onobject()`` is called for each object emitted by the command | |
1939 | function. |
|
1939 | function. | |
1940 | 10. After the final object is seen, ``onfinished()`` is called. |
|
1940 | 10. After the final object is seen, ``onfinished()`` is called. | |
1941 | 11. ``__exit__`` is called to signal the end of use of the instance. |
|
1941 | 11. ``__exit__`` is called to signal the end of use of the instance. | |
1942 |
|
1942 | |||
1943 | Cache *key* derivation can be influenced by the instance. |
|
1943 | Cache *key* derivation can be influenced by the instance. | |
1944 |
|
1944 | |||
1945 | Cache keys are initially derived by a deterministic representation of |
|
1945 | Cache keys are initially derived by a deterministic representation of | |
1946 | the command request. This includes the command name, arguments, protocol |
|
1946 | the command request. This includes the command name, arguments, protocol | |
1947 | version, etc. This initial key derivation is performed by CBOR-encoding a |
|
1947 | version, etc. This initial key derivation is performed by CBOR-encoding a | |
1948 | data structure and feeding that output into a hasher. |
|
1948 | data structure and feeding that output into a hasher. | |
1949 |
|
1949 | |||
1950 | Instances of this interface can influence this initial key derivation |
|
1950 | Instances of this interface can influence this initial key derivation | |
1951 | via ``adjustcachekeystate()``. |
|
1951 | via ``adjustcachekeystate()``. | |
1952 |
|
1952 | |||
1953 | The instance is informed of the derived cache key via a call to |
|
1953 | The instance is informed of the derived cache key via a call to | |
1954 | ``setcachekey()``. The instance must store the key locally so it can |
|
1954 | ``setcachekey()``. The instance must store the key locally so it can | |
1955 | be consulted on subsequent operations that may require it. |
|
1955 | be consulted on subsequent operations that may require it. | |
1956 |
|
1956 | |||
1957 | When constructed, the instance has access to a callable that can be used |
|
1957 | When constructed, the instance has access to a callable that can be used | |
1958 | for encoding response objects. This callable receives as its single |
|
1958 | for encoding response objects. This callable receives as its single | |
1959 | argument an object emitted by a command function. It returns an iterable |
|
1959 | argument an object emitted by a command function. It returns an iterable | |
1960 | of bytes chunks representing the encoded object. Unless the cacher is |
|
1960 | of bytes chunks representing the encoded object. Unless the cacher is | |
1961 | caching native Python objects in memory or has a way of reconstructing |
|
1961 | caching native Python objects in memory or has a way of reconstructing | |
1962 | the original Python objects, implementations typically call this function |
|
1962 | the original Python objects, implementations typically call this function | |
1963 | to produce bytes from the output objects and then store those bytes in |
|
1963 | to produce bytes from the output objects and then store those bytes in | |
1964 | the cache. When it comes time to re-emit those bytes, they are wrapped |
|
1964 | the cache. When it comes time to re-emit those bytes, they are wrapped | |
1965 | in a ``wireprototypes.encodedresponse`` instance to tell the output |
|
1965 | in a ``wireprototypes.encodedresponse`` instance to tell the output | |
1966 | layer that they are pre-encoded. |
|
1966 | layer that they are pre-encoded. | |
1967 |
|
1967 | |||
1968 | When receiving the objects emitted by the command function, instances |
|
1968 | When receiving the objects emitted by the command function, instances | |
1969 | can choose what to do with those objects. The simplest thing to do is |
|
1969 | can choose what to do with those objects. The simplest thing to do is | |
1970 | re-emit the original objects. They will be forwarded to the output |
|
1970 | re-emit the original objects. They will be forwarded to the output | |
1971 | layer and will be processed as if the cacher did not exist. |
|
1971 | layer and will be processed as if the cacher did not exist. | |
1972 |
|
1972 | |||
1973 | Implementations could also choose to not emit objects - instead locally |
|
1973 | Implementations could also choose to not emit objects - instead locally | |
1974 | buffering objects or their encoded representation. They could then emit |
|
1974 | buffering objects or their encoded representation. They could then emit | |
1975 | a single "coalesced" object when ``onfinished()`` is called. In |
|
1975 | a single "coalesced" object when ``onfinished()`` is called. In | |
1976 | this way, the implementation would function as a filtering layer of |
|
1976 | this way, the implementation would function as a filtering layer of | |
1977 | sorts. |
|
1977 | sorts. | |
1978 |
|
1978 | |||
1979 | When caching objects, typically the encoded form of the object will |
|
1979 | When caching objects, typically the encoded form of the object will | |
1980 | be stored. Keep in mind that if the original object is forwarded to |
|
1980 | be stored. Keep in mind that if the original object is forwarded to | |
1981 | the output layer, it will need to be encoded there as well. For large |
|
1981 | the output layer, it will need to be encoded there as well. For large | |
1982 | output, this redundant encoding could add overhead. Implementations |
|
1982 | output, this redundant encoding could add overhead. Implementations | |
1983 | could wrap the encoded object data in ``wireprototypes.encodedresponse`` |
|
1983 | could wrap the encoded object data in ``wireprototypes.encodedresponse`` | |
1984 | instances to avoid this overhead. |
|
1984 | instances to avoid this overhead. | |
1985 | """ |
|
1985 | """ | |
1986 |
|
1986 | |||
1987 | def __enter__(): |
|
1987 | def __enter__(): | |
1988 | """Marks the instance as active. |
|
1988 | """Marks the instance as active. | |
1989 |
|
1989 | |||
1990 | Should return self. |
|
1990 | Should return self. | |
1991 | """ |
|
1991 | """ | |
1992 |
|
1992 | |||
1993 | def __exit__(exctype, excvalue, exctb): |
|
1993 | def __exit__(exctype, excvalue, exctb): | |
1994 | """Called when cacher is no longer used. |
|
1994 | """Called when cacher is no longer used. | |
1995 |
|
1995 | |||
1996 | This can be used by implementations to perform cleanup actions (e.g. |
|
1996 | This can be used by implementations to perform cleanup actions (e.g. | |
1997 | disconnecting network sockets, aborting a partially cached response. |
|
1997 | disconnecting network sockets, aborting a partially cached response. | |
1998 | """ |
|
1998 | """ | |
1999 |
|
1999 | |||
2000 | def adjustcachekeystate(state): |
|
2000 | def adjustcachekeystate(state): | |
2001 | """Influences cache key derivation by adjusting state to derive key. |
|
2001 | """Influences cache key derivation by adjusting state to derive key. | |
2002 |
|
2002 | |||
2003 | A dict defining the state used to derive the cache key is passed. |
|
2003 | A dict defining the state used to derive the cache key is passed. | |
2004 |
|
2004 | |||
2005 | Implementations can modify this dict to record additional state that |
|
2005 | Implementations can modify this dict to record additional state that | |
2006 | is wanted to influence key derivation. |
|
2006 | is wanted to influence key derivation. | |
2007 |
|
2007 | |||
2008 | Implementations are *highly* encouraged to not modify or delete |
|
2008 | Implementations are *highly* encouraged to not modify or delete | |
2009 | existing keys. |
|
2009 | existing keys. | |
2010 | """ |
|
2010 | """ | |
2011 |
|
2011 | |||
2012 | def setcachekey(key): |
|
2012 | def setcachekey(key): | |
2013 | """Record the derived cache key for this request. |
|
2013 | """Record the derived cache key for this request. | |
2014 |
|
2014 | |||
2015 | Instances may mutate the key for internal usage, as desired. e.g. |
|
2015 | Instances may mutate the key for internal usage, as desired. e.g. | |
2016 | instances may wish to prepend the repo name, introduce path |
|
2016 | instances may wish to prepend the repo name, introduce path | |
2017 | components for filesystem or URL addressing, etc. Behavior is up to |
|
2017 | components for filesystem or URL addressing, etc. Behavior is up to | |
2018 | the cache. |
|
2018 | the cache. | |
2019 |
|
2019 | |||
2020 | Returns a bool indicating if the request is cacheable by this |
|
2020 | Returns a bool indicating if the request is cacheable by this | |
2021 | instance. |
|
2021 | instance. | |
2022 | """ |
|
2022 | """ | |
2023 |
|
2023 | |||
2024 | def lookup(): |
|
2024 | def lookup(): | |
2025 | """Attempt to resolve an entry in the cache. |
|
2025 | """Attempt to resolve an entry in the cache. | |
2026 |
|
2026 | |||
2027 | The instance is instructed to look for the cache key that it was |
|
2027 | The instance is instructed to look for the cache key that it was | |
2028 | informed about via the call to ``setcachekey()``. |
|
2028 | informed about via the call to ``setcachekey()``. | |
2029 |
|
2029 | |||
2030 | If there's no cache hit or the cacher doesn't wish to use the cached |
|
2030 | If there's no cache hit or the cacher doesn't wish to use the cached | |
2031 | entry, ``None`` should be returned. |
|
2031 | entry, ``None`` should be returned. | |
2032 |
|
2032 | |||
2033 | Else, a dict defining the cached result should be returned. The |
|
2033 | Else, a dict defining the cached result should be returned. The | |
2034 | dict may have the following keys: |
|
2034 | dict may have the following keys: | |
2035 |
|
2035 | |||
2036 | objs |
|
2036 | objs | |
2037 | An iterable of objects that should be sent to the client. That |
|
2037 | An iterable of objects that should be sent to the client. That | |
2038 | iterable of objects is expected to be what the command function |
|
2038 | iterable of objects is expected to be what the command function | |
2039 | would return if invoked or an equivalent representation thereof. |
|
2039 | would return if invoked or an equivalent representation thereof. | |
2040 | """ |
|
2040 | """ | |
2041 |
|
2041 | |||
2042 | def onobject(obj): |
|
2042 | def onobject(obj): | |
2043 | """Called when a new object is emitted from the command function. |
|
2043 | """Called when a new object is emitted from the command function. | |
2044 |
|
2044 | |||
2045 | Receives as its argument the object that was emitted from the |
|
2045 | Receives as its argument the object that was emitted from the | |
2046 | command function. |
|
2046 | command function. | |
2047 |
|
2047 | |||
2048 | This method returns an iterator of objects to forward to the output |
|
2048 | This method returns an iterator of objects to forward to the output | |
2049 | layer. The easiest implementation is a generator that just |
|
2049 | layer. The easiest implementation is a generator that just | |
2050 | ``yield obj``. |
|
2050 | ``yield obj``. | |
2051 | """ |
|
2051 | """ | |
2052 |
|
2052 | |||
2053 | def onfinished(): |
|
2053 | def onfinished(): | |
2054 | """Called after all objects have been emitted from the command function. |
|
2054 | """Called after all objects have been emitted from the command function. | |
2055 |
|
2055 | |||
2056 | Implementations should return an iterator of objects to forward to |
|
2056 | Implementations should return an iterator of objects to forward to | |
2057 | the output layer. |
|
2057 | the output layer. | |
2058 |
|
2058 | |||
2059 | This method can be a generator. |
|
2059 | This method can be a generator. | |
2060 | """ |
|
2060 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now