mercurial/repository.py
changeset 38530 c82ea938efbb
parent 38509 5cfb01d5ff26
child 38555 f2f9bacf0587
equal deleted inserted replaced
38529:1ad873c3e4a4 38530:c82ea938efbb
   640         """Obtain the expected sizes of backing files.
   640         """Obtain the expected sizes of backing files.
   641 
   641 
   642         TODO this is used by verify and it should not be part of the interface.
   642         TODO this is used by verify and it should not be part of the interface.
   643         """
   643         """
   644 
   644 
       
   645 class idirs(interfaceutil.Interface):
       
   646     """Interface representing a collection of directories from paths.
       
   647 
       
   648     This interface is essentially a derived data structure representing
       
   649     directories from a collection of paths.
       
   650     """
       
   651 
       
   652     def addpath(path):
       
   653         """Add a path to the collection.
       
   654 
       
   655         All directories in the path will be added to the collection.
       
   656         """
       
   657 
       
   658     def delpath(path):
       
   659         """Remove a path from the collection.
       
   660 
       
   661         If the removal was the last path in a particular directory, the
       
   662         directory is removed from the collection.
       
   663         """
       
   664 
       
   665     def __iter__():
       
   666         """Iterate over the directories in this collection of paths."""
       
   667 
       
   668     def __contains__(path):
       
   669         """Whether a specific directory is in this collection."""
       
   670 
       
   671 class imanifestdict(interfaceutil.Interface):
       
   672     """Interface representing a manifest data structure.
       
   673 
       
   674     A manifest is effectively a dict mapping paths to entries. Each entry
       
   675     consists of a binary node and extra flags affecting that entry.
       
   676     """
       
   677 
       
   678     def __getitem__(path):
       
   679         """Returns the binary node value for a path in the manifest.
       
   680 
       
   681         Raises ``KeyError`` if the path does not exist in the manifest.
       
   682 
       
   683         Equivalent to ``self.find(path)[0]``.
       
   684         """
       
   685 
       
   686     def find(path):
       
   687         """Returns the entry for a path in the manifest.
       
   688 
       
   689         Returns a 2-tuple of (node, flags).
       
   690 
       
   691         Raises ``KeyError`` if the path does not exist in the manifest.
       
   692         """
       
   693 
       
   694     def __len__():
       
   695         """Return the number of entries in the manifest."""
       
   696 
       
   697     def __nonzero__():
       
   698         """Returns True if the manifest has entries, False otherwise."""
       
   699 
       
   700     __bool__ = __nonzero__
       
   701 
       
   702     def __setitem__(path, node):
       
   703         """Define the node value for a path in the manifest.
       
   704 
       
   705         If the path is already in the manifest, its flags will be copied to
       
   706         the new entry.
       
   707         """
       
   708 
       
   709     def __contains__(path):
       
   710         """Whether a path exists in the manifest."""
       
   711 
       
   712     def __delitem__(path):
       
   713         """Remove a path from the manifest.
       
   714 
       
   715         Raises ``KeyError`` if the path is not in the manifest.
       
   716         """
       
   717 
       
   718     def __iter__():
       
   719         """Iterate over paths in the manifest."""
       
   720 
       
   721     def iterkeys():
       
   722         """Iterate over paths in the manifest."""
       
   723 
       
   724     def keys():
       
   725         """Obtain a list of paths in the manifest."""
       
   726 
       
   727     def filesnotin(other, match=None):
       
   728         """Obtain the set of paths in this manifest but not in another.
       
   729 
       
   730         ``match`` is an optional matcher function to be applied to both
       
   731         manifests.
       
   732 
       
   733         Returns a set of paths.
       
   734         """
       
   735 
       
   736     def dirs():
       
   737         """Returns an object implementing the ``idirs`` interface."""
       
   738 
       
   739     def hasdir(dir):
       
   740         """Returns a bool indicating if a directory is in this manifest."""
       
   741 
       
   742     def matches(match):
       
   743         """Generate a new manifest filtered through a matcher.
       
   744 
       
   745         Returns an object conforming to the ``imanifestdict`` interface.
       
   746         """
       
   747 
       
   748     def walk(match):
       
   749         """Generator of paths in manifest satisfying a matcher.
       
   750 
       
   751         This is equivalent to ``self.matches(match).iterkeys()`` except a new
       
   752         manifest object is not created.
       
   753 
       
   754         If the matcher has explicit files listed and they don't exist in
       
   755         the manifest, ``match.bad()`` is called for each missing file.
       
   756         """
       
   757 
       
   758     def diff(other, match=None, clean=False):
       
   759         """Find differences between this manifest and another.
       
   760 
       
   761         This manifest is compared to ``other``.
       
   762 
       
   763         If ``match`` is provided, the two manifests are filtered against this
       
   764         matcher and only entries satisfying the matcher are compared.
       
   765 
       
   766         If ``clean`` is True, unchanged files are included in the returned
       
   767         object.
       
   768 
       
   769         Returns a dict with paths as keys and values of 2-tuples of 2-tuples of
       
   770         the form ``((node1, flag1), (node2, flag2))`` where ``(node1, flag1)``
       
   771         represents the node and flags for this manifest and ``(node2, flag2)``
       
   772         are the same for the other manifest.
       
   773         """
       
   774 
       
   775     def setflag(path, flag):
       
   776         """Set the flag value for a given path.
       
   777 
       
   778         Raises ``KeyError`` if the path is not already in the manifest.
       
   779         """
       
   780 
       
   781     def get(path, default=None):
       
   782         """Obtain the node value for a path or a default value if missing."""
       
   783 
       
   784     def flags(path, default=''):
       
   785         """Return the flags value for a path or a default value if missing."""
       
   786 
       
   787     def copy():
       
   788         """Return a copy of this manifest."""
       
   789 
       
   790     def items():
       
   791         """Returns an iterable of (path, node) for items in this manifest."""
       
   792 
       
   793     def iteritems():
       
   794         """Identical to items()."""
       
   795 
       
   796     def iterentries():
       
   797         """Returns an iterable of (path, node, flags) for this manifest.
       
   798 
       
   799         Similar to ``iteritems()`` except items are a 3-tuple and include
       
   800         flags.
       
   801         """
       
   802 
       
   803     def text():
       
   804         """Obtain the raw data representation for this manifest.
       
   805 
       
   806         Result is used to create a manifest revision.
       
   807         """
       
   808 
       
   809     def fastdelta(base, changes):
       
   810         """Obtain a delta between this manifest and another given changes.
       
   811 
       
   812         ``base`` in the raw data representation for another manifest.
       
   813 
       
   814         ``changes`` is an iterable of ``(path, to_delete)``.
       
   815 
       
   816         Returns a 2-tuple containing ``bytearray(self.text())`` and the
       
   817         delta between ``base`` and this manifest.
       
   818         """
       
   819 
       
   820 class imanifestrevisionbase(interfaceutil.Interface):
       
   821     """Base interface representing a single revision of a manifest.
       
   822 
       
   823     Should not be used as a primary interface: should always be inherited
       
   824     as part of a larger interface.
       
   825     """
       
   826 
       
   827     def new():
       
   828         """Obtain a new manifest instance.
       
   829 
       
   830         Returns an object conforming to the ``imanifestrevisionwritable``
       
   831         interface. The instance will be associated with the same
       
   832         ``imanifestlog`` collection as this instance.
       
   833         """
       
   834 
       
   835     def copy():
       
   836         """Obtain a copy of this manifest instance.
       
   837 
       
   838         Returns an object conforming to the ``imanifestrevisionwritable``
       
   839         interface. The instance will be associated with the same
       
   840         ``imanifestlog`` collection as this instance.
       
   841         """
       
   842 
       
   843     def read():
       
   844         """Obtain the parsed manifest data structure.
       
   845 
       
   846         The returned object conforms to the ``imanifestdict`` interface.
       
   847         """
       
   848 
       
   849 class imanifestrevisionstored(imanifestrevisionbase):
       
   850     """Interface representing a manifest revision committed to storage."""
       
   851 
       
   852     def node():
       
   853         """The binary node for this manifest."""
       
   854 
       
   855     parents = interfaceutil.Attribute(
       
   856         """List of binary nodes that are parents for this manifest revision."""
       
   857     )
       
   858 
       
   859     def readdelta(shallow=False):
       
   860         """Obtain the manifest data structure representing changes from parent.
       
   861 
       
   862         This manifest is compared to its 1st parent. A new manifest representing
       
   863         those differences is constructed.
       
   864 
       
   865         The returned object conforms to the ``imanifestdict`` interface.
       
   866         """
       
   867 
       
   868     def readfast(shallow=False):
       
   869         """Calls either ``read()`` or ``readdelta()``.
       
   870 
       
   871         The faster of the two options is called.
       
   872         """
       
   873 
       
   874     def find(key):
       
   875         """Calls self.read().find(key)``.
       
   876 
       
   877         Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``.
       
   878         """
       
   879 
       
   880 class imanifestrevisionwritable(imanifestrevisionbase):
       
   881     """Interface representing a manifest revision that can be committed."""
       
   882 
       
   883     def write(transaction, linkrev, p1node, p2node, added, removed):
       
   884         """Add this revision to storage.
       
   885 
       
   886         Takes a transaction object, the changeset revision number it will
       
   887         be associated with, its parent nodes, and lists of added and
       
   888         removed paths.
       
   889 
       
   890         Returns the binary node of the created revision.
       
   891         """
       
   892 
       
   893 class imanifestlog(interfaceutil.Interface):
       
   894     """Interface representing a collection of manifest snapshots."""
       
   895 
       
   896     def __getitem__(node):
       
   897         """Obtain a manifest instance for a given binary node.
       
   898 
       
   899         Equivalent to calling ``self.get('', node)``.
       
   900 
       
   901         The returned object conforms to the ``imanifestrevisionstored``
       
   902         interface.
       
   903         """
       
   904 
       
   905     def get(dir, node, verify=True):
       
   906         """Retrieve the manifest instance for a given directory and binary node.
       
   907 
       
   908         ``node`` always refers to the node of the root manifest (which will be
       
   909         the only manifest if flat manifests are being used).
       
   910 
       
   911         If ``dir`` is the empty string, the root manifest is returned. Otherwise
       
   912         the manifest for the specified directory will be returned (requires
       
   913         tree manifests).
       
   914 
       
   915         If ``verify`` is True, ``LookupError`` is raised if the node is not
       
   916         known.
       
   917 
       
   918         The returned object conforms to the ``imanifestrevisionstored``
       
   919         interface.
       
   920         """
       
   921 
       
   922     def clearcaches():
       
   923         """Clear caches associated with this collection."""
       
   924 
   645 class completelocalrepository(interfaceutil.Interface):
   925 class completelocalrepository(interfaceutil.Interface):
   646     """Monolithic interface for local repositories.
   926     """Monolithic interface for local repositories.
   647 
   927 
   648     This currently captures the reality of things - not how things should be.
   928     This currently captures the reality of things - not how things should be.
   649     """
   929     """
   755 
  1035 
   756     changelog = interfaceutil.Attribute(
  1036     changelog = interfaceutil.Attribute(
   757         """A handle on the changelog revlog.""")
  1037         """A handle on the changelog revlog.""")
   758 
  1038 
   759     manifestlog = interfaceutil.Attribute(
  1039     manifestlog = interfaceutil.Attribute(
   760         """A handle on the root manifest revlog.""")
  1040         """An instance conforming to the ``imanifestlog`` interface.
       
  1041 
       
  1042         Provides access to manifests for the repository.
       
  1043         """)
   761 
  1044 
   762     dirstate = interfaceutil.Attribute(
  1045     dirstate = interfaceutil.Attribute(
   763         """Working directory state.""")
  1046         """Working directory state.""")
   764 
  1047 
   765     narrowpats = interfaceutil.Attribute(
  1048     narrowpats = interfaceutil.Attribute(