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