class documentation

Base class for a git repository.

This base class is meant to be used for Repository implementations that e.g. work on top of a different transport than a standard filesystem path.

Method __contains__ Check if a specific Git object or ref is present.
Method __delitem__ Remove a ref.
Method __getitem__ Retrieve a Git object by SHA1 or ref.
Method __init__ Open a repository.
Method __setitem__ Set a ref.
Method fetch Fetch objects into another repository.
Method fetch_pack_data Fetch the pack data required for a set of revisions.
Method find_missing_objects Fetch 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_blob_normalizer Return a BlobNormalizer object for checkin/checkout operations.
Method get_config Retrieve the config object.
Method get_config_stack Return a config stack for this repository.
Method get_description Retrieve the description for this repository.
Method get_gitattributes Read gitattributes for the repository.
Method get_graph_walker Retrieve a graph walker.
Method get_named_file Get a file from the control dir with a specific name.
Method get_object Retrieve the object with the specified SHA.
Method get_parents Retrieve the parents of a specific commit.
Method get_peeled Get the peeled value of a ref.
Method get_rebase_state_manager Get the appropriate rebase state manager for this repository.
Method get_refs Get dictionary with all refs.
Method get_shallow Get the set of shallow commits.
Method get_walker Obtain a walker for this repository.
Method get_worktree Get the working tree for this repository.
Method get_worktree_config Retrieve the worktree config object.
Method head Return the SHA1 pointed at by HEAD.
Method open_index Open the index for this repository.
Method parents_provider Get a parents provider for this repository.
Method set_description Set the description for this repository.
Method update_shallow Update the list of shallow objects.
Instance Variable hooks Undocumented
Instance Variable object_format Undocumented
Instance Variable object_store Dictionary-like object for accessing the objects
Instance Variable refs Dictionary-like object with the refs in this repository
Property notes Access notes functionality for this repository.
Method _add_graftpoints Add or modify graftpoints.
Method _change_object_format Change the object format of this repository.
Method _del_named_file Delete a file in the control directory with the given name.
Method _determine_file_mode Probe the file-system to determine whether permissions can be trusted.
Method _determine_symlinks Probe the filesystem to determine whether symlinks can be created.
Method _get_object Undocumented
Method _get_user_identity Determine the identity to use for new commits.
Method _init_config Initialize repository configuration.
Method _init_files Initialize a default set of named files.
Method _put_named_file Write a file to the control dir with the given name and contents.
Method _read_heads Undocumented
Method _remove_graftpoints Remove graftpoints.
Instance Variable _graftpoints Undocumented
def __contains__(self, name: bytes) -> bool:

Check if a specific Git object or ref is present.

Parameters
name:bytesGit object SHA1/SHA256 or ref name
Returns
boolUndocumented
def __delitem__(self, name: bytes):

Remove a ref.

Parameters
name:bytesName of the ref to remove
def __getitem__(self, name: ObjectID | Ref | bytes) -> ShaFile:

Retrieve a Git object by SHA1 or ref.

Returns: A ShaFile object, such as a Commit or Blob

Parameters
name:ObjectID | Ref | bytesA Git object SHA1 or a ref name
Returns
ShaFileUndocumented
Raises
KeyErrorwhen the specified ref or object does not exist
def __init__(self, object_store: PackCapableObjectStore, refs: RefsContainer, object_format: ObjectFormat | None = None):

Open a repository.

This shouldn't be called directly, but rather through one of the base classes, such as MemoryRepo or Repo.

Parameters
object_store:PackCapableObjectStoreObject store to use
refs:RefsContainerRefs container to use
object_format:ObjectFormat | NoneHash algorithm to use (if None, will use object_store's format)
def __setitem__(self, name: bytes, value: ShaFile | bytes):

Set a ref.

Parameters
name:bytesref name
value:ShaFile | bytesRef value - either a ShaFile object, or a hex sha
def fetch(self, target: BaseRepo, determine_wants: Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]] | None = None, progress: Callable[..., None] | None = None, depth: int | None = None) -> dict[Ref, ObjectID]:

Fetch objects into another repository.

Returns: The local refs

Parameters
target:BaseRepoThe target repository
determine_wants:Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]] | NoneOptional function to determine what refs to fetch.
progress:Callable[..., None] | NoneOptional progress function
depth:int | NoneOptional shallow fetch depth
Returns
dict[Ref, ObjectID]Undocumented
def fetch_pack_data(self, determine_wants: Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]], graph_walker: GraphWalker, progress: Callable[[bytes], None] | None, *, get_tagged: Callable[[], dict[ObjectID, ObjectID]] | None = None, depth: int | None = None) -> tuple[int, Iterator[UnpackedObject]]:

Fetch the pack data required for a set of revisions.

Returns: count and iterator over pack data

Parameters
determine_wants:Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]]Function that takes a dictionary with heads and returns the list of heads to fetch.
graph_walker:GraphWalkerObject that can iterate over the list of revisions to fetch and has an "ack" method that will be called to acknowledge that a revision is present.
progress:Callable[[bytes], 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.
depth:int | NoneShallow fetch depth
Returns
tuple[int, Iterator[UnpackedObject]]Undocumented
def find_missing_objects(self, determine_wants: Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]], graph_walker: GraphWalker, progress: Callable[[bytes], None] | None, *, get_tagged: Callable[[], dict[ObjectID, ObjectID]] | None = None, depth: int | None = None) -> MissingObjectFinder | None:

Fetch the missing objects required for a set of revisions.

Returns: iterator over objects, with __len__ implemented

Parameters
determine_wants:Callable[[Mapping[Ref, ObjectID], (int | None)], list[ObjectID]]Function that takes a dictionary with heads and returns the list of heads to fetch.
graph_walker:GraphWalkerObject that can iterate over the list of revisions to fetch and has an "ack" method that will be called to acknowledge that a revision is present.
progress:Callable[[bytes], 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.
depth:int | NoneShallow fetch depth
Returns
MissingObjectFinder | NoneUndocumented
def generate_pack_data(self, have: set[ObjectID], want: set[ObjectID], *, shallow: set[ObjectID] | None = None, progress: Callable[[str], None] | None = None, ofs_delta: bool | None = None) -> tuple[int, Iterator[UnpackedObject]]:

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

Parameters
have:set[ObjectID]List of SHA1s of objects that should not be sent
want:set[ObjectID]List of SHA1s of objects that should be sent
shallow:set[ObjectID] | NoneSet of shallow commit SHA1s to skip (defaults to repo's shallow commits)
progress:Callable[[str], None] | NoneOptional progress reporting method
ofs_delta:bool | NoneWhether OFS deltas can be included
Returns
tuple[int, Iterator[UnpackedObject]]Undocumented
def get_blob_normalizer(self) -> FilterBlobNormalizer:

Return a BlobNormalizer object for checkin/checkout operations.

Returns: BlobNormalizer instance

def get_config(self) -> ConfigFile:

Retrieve the config object.

Returns: ConfigFile object for the .git/config file.

def get_config_stack(self) -> StackedConfig:

Return a config stack for this repository.

This stack accesses the configuration for both this repository itself (.git/config) and the global configuration, which usually lives in ~/.gitconfig.

Returns: Config instance for this repository

def get_description(self) -> bytes | None:

Retrieve the description for this repository.

Returns: Bytes with the description of the repository
as set by the user.
def get_gitattributes(self, tree: bytes | None = None) -> GitAttributes:

Read gitattributes for the repository.

Parameters
tree:bytes | NoneTree SHA to read .gitattributes from (defaults to HEAD)
Returns
GitAttributesGitAttributes object that can be used to match paths
def get_graph_walker(self, heads: list[ObjectID] | None = None) -> ObjectStoreGraphWalker:

Retrieve a graph walker.

A graph walker is used by a remote repository (or proxy) to find out which objects are present in this repository.

Returns: A graph walker object

Parameters
heads:list[ObjectID] | NoneRepository heads to use (optional)
Returns
ObjectStoreGraphWalkerUndocumented
def get_named_file(self, path: str) -> BinaryIO | None:

Get a file from the control dir with a specific name.

Although the filename should be interpreted as a filename relative to the control dir in a disk-based Repo, the object returned need not be pointing to a file in that location.

Returns: An open file object, or None if the file does not exist.

Parameters
path:strThe path to the file, relative to the control dir.
Returns
BinaryIO | NoneUndocumented
def get_object(self, sha: ObjectID | RawObjectID) -> ShaFile:

Retrieve the object with the specified SHA.

Returns: A ShaFile object

Parameters
sha:ObjectID | RawObjectIDSHA to retrieve
Returns
ShaFileUndocumented
Raises
KeyErrorwhen the object can not be found
def get_parents(self, sha: ObjectID, commit: Commit | None = None) -> list[ObjectID]:

Retrieve the parents of a specific commit.

If the specific commit is a graftpoint, the graft parents will be returned instead.

Returns: List of parents

Parameters
sha:ObjectIDSHA of the commit for which to retrieve the parents
commit:Commit | NoneOptional commit matching the sha
Returns
list[ObjectID]Undocumented
def get_peeled(self, ref: Ref) -> ObjectID:

Get the peeled value of a ref.

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
ref:RefThe refname to peel.
Returns
ObjectIDUndocumented
def get_rebase_state_manager(self) -> RebaseStateManager:

Get the appropriate rebase state manager for this repository.

Returns: RebaseStateManager instance

def get_refs(self) -> dict[Ref, ObjectID]:

Get dictionary with all refs.

Returns: A dict mapping ref names to SHA1s

def get_shallow(self) -> set[ObjectID]:

Get the set of shallow commits.

Returns: Set of shallow commits.

def get_walker(self, include: Sequence[ObjectID] | None = None, exclude: Sequence[ObjectID] | None = None, order: str = 'date', reverse: bool = False, max_entries: int | None = None, paths: Sequence[bytes] | None = None, rename_detector: RenameDetector | None = None, follow: bool = False, since: int | None = None, until: int | None = None, queue_cls: type | None = None) -> Walker:

Obtain a walker for this repository.

Returns: A Walker object

Parameters
include:Sequence[ObjectID] | NoneIterable of SHAs of commits to include along with their ancestors. Defaults to [HEAD]
exclude:Sequence[ObjectID] | NoneIterable of SHAs of commits to exclude along with their ancestors, overriding includes.
order:strORDER_* constant specifying the order of results. Anything other than ORDER_DATE may result in O(n) memory usage.
reverse:boolIf True, reverse the order of output, requiring O(n) memory.
max_entries:int | NoneThe maximum number of entries to yield, or None for no limit.
paths:Sequence[bytes] | NoneIterable of file or subtree paths to show entries for.
rename_detector:RenameDetector | Nonediff.RenameDetector object for detecting renames.
follow:boolIf True, follow path across renames/copies. Forces a default rename_detector.
since:int | NoneTimestamp to list commits after.
until:int | NoneTimestamp to list commits before.
queue_cls:type | NoneA class to use for a queue of commits, supporting the iterator protocol. The constructor takes a single argument, the Walker.
Returns
WalkerUndocumented
def get_worktree(self) -> WorkTree:
overridden in dulwich.repo.Repo

Get the working tree for this repository.

Returns
WorkTreeWorkTree instance for performing working tree operations
Raises
NotImplementedErrorIf the repository doesn't support working trees
def get_worktree_config(self) -> ConfigFile:
overridden in dulwich.repo.Repo

Retrieve the worktree config object.

def head(self) -> ObjectID:

Return the SHA1 pointed at by HEAD.

def open_index(self) -> Index:

Open the index for this repository.

Returns: The matching Index

Raises
NoIndexPresentIf no index is present
def parents_provider(self) -> ParentsProvider:

Get a parents provider for this repository.

Returns
ParentsProviderParentsProvider instance configured with grafts and shallows
def set_description(self, description: bytes):

Set the description for this repository.

Parameters
description:bytesText to set as description for this repository.
def update_shallow(self, new_shallow: set[ObjectID] | None, new_unshallow: set[ObjectID] | None):

Update the list of shallow objects.

Parameters
new_shallow:set[ObjectID] | NoneNewly shallow objects
new_unshallow:set[ObjectID] | NoneNewly no longer shallow objects
hooks: dict[str, Hook] =

Undocumented

object_format: ObjectFormat =

Undocumented

object_store =
overridden in dulwich.repo.Repo

Dictionary-like object for accessing the objects

refs =
overridden in dulwich.repo.Repo

Dictionary-like object with the refs in this repository

notes: Notes =

Access notes functionality for this repository.

Returns
Notes object for accessing notes
def _add_graftpoints(self, updated_graftpoints: dict[ObjectID, list[ObjectID]]):

Add or modify graftpoints.

Parameters
updated_graftpoints:dict[ObjectID, list[ObjectID]]Dict of commit shas to list of parent shas
def _change_object_format(self, object_format_name: str):

Change the object format of this repository.

This can only be done if the object store is empty (no objects written yet).

Parameters
object_format_name:strName of the new object format (e.g., "sha1", "sha256")
Raises
AssertionErrorIf the object store is not empty
def _del_named_file(self, path: str):

Delete a file in the control directory with the given name.

def _determine_file_mode(self) -> bool:

Probe the file-system to determine whether permissions can be trusted.

Returns: True if permissions can be trusted, False otherwise.

def _determine_symlinks(self) -> bool:

Probe the filesystem to determine whether symlinks can be created.

Returns: True if symlinks can be created, False otherwise.

def _get_object(self, sha: ObjectID | RawObjectID, cls: type[T]) -> T:

Undocumented

def _get_user_identity(self, config: StackedConfig, kind: str | None = None) -> bytes:

Determine the identity to use for new commits.

def _init_config(self, config: ConfigFile):

Initialize repository configuration.

This method can be overridden by subclasses to handle config initialization.

Parameters
config:ConfigFileThe ConfigFile object that was just created
def _init_files(self, bare: bool, symlinks: bool | None = None, format: int | None = None, shared_repository: str | bool | None = None, object_format: str | None = None):

Initialize a default set of named files.

def _put_named_file(self, path: str, contents: bytes):

Write a file to the control dir with the given name and contents.

Parameters
path:strThe path to the file, relative to the control dir.
contents:bytesA string to write to the file.
def _read_heads(self, name: str) -> list[ObjectID]:

Undocumented

def _remove_graftpoints(self, to_remove: Sequence[ObjectID] = ()):

Remove graftpoints.

Parameters
to_remove:Sequence[ObjectID]List of commit shas
_graftpoints: dict[ObjectID, list[ObjectID]] =
overridden in dulwich.repo.Repo

Undocumented