Mercurial > public > mercurial-scm > hg
comparison mercurial/interfaces/repository.py @ 52445:26dd402c3497
interfaces: convert the repository zope interfaces to Protocol classes
This is the same transformation as 382d9629cede did for dirstate. The same
caveat applies- the code may not be valid, since the functions are missing the
`self` arg, and the attrs should be plain attrs, not zope `Attribute`. These
classes are pretty intertwined however, so making the same transformation to
everything makes it easier to change and review.
Additionally, there are some classes that subclass multiple protocol classes,
and should themselves subclass `typing.Protocol` to be a protocol class. But
defer that for now for clarity.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 22 Oct 2024 16:04:27 -0400 |
parents | b2821a846470 |
children | c1674551c109 |
comparison
equal
deleted
inserted
replaced
52444:cdb45eb77efb | 52445:26dd402c3497 |
---|---|
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 annotations | 9 from __future__ import annotations |
10 | |
11 from typing import ( | |
12 Protocol, | |
13 ) | |
10 | 14 |
11 from ..i18n import _ | 15 from ..i18n import _ |
12 from .. import error | 16 from .. import error |
13 from . import util as interfaceutil | 17 from . import util as interfaceutil |
14 | 18 |
96 CACHES_POST_CLONE = CACHES_ALL.copy() | 100 CACHES_POST_CLONE = CACHES_ALL.copy() |
97 CACHES_POST_CLONE.discard(CACHE_FILE_NODE_TAGS) | 101 CACHES_POST_CLONE.discard(CACHE_FILE_NODE_TAGS) |
98 CACHES_POST_CLONE.discard(CACHE_REV_BRANCH) | 102 CACHES_POST_CLONE.discard(CACHE_REV_BRANCH) |
99 | 103 |
100 | 104 |
101 class ipeerconnection(interfaceutil.Interface): | 105 class ipeerconnection(Protocol): |
102 """Represents a "connection" to a repository. | 106 """Represents a "connection" to a repository. |
103 | 107 |
104 This is the base interface for representing a connection to a repository. | 108 This is the base interface for representing a connection to a repository. |
105 It holds basic properties and methods applicable to all peer types. | 109 It holds basic properties and methods applicable to all peer types. |
106 | 110 |
139 This is called when the peer will no longer be used. Resources | 143 This is called when the peer will no longer be used. Resources |
140 associated with the peer should be cleaned up. | 144 associated with the peer should be cleaned up. |
141 """ | 145 """ |
142 | 146 |
143 | 147 |
144 class ipeercapabilities(interfaceutil.Interface): | 148 class ipeercapabilities(Protocol): |
145 """Peer sub-interface related to capabilities.""" | 149 """Peer sub-interface related to capabilities.""" |
146 | 150 |
147 def capable(name): | 151 def capable(name): |
148 """Determine support for a named capability. | 152 """Determine support for a named capability. |
149 | 153 |
160 | 164 |
161 Raises a ``CapabilityError`` if the capability isn't present. | 165 Raises a ``CapabilityError`` if the capability isn't present. |
162 """ | 166 """ |
163 | 167 |
164 | 168 |
165 class ipeercommands(interfaceutil.Interface): | 169 class ipeercommands(Protocol): |
166 """Client-side interface for communicating over the wire protocol. | 170 """Client-side interface for communicating over the wire protocol. |
167 | 171 |
168 This interface is used as a gateway to the Mercurial wire protocol. | 172 This interface is used as a gateway to the Mercurial wire protocol. |
169 methods commonly call wire protocol commands of the same name. | 173 methods commonly call wire protocol commands of the same name. |
170 """ | 174 """ |
256 | 260 |
257 Returns the integer number of heads added to the peer. | 261 Returns the integer number of heads added to the peer. |
258 """ | 262 """ |
259 | 263 |
260 | 264 |
261 class ipeerlegacycommands(interfaceutil.Interface): | 265 class ipeerlegacycommands(Protocol): |
262 """Interface for implementing support for legacy wire protocol commands. | 266 """Interface for implementing support for legacy wire protocol commands. |
263 | 267 |
264 Wire protocol commands transition to legacy status when they are no longer | 268 Wire protocol commands transition to legacy status when they are no longer |
265 used by modern clients. To facilitate identifying which commands are | 269 used by modern clients. To facilitate identifying which commands are |
266 legacy, the interfaces are split. | 270 legacy, the interfaces are split. |
289 | 293 |
290 def changegroupsubset(bases, heads, source): | 294 def changegroupsubset(bases, heads, source): |
291 pass | 295 pass |
292 | 296 |
293 | 297 |
294 class ipeercommandexecutor(interfaceutil.Interface): | 298 class ipeercommandexecutor(Protocol): |
295 """Represents a mechanism to execute remote commands. | 299 """Represents a mechanism to execute remote commands. |
296 | 300 |
297 This is the primary interface for requesting that wire protocol commands | 301 This is the primary interface for requesting that wire protocol commands |
298 be executed. Instances of this interface are active in a context manager | 302 be executed. Instances of this interface are active in a context manager |
299 and have a well-defined lifetime. When the context manager exits, all | 303 and have a well-defined lifetime. When the context manager exits, all |
347 | 351 |
348 This method may call ``sendcommands()`` if there are buffered commands. | 352 This method may call ``sendcommands()`` if there are buffered commands. |
349 """ | 353 """ |
350 | 354 |
351 | 355 |
352 class ipeerrequests(interfaceutil.Interface): | 356 class ipeerrequests(Protocol): |
353 """Interface for executing commands on a peer.""" | 357 """Interface for executing commands on a peer.""" |
354 | 358 |
355 limitedarguments = interfaceutil.Attribute( | 359 limitedarguments = interfaceutil.Attribute( |
356 """True if the peer cannot receive large argument value for commands.""" | 360 """True if the peer cannot receive large argument value for commands.""" |
357 ) | 361 ) |
429 ) | 433 ) |
430 % (purpose, name) | 434 % (purpose, name) |
431 ) | 435 ) |
432 | 436 |
433 | 437 |
434 class iverifyproblem(interfaceutil.Interface): | 438 class iverifyproblem(Protocol): |
435 """Represents a problem with the integrity of the repository. | 439 """Represents a problem with the integrity of the repository. |
436 | 440 |
437 Instances of this interface are emitted to describe an integrity issue | 441 Instances of this interface are emitted to describe an integrity issue |
438 with a repository (e.g. corrupt storage, missing data, etc). | 442 with a repository (e.g. corrupt storage, missing data, etc). |
439 | 443 |
452 ``None`` means the problem doesn't apply to a single revision. | 456 ``None`` means the problem doesn't apply to a single revision. |
453 """ | 457 """ |
454 ) | 458 ) |
455 | 459 |
456 | 460 |
457 class irevisiondelta(interfaceutil.Interface): | 461 class irevisiondelta(Protocol): |
458 """Represents a delta between one revision and another. | 462 """Represents a delta between one revision and another. |
459 | 463 |
460 Instances convey enough information to allow a revision to be exchanged | 464 Instances convey enough information to allow a revision to be exchanged |
461 with another repository. | 465 with another repository. |
462 | 466 |
524 This is a bitwise composition of the ``storageutil.CG_FLAG*`` constants. | 528 This is a bitwise composition of the ``storageutil.CG_FLAG*`` constants. |
525 """ | 529 """ |
526 ) | 530 ) |
527 | 531 |
528 | 532 |
529 class ifilerevisionssequence(interfaceutil.Interface): | 533 class ifilerevisionssequence(Protocol): |
530 """Contains index data for all revisions of a file. | 534 """Contains index data for all revisions of a file. |
531 | 535 |
532 Types implementing this behave like lists of tuples. The index | 536 Types implementing this behave like lists of tuples. The index |
533 in the list corresponds to the revision number. The values contain | 537 in the list corresponds to the revision number. The values contain |
534 index metadata. | 538 index metadata. |
576 | 580 |
577 def insert(self, i, entry): | 581 def insert(self, i, entry): |
578 """Add an item to the index at specific revision.""" | 582 """Add an item to the index at specific revision.""" |
579 | 583 |
580 | 584 |
581 class ifileindex(interfaceutil.Interface): | 585 class ifileindex(Protocol): |
582 """Storage interface for index data of a single file. | 586 """Storage interface for index data of a single file. |
583 | 587 |
584 File storage data is divided into index metadata and data storage. | 588 File storage data is divided into index metadata and data storage. |
585 This interface defines the index portion of the interface. | 589 This interface defines the index portion of the interface. |
586 | 590 |
677 | 681 |
678 Returns a list of nodes. | 682 Returns a list of nodes. |
679 """ | 683 """ |
680 | 684 |
681 | 685 |
682 class ifiledata(interfaceutil.Interface): | 686 class ifiledata(Protocol): |
683 """Storage interface for data storage of a specific file. | 687 """Storage interface for data storage of a specific file. |
684 | 688 |
685 This complements ``ifileindex`` and provides an interface for accessing | 689 This complements ``ifileindex`` and provides an interface for accessing |
686 data for a tracked file. | 690 data for a tracked file. |
687 """ | 691 """ |
784 emitted just prior. The initial revision should be a delta against its | 788 emitted just prior. The initial revision should be a delta against its |
785 1st parent. | 789 1st parent. |
786 """ | 790 """ |
787 | 791 |
788 | 792 |
789 class ifilemutation(interfaceutil.Interface): | 793 class ifilemutation(Protocol): |
790 """Storage interface for mutation events of a tracked file.""" | 794 """Storage interface for mutation events of a tracked file.""" |
791 | 795 |
792 def add(filedata, meta, transaction, linkrev, p1, p2): | 796 def add(filedata, meta, transaction, linkrev, p1, p2): |
793 """Add a new revision to the store. | 797 """Add a new revision to the store. |
794 | 798 |
966 The method yields objects conforming to the ``iverifyproblem`` | 970 The method yields objects conforming to the ``iverifyproblem`` |
967 interface. | 971 interface. |
968 """ | 972 """ |
969 | 973 |
970 | 974 |
971 class idirs(interfaceutil.Interface): | 975 class idirs(Protocol): |
972 """Interface representing a collection of directories from paths. | 976 """Interface representing a collection of directories from paths. |
973 | 977 |
974 This interface is essentially a derived data structure representing | 978 This interface is essentially a derived data structure representing |
975 directories from a collection of paths. | 979 directories from a collection of paths. |
976 """ | 980 """ |
993 | 997 |
994 def __contains__(path): | 998 def __contains__(path): |
995 """Whether a specific directory is in this collection.""" | 999 """Whether a specific directory is in this collection.""" |
996 | 1000 |
997 | 1001 |
998 class imanifestdict(interfaceutil.Interface): | 1002 class imanifestdict(Protocol): |
999 """Interface representing a manifest data structure. | 1003 """Interface representing a manifest data structure. |
1000 | 1004 |
1001 A manifest is effectively a dict mapping paths to entries. Each entry | 1005 A manifest is effectively a dict mapping paths to entries. Each entry |
1002 consists of a binary node and extra flags affecting that entry. | 1006 consists of a binary node and extra flags affecting that entry. |
1003 """ | 1007 """ |
1143 If this manifest implementation can't support ``fastdelta()``, | 1147 If this manifest implementation can't support ``fastdelta()``, |
1144 raise ``mercurial.manifest.FastdeltaUnavailable``. | 1148 raise ``mercurial.manifest.FastdeltaUnavailable``. |
1145 """ | 1149 """ |
1146 | 1150 |
1147 | 1151 |
1148 class imanifestrevisionbase(interfaceutil.Interface): | 1152 class imanifestrevisionbase(Protocol): |
1149 """Base interface representing a single revision of a manifest. | 1153 """Base interface representing a single revision of a manifest. |
1150 | 1154 |
1151 Should not be used as a primary interface: should always be inherited | 1155 Should not be used as a primary interface: should always be inherited |
1152 as part of a larger interface. | 1156 as part of a larger interface. |
1153 """ | 1157 """ |
1274 | 1278 |
1275 Returns the binary node of the created revision. | 1279 Returns the binary node of the created revision. |
1276 """ | 1280 """ |
1277 | 1281 |
1278 | 1282 |
1279 class imanifeststorage(interfaceutil.Interface): | 1283 class imanifeststorage(Protocol): |
1280 """Storage interface for manifest data.""" | 1284 """Storage interface for manifest data.""" |
1281 | 1285 |
1282 nodeconstants = interfaceutil.Attribute( | 1286 nodeconstants = interfaceutil.Attribute( |
1283 """nodeconstants used by the current repository.""" | 1287 """nodeconstants used by the current repository.""" |
1284 ) | 1288 ) |
1482 storage is a revlog for optimization, so giving simple way to access | 1486 storage is a revlog for optimization, so giving simple way to access |
1483 the revlog instance helps such code. | 1487 the revlog instance helps such code. |
1484 """ | 1488 """ |
1485 | 1489 |
1486 | 1490 |
1487 class imanifestlog(interfaceutil.Interface): | 1491 class imanifestlog(Protocol): |
1488 """Interface representing a collection of manifest snapshots. | 1492 """Interface representing a collection of manifest snapshots. |
1489 | 1493 |
1490 Represents the root manifest in a repository. | 1494 Represents the root manifest in a repository. |
1491 | 1495 |
1492 Also serves as a means to access nested tree manifests and to cache | 1496 Also serves as a means to access nested tree manifests and to cache |
1547 | 1551 |
1548 def update_caches(transaction): | 1552 def update_caches(transaction): |
1549 """update whatever cache are relevant for the used storage.""" | 1553 """update whatever cache are relevant for the used storage.""" |
1550 | 1554 |
1551 | 1555 |
1552 class ilocalrepositoryfilestorage(interfaceutil.Interface): | 1556 class ilocalrepositoryfilestorage(Protocol): |
1553 """Local repository sub-interface providing access to tracked file storage. | 1557 """Local repository sub-interface providing access to tracked file storage. |
1554 | 1558 |
1555 This interface defines how a repository accesses storage for a single | 1559 This interface defines how a repository accesses storage for a single |
1556 tracked file path. | 1560 tracked file path. |
1557 """ | 1561 """ |
1561 | 1565 |
1562 The returned type conforms to the ``ifilestorage`` interface. | 1566 The returned type conforms to the ``ifilestorage`` interface. |
1563 """ | 1567 """ |
1564 | 1568 |
1565 | 1569 |
1566 class ilocalrepositorymain(interfaceutil.Interface): | 1570 class ilocalrepositorymain(Protocol): |
1567 """Main interface for local repositories. | 1571 """Main interface for local repositories. |
1568 | 1572 |
1569 This currently captures the reality of things - not how things should be. | 1573 This currently captures the reality of things - not how things should be. |
1570 """ | 1574 """ |
1571 | 1575 |
1987 ilocalrepositorymain, ilocalrepositoryfilestorage | 1991 ilocalrepositorymain, ilocalrepositoryfilestorage |
1988 ): | 1992 ): |
1989 """Complete interface for a local repository.""" | 1993 """Complete interface for a local repository.""" |
1990 | 1994 |
1991 | 1995 |
1992 class iwireprotocolcommandcacher(interfaceutil.Interface): | 1996 class iwireprotocolcommandcacher(Protocol): |
1993 """Represents a caching backend for wire protocol commands. | 1997 """Represents a caching backend for wire protocol commands. |
1994 | 1998 |
1995 Wire protocol version 2 supports transparent caching of many commands. | 1999 Wire protocol version 2 supports transparent caching of many commands. |
1996 To leverage this caching, servers can activate objects that cache | 2000 To leverage this caching, servers can activate objects that cache |
1997 command responses. Objects handle both cache writing and reading. | 2001 command responses. Objects handle both cache writing and reading. |