module documentation

Repository access.

This module contains the base class for git repositories (BaseRepo) and an implementation which uses a repository on local disk (Repo).

Class BaseRepo Base class for a git repository.
Class MemoryRepo Repo that stores refs, objects, and named files in memory.
Class ParentsProvider Provider for commit parent information.
Class Repo A git repository backed by local disk.
Exception DefaultIdentityNotFound Default identity could not be determined.
Exception InvalidUserIdentity User identity is not of the format 'user <email>'.
Exception UnsupportedExtension Unsupported repository extension.
Exception UnsupportedVersion Unsupported repository version.
Function check_user_identity Verify that a user identity is formatted correctly.
Function get_user_identity Determine the identity to use for new commits.
Function parse_graftpoints Convert a list of graftpoints into a dict.
Function parse_shared_repository Parse core.sharedRepository configuration value.
Function read_gitfile Read a .git file.
Function serialize_graftpoints Convert a dictionary of grafts into string.
Constant BASE_DIRECTORIES Undocumented
Constant COMMONDIR Undocumented
Constant CONTROLDIR Undocumented
Constant DEFAULT_BRANCH Undocumented
Constant DEFAULT_OFS_DELTA Undocumented
Constant GITDIR Undocumented
Constant INDEX_FILENAME Undocumented
Constant OBJECTDIR Undocumented
Constant REFSDIR Undocumented
Constant REFSDIR_HEADS Undocumented
Constant REFSDIR_TAGS Undocumented
Constant WORKTREES Undocumented
Type Variable T Undocumented
Function _enable_relative_worktrees_extension Enable the relativeworktrees extension in repository config.
Function _get_default_identity Undocumented
Function _set_filesystem_hidden Mark path as to be hidden if supported by platform and filesystem.
def check_user_identity(identity: bytes):

Verify that a user identity is formatted correctly.

Parameters
identity:bytesUser identity bytestring
Raises
InvalidUserIdentityRaised when identity is invalid
def get_user_identity(config: StackedConfig, kind: str | None = None) -> bytes:

Determine the identity to use for new commits.

If kind is set, this first checks GIT_${KIND}_NAME and GIT_${KIND}_EMAIL.

If those variables are not set, then it will fall back to reading the user.name and user.email settings from the specified configuration.

If that also fails, then it will fall back to using the current users' identity as obtained from the host system (e.g. the gecos field, $EMAIL, $USER@$(hostname -f).

Parameters
config:StackedConfigConfiguration stack to read from
kind:str | NoneOptional kind to return identity for, usually either "AUTHOR" or "COMMITTER".
Returns
bytesA user identity
def parse_graftpoints(graftpoints: Iterable[bytes]) -> dict[ObjectID, list[ObjectID]]:

Convert a list of graftpoints into a dict.

Each line is formatted as:
<commit sha1> <parent sha1> [<parent sha1>]*
Resulting dictionary is:
<commit sha1>: [<parent sha1>*]

https://git.wiki.kernel.org/index.php/GraftPoint

Parameters
graftpoints:Iterable[bytes]Iterator of graftpoint lines
Returns
dict[ObjectID, list[ObjectID]]Undocumented
def parse_shared_repository(value: str | bytes | bool) -> tuple[int | None, int | None]:

Parse core.sharedRepository configuration value.

The masks are permission bits to apply via chmod.

Parameters
value:str | bytes | boolConfiguration value (string, bytes, or boolean)
Returns
tuple[int | None, int | None]tuple of (file_mask, directory_mask) or (None, None) if not shared
def read_gitfile(f: BinaryIO) -> str:

Read a .git file.

The first line of the file should start with "gitdir: "

Returns: A path

Parameters
f:BinaryIOFile-like object to read from
Returns
strUndocumented
def serialize_graftpoints(graftpoints: Mapping[ObjectID, Sequence[ObjectID]]) -> bytes:

Convert a dictionary of grafts into string.

The graft dictionary is:
<commit sha1>: [<parent sha1>*]
Each line is formatted as:
<commit sha1> <parent sha1> [<parent sha1>]*

https://git.wiki.kernel.org/index.php/GraftPoint

BASE_DIRECTORIES =

Undocumented

Value
[['branches'],
 [REFSDIR],
 [REFSDIR, REFSDIR_TAGS],
 [REFSDIR, REFSDIR_HEADS],
 ['hooks'],
 ['info']]
COMMONDIR: str =

Undocumented

Value
'commondir'
CONTROLDIR: str =

Undocumented

Value
'.git'
DEFAULT_BRANCH: bytes =

Undocumented

Value
b'master'
DEFAULT_OFS_DELTA: bool =

Undocumented

Value
True
GITDIR: str =

Undocumented

Value
'gitdir'
INDEX_FILENAME: str =

Undocumented

Value
'index'
OBJECTDIR: str =

Undocumented

Value
'objects'
REFSDIR: str =

Undocumented

Value
'refs'
REFSDIR_HEADS: str =

Undocumented

Value
'heads'
REFSDIR_TAGS: str =

Undocumented

Value
'tags'
WORKTREES: str =

Undocumented

Value
'worktrees'
T =

Undocumented

Value
TypeVar('T',
        bound='ShaFile')
def _enable_relative_worktrees_extension(repo: Repo):

Enable the relativeworktrees extension in repository config.

This sets core.repositoryformatversion to 1 (if not already) and enables the extensions.relativeworktrees extension.

Parameters
repo:RepoThe repository to configure
def _get_default_identity() -> tuple[str, str]:

Undocumented

def _set_filesystem_hidden(path: str):

Mark path as to be hidden if supported by platform and filesystem.

On win32 uses SetFileAttributesW api: <https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-setfileattributesw>