D3148: repository: define existing interface for file storage

2018-04-06 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG4335a75f0bd0: repository: define existing interface for 
file storage (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3148?vs=7762=7846

REVISION DETAIL
  https://phab.mercurial-scm.org/D3148

AFFECTED FILES
  mercurial/repository.py

CHANGE DETAILS

diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -251,6 +251,334 @@
 class legacypeer(peer):
 """peer but with support for legacy wire protocol commands."""
 
+class ifilerevisionssequence(zi.Interface):
+"""Contains index data for all revisions of a file.
+
+Types implementing this behave like lists of tuples. The index
+in the list corresponds to the revision number. The values contain
+index metadata.
+
+The *null* revision (revision number -1) is always the last item
+in the index.
+"""
+
+def __len__():
+"""The total number of revisions."""
+
+def __getitem__(rev):
+"""Returns the object having a specific revision number.
+
+Returns an 8-tuple with the following fields:
+
+offset+flags
+   Contains the offset and flags for the revision. 64-bit unsigned
+   integer where first 6 bytes are the offset and the next 2 bytes
+   are flags. The offset can be 0 if it is not used by the store.
+compressed size
+Size of the revision data in the store. It can be 0 if it isn't
+needed by the store.
+uncompressed size
+Fulltext size. It can be 0 if it isn't needed by the store.
+base revision
+Revision number of revision the delta for storage is encoded
+against. -1 indicates not encoded against a base revision.
+link revision
+Revision number of changelog revision this entry is related to.
+p1 revision
+Revision number of 1st parent. -1 if no 1st parent.
+p2 revision
+Revision number of 2nd parent. -1 if no 1st parent.
+node
+Binary node value for this revision number.
+
+Negative values should index off the end of the sequence. ``-1``
+should return the null revision. ``-2`` should return the most
+recent revision.
+"""
+
+def __contains__(rev):
+"""Whether a revision number exists."""
+
+def insert(self, i, entry):
+"""Add an item to the index at specific revision."""
+
+class ifileindex(zi.Interface):
+"""Storage interface for index data of a single file.
+
+File storage data is divided into index metadata and data storage.
+This interface defines the index portion of the interface.
+
+The index logically consists of:
+
+* A mapping between revision numbers and nodes.
+* DAG data (storing and querying the relationship between nodes).
+* Metadata to facilitate storage.
+"""
+index = zi.Attribute(
+"""An ``ifilerevisionssequence`` instance.""")
+
+def __len__():
+"""Obtain the number of revisions stored for this file."""
+
+def __iter__():
+"""Iterate over revision numbers for this file."""
+
+def revs(start=0, stop=None):
+"""Iterate over revision numbers for this file, with control."""
+
+def parents(node):
+"""Returns a 2-tuple of parent nodes for a revision.
+
+Values will be ``nullid`` if the parent is empty.
+"""
+
+def parentrevs(rev):
+"""Like parents() but operates on revision numbers."""
+
+def rev(node):
+"""Obtain the revision number given a node.
+
+Raises ``error.LookupError`` if the node is not known.
+"""
+
+def node(rev):
+"""Obtain the node value given a revision number.
+
+Raises ``IndexError`` if the node is not known.
+"""
+
+def lookup(node):
+"""Attempt to resolve a value to a node.
+
+Value can be a binary node, hex node, revision number, or a string
+that can be converted to an integer.
+
+Raises ``error.LookupError`` if a node could not be resolved.
+"""
+
+def linkrev(rev):
+"""Obtain the changeset revision number a revision is linked to."""
+
+def flags(rev):
+"""Obtain flags used to affect storage of a revision."""
+
+def iscensored(rev):
+"""Return whether a revision's content has been censored."""
+
+def commonancestorsheads(node1, node2):
+"""Obtain an iterable of nodes containing heads of common ancestors.
+
+See ``ancestor.commonancestorsheads()``.
+"""
+
+def descendants(revs):
+"""Obtain descendant revision numbers for a set of revision numbers.
+
+If ``nullrev`` is in the set, this is equivalent to ``revs()``.
+"""
+
+def headrevs():
+"""Obtain a list of 

D3148: repository: define existing interface for file storage

2018-04-05 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Now that we have mostly successfully implemented an alternate
  storage backend for files data, let's start to define the
  interface for it!
  
  This commit takes the mostly-working interface as defined by the
  simple store repo and codifies it as the file storage interface.
  
  The interface has been split into its logical components:
  
  - index metadata
  - fulltext data
  - mutation
  - everything else
  
  I don't consider the existing interface to be great. But it will
  help to have it more formally defined so we can start chipping away
  at refactoring it.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3148

AFFECTED FILES
  mercurial/repository.py

CHANGE DETAILS

diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -251,6 +251,334 @@
 class legacypeer(peer):
 """peer but with support for legacy wire protocol commands."""
 
+class ifilerevisionssequence(zi.Interface):
+"""Contains index data for all revisions of a file.
+
+Types implementing this behave like lists of tuples. The index
+in the list corresponds to the revision number. The values contain
+index metadata.
+
+The *null* revision (revision number -1) is always the last item
+in the index.
+"""
+
+def __len__():
+"""The total number of revisions."""
+
+def __getitem__(rev):
+"""Returns the object having a specific revision number.
+
+Returns an 8-tuple with the following fields:
+
+offset+flags
+   Contains the offset and flags for the revision. 64-bit unsigned
+   integer where first 6 bytes are the offset and the next 2 bytes
+   are flags. The offset can be 0 if it is not used by the store.
+compressed size
+Size of the revision data in the store. It can be 0 if it isn't
+needed by the store.
+uncompressed size
+Fulltext size. It can be 0 if it isn't needed by the store.
+base revision
+Revision number of revision the delta for storage is encoded
+against. -1 indicates not encoded against a base revision.
+link revision
+Revision number of changelog revision this entry is related to.
+p1 revision
+Revision number of 1st parent. -1 if no 1st parent.
+p2 revision
+Revision number of 2nd parent. -1 if no 1st parent.
+node
+Binary node value for this revision number.
+
+Negative values should index off the end of the sequence. ``-1``
+should return the null revision. ``-2`` should return the most
+recent revision.
+"""
+
+def __contains__(rev):
+"""Whether a revision number exists."""
+
+def insert(self, i, entry):
+"""Add an item to the index at specific revision."""
+
+class ifileindex(zi.Interface):
+"""Storage interface for index data of a single file.
+
+File storage data is divided into index metadata and data storage.
+This interface defines the index portion of the interface.
+
+The index logically consists of:
+
+* A mapping between revision numbers and nodes.
+* DAG data (storing and querying the relationship between nodes).
+* Metadata to facilitate storage.
+"""
+index = zi.Attribute(
+"""An ``ifilerevisionssequence`` instance.""")
+
+def __len__():
+"""Obtain the number of revisions stored for this file."""
+
+def __iter__():
+"""Iterate over revision numbers for this file."""
+
+def revs(start=0, stop=None):
+"""Iterate over revision numbers for this file, with control."""
+
+def parents(node):
+"""Returns a 2-tuple of parent nodes for a revision.
+
+Values will be ``nullid`` if the parent is empty.
+"""
+
+def parentrevs(rev):
+"""Like parents() but operates on revision numbers."""
+
+def rev(node):
+"""Obtain the revision number given a node.
+
+Raises ``error.LookupError`` if the node is not known.
+"""
+
+def node(rev):
+"""Obtain the node value given a revision number.
+
+Raises ``IndexError`` if the node is not known.
+"""
+
+def lookup(node):
+"""Attempt to resolve a value to a node.
+
+Value can be a binary node, hex node, revision number, or a string
+that can be converted to an integer.
+
+Raises ``error.LookupError`` if a node could not be resolved.
+"""
+
+def linkrev(rev):
+"""Obtain the changeset revision number a revision is linked to."""
+
+def flags(rev):
+"""Obtain flags used to affect storage of a revision."""
+
+def iscensored(rev):
+"""Return whether a revision's content has been censored."""
+
+