class documentation

Object store interface.

Method __contains__ Check if a particular object is present by SHA1.
Method __getitem__ Obtain an object by SHA1.
Method __init__ Initialize object store.
Method __iter__ Iterate over the SHAs that are present in this store.
Method add_object Add a single object to this object store.
Method add_objects Add a set of objects to this object store.
Method close Close any files opened by this object store.
Method contains_loose Check if a particular object is present by SHA1 and is loose.
Method contains_packed Check if a particular object is present by SHA1 and is packed.
Method determine_wants_all Determine which objects are wanted based on refs.
Method find_common_revisions Find which revisions this store has in common using graphwalker.
Method find_missing_objects Find the missing objects required for a set of revisions.
Method generate_pack_data Generate pack data objects for a set of wants/haves.
Method get_commit_graph Get the commit graph for this object store.
Method get_object_mtime Get the modification time of an object.
Method get_raw Obtain the raw text for an object.
Method get_reachability_provider Get a reachability provider for this object store.
Method iter_prefix Iterate over all SHA1s that start with a given prefix.
Method iter_tree_contents Iterate the contents of a tree and all subtrees.
Method iter_unpacked_subset Iterate over unpacked objects for a subset of SHAs.
Method iterobjects_subset Iterate over a subset of objects in the store.
Method peel_sha Peel all tags from a SHA.
Method prune Prune/clean up this object store.
Method tree_changes Find the differences between the contents of two trees.
Method write_commit_graph Write a commit graph file for this object store.
Instance Variable object_format Undocumented
Property packs Iterable of pack objects.
Method _get_depth Return the current available depth for the given head.
def __contains__(self, sha1: ObjectID | RawObjectID) -> bool:

Check if a particular object is present by SHA1.

This method makes no distinction between loose and packed objects.

def __getitem__(self, sha1: ObjectID | RawObjectID) -> ShaFile:

Obtain an object by SHA1.

def __init__(self, *, object_format: ObjectFormat | None = None):

Initialize object store.

Parameters
object_format:ObjectFormat | NoneObject format to use (defaults to DEFAULT_OBJECT_FORMAT)
def add_objects(self, objects: Sequence[tuple[ShaFile, str | None]], progress: Callable[..., None] | None = None) -> Pack | None:

Add a set of objects to this object store.

Parameters
objects:Sequence[tuple[ShaFile, str | None]]Iterable over a list of (object, path) tuples
progress:Callable[..., None] | NoneOptional progress callback
Returns
Pack | NoneUndocumented
def close(self):

Close any files opened by this object store.

def contains_loose(self, sha: ObjectID | RawObjectID) -> bool:
def contains_packed(self, sha: ObjectID | RawObjectID) -> bool:

Check if a particular object is present by SHA1 and is packed.

def determine_wants_all(self, refs: Mapping[Ref, ObjectID], depth: int | None = None) -> list[ObjectID]:

Determine which objects are wanted based on refs.

def find_common_revisions(self, graphwalker: GraphWalker) -> list[ObjectID]:

Find which revisions this store has in common using graphwalker.

Returns: List of SHAs that are in common

Parameters
graphwalker:GraphWalkerA graphwalker object.
Returns
list[ObjectID]Undocumented
def find_missing_objects(self, haves: Iterable[ObjectID], wants: Iterable[ObjectID], shallow: Set[ObjectID] | None = None, progress: Callable[..., None] | None = None, get_tagged: Callable[[], dict[ObjectID, ObjectID]] | None = None, get_parents: Callable[..., list[ObjectID]] = lambda commit: commit.parents) -> Iterator[tuple[ObjectID, PackHint | None]]:

Find the missing objects required for a set of revisions.

Returns: Iterator over (sha, path) pairs.

Parameters
haves:Iterable[ObjectID]Iterable over SHAs already in common.
wants:Iterable[ObjectID]Iterable over SHAs of objects to fetch.
shallow:Set[ObjectID] | NoneSet of shallow commit SHA1s to skip
progress:Callable[..., None] | NoneSimple progress function that will be called with updated progress strings.
get_tagged:Callable[[], dict[ObjectID, ObjectID]] | NoneFunction that returns a dict of pointed-to sha -> tag sha for including tags.
get_parents:Callable[..., list[ObjectID]]Optional function for getting the parents of a commit.
Returns
Iterator[tuple[ObjectID, PackHint | None]]Undocumented
def generate_pack_data(self, have: Iterable[ObjectID], want: Iterable[ObjectID], *, shallow: Set[ObjectID] | None = None, progress: Callable[..., None] | None = None, ofs_delta: bool = True) -> tuple[int, Iterator[UnpackedObject]]:

Generate pack data objects for a set of wants/haves.

Parameters
have:Iterable[ObjectID]List of SHA1s of objects that should not be sent
want:Iterable[ObjectID]List of SHA1s of objects that should be sent
shallow:Set[ObjectID] | NoneSet of shallow commit SHA1s to skip
progress:Callable[..., None] | NoneOptional progress reporting method
ofs_delta:boolWhether OFS deltas can be included
Returns
tuple[int, Iterator[UnpackedObject]]Undocumented
def get_commit_graph(self) -> CommitGraph | None:

Get the commit graph for this object store.

Returns
CommitGraph | NoneCommitGraph object if available, None otherwise
def get_object_mtime(self, sha: ObjectID) -> float:

Get the modification time of an object.

Parameters
sha:ObjectIDSHA1 of the object
Returns
floatModification time as seconds since epoch
Raises
KeyErrorif the object is not found
def get_raw(self, name: RawObjectID | ObjectID) -> tuple[int, bytes]:

Obtain the raw text for an object.

Returns: tuple with numeric type and object contents.

Parameters
name:RawObjectID | ObjectIDsha for the object.
Returns
tuple[int, bytes]Undocumented
def get_reachability_provider(self, prefer_bitmap: bool = True) -> ObjectReachabilityProvider:

Get a reachability provider for this object store.

Returns an ObjectReachabilityProvider that can efficiently compute object reachability queries. Subclasses can override this to provide optimized implementations (e.g., using bitmap indexes).

Parameters
prefer_bitmap:boolWhether to prefer bitmap-based reachability if available.
Returns
ObjectReachabilityProviderObjectReachabilityProvider instance
def iter_prefix(self, prefix: bytes) -> Iterator[ObjectID]:

Iterate over all SHA1s that start with a given prefix.

The default implementation is a naive iteration over all objects. However, subclasses may override this method with more efficient implementations.

def iter_tree_contents(self, tree_id: ObjectID, include_trees: bool = False) -> Iterator[TreeEntry]:

Iterate the contents of a tree and all subtrees.

Iteration is depth-first pre-order, as in e.g. os.walk.

Returns: Iterator over TreeEntry namedtuples for all the objects in a
tree.
Parameters
tree_id:ObjectIDSHA1 of the tree.
include_trees:boolIf True, include tree objects in the iteration.
Returns
Iterator[TreeEntry]Undocumented
def iter_unpacked_subset(self, shas: Iterable[ObjectID | RawObjectID], include_comp: bool = False, allow_missing: bool = False, convert_ofs_delta: bool = True) -> Iterator[UnpackedObject]:

Iterate over unpacked objects for a subset of SHAs.

Default implementation that converts ShaFile objects to UnpackedObject. Subclasses may override for more efficient unpacked access.

Parameters
shas:Iterable[ObjectID | RawObjectID]Iterable of object SHAs to retrieve
include_comp:boolWhether to include compressed data (ignored in base implementation)
allow_missing:boolIf True, skip missing objects; if False, raise KeyError
convert_ofs_delta:boolWhether to convert OFS_DELTA objects (ignored in base implementation)
Returns
Iterator[UnpackedObject]Iterator of UnpackedObject instances
Raises
KeyErrorIf an object is missing and allow_missing is False
def iterobjects_subset(self, shas: Iterable[ObjectID], *, allow_missing: bool = False) -> Iterator[ShaFile]:

Iterate over a subset of objects in the store.

Parameters
shas:Iterable[ObjectID]Iterable of object SHAs to retrieve
allow_missing:boolIf True, skip missing objects; if False, raise KeyError
Returns
Iterator[ShaFile]Iterator of ShaFile objects
Raises
KeyErrorIf an object is missing and allow_missing is False
def peel_sha(self, sha: ObjectID | RawObjectID) -> ObjectID:

Peel all tags from a SHA.

Returns: The fully-peeled SHA1 of a tag object, after peeling all
intermediate tags; if the original ref does not point to a tag, this will equal the original SHA1.
Parameters
sha:ObjectID | RawObjectIDThe object SHA to peel.
Returns
ObjectIDUndocumented
def prune(self, grace_period: int | None = None):

Prune/clean up this object store.

This includes removing orphaned temporary files and other housekeeping tasks. Default implementation is a NO-OP.

Parameters
grace_period:int | NoneGrace period in seconds for removing temporary files. If None, uses the default grace period.
def tree_changes(self, source: ObjectID | None, target: ObjectID | None, want_unchanged: bool = False, include_trees: bool = False, change_type_same: bool = False, rename_detector: RenameDetector | None = None, paths: Sequence[bytes] | None = None) -> Iterator[tuple[tuple[bytes | None, bytes | None], tuple[int | None, int | None], tuple[ObjectID | None, ObjectID | None]]]:

Find the differences between the contents of two trees.

Returns: Iterator over tuples with
(oldpath, newpath), (oldmode, newmode), (oldsha, newsha)
Parameters
source:ObjectID | NoneSHA1 of the source tree
target:ObjectID | NoneSHA1 of the target tree
want_unchanged:boolWhether unchanged files should be reported
include_trees:boolWhether to include trees
change_type_same:boolWhether to report files changing type in the same entry.
rename_detector:RenameDetector | NoneRenameDetector object for detecting renames.
paths:Sequence[bytes] | NoneOptional list of paths to filter to (as bytes).
Returns
Iterator[tuple[tuple[bytes | None, bytes | None], tuple[int | None, int | None], tuple[ObjectID | None, ObjectID | None]]]Undocumented
def write_commit_graph(self, refs: Iterable[ObjectID] | None = None, reachable: bool = True):

Write a commit graph file for this object store.

Note

Default implementation does nothing. Subclasses should override this method to provide commit graph writing functionality.

Parameters
refs:Iterable[ObjectID] | NoneList of refs to include. If None, includes all refs from object store.
reachable:boolIf True, includes all commits reachable from refs. If False, only includes the direct ref targets.
object_format =

Undocumented

def _get_depth(self, head: ObjectID, get_parents: Callable[..., list[ObjectID]] = lambda commit: commit.parents, max_depth: int | None = None) -> int:

Return the current available depth for the given head.

For commits with multiple parents, the largest possible depth will be returned.

Parameters
head:ObjectIDcommit to start from
get_parents:Callable[..., list[ObjectID]]optional function for getting the parents of a commit
max_depth:int | Nonemaximum depth to search
Returns
intUndocumented