class documentation

A container for refs.

Method __contains__ Check if a reference exists.
Method __delitem__ Remove a refname.
Method __getitem__ Get the SHA1 for a reference name.
Method __init__ Initialize RefsContainer with optional logger function.
Method __iter__ Iterate over all reference keys.
Method __setitem__ Set a reference name to point to the given SHA1.
Method add_if_new Add a new reference only if it does not already exist.
Method add_packed_refs Add the given refs as packed refs.
Method allkeys All refs present in this container.
Method as_dict Return the contents of this container as a dictionary.
Method follow Follow a reference name.
Method get_packed_refs Get contents of the packed-refs file.
Method get_peeled Return the cached peeled value of a ref, if available.
Method get_symrefs Get a dict with all symrefs in this container.
Method import_refs Import refs from another repository.
Method keys Refs present in this container.
Method pack_refs Pack loose refs into packed-refs file.
Method read_loose_ref Read a loose reference and return its contents.
Method read_ref Read a reference without following any references.
Method remove_if_equals Remove a refname only if it currently equals old_ref.
Method set_if_equals Set a refname to new_ref only if it currently equals old_ref.
Method set_symbolic_ref Make a ref point at another ref.
Method subkeys Refs present in this container under a base.
Method _check_refname Ensure a refname is valid and lives in refs or is HEAD.
Method _log Undocumented
Instance Variable _logger Undocumented
def __contains__(self, refname: Ref) -> bool:

Check if a reference exists.

def __delitem__(self, name: Ref):

Remove a refname.

This method does not follow symbolic references, even if applicable for the subclass.

Note: This method unconditionally deletes the contents of a reference.
To delete atomically only if the reference has not changed, use remove_if_equals().
Parameters
name:RefThe refname to delete.
def __getitem__(self, name: Ref) -> ObjectID:

Get the SHA1 for a reference name.

This method follows all symbolic references.

def __init__(self, logger: Callable[[bytes, bytes, bytes, (bytes | None), (int | None), (int | None), bytes], None] | None = None):
def __iter__(self) -> Iterator[Ref]:

Iterate over all reference keys.

def __setitem__(self, name: Ref, ref: ObjectID):

Set a reference name to point to the given SHA1.

This method follows all symbolic references if applicable for the subclass.

Note: This method unconditionally overwrites the contents of a
reference. To update atomically only if the reference has not changed, use set_if_equals().
Parameters
name:RefThe refname to set.
ref:ObjectIDThe new sha the refname will refer to.
def add_if_new(self, name: Ref, ref: ObjectID, committer: bytes | None = None, timestamp: int | None = None, timezone: int | None = None, message: bytes | None = None) -> bool:

Add a new reference only if it does not already exist.

Parameters
name:RefRef name
ref:ObjectIDRef value
committer:bytes | NoneOptional committer name/email
timestamp:int | NoneOptional timestamp
timezone:int | NoneOptional timezone
message:bytes | NoneOptional message for reflog
Returns
boolUndocumented
def add_packed_refs(self, new_refs: Mapping[Ref, ObjectID | None]):

Add the given refs as packed refs.

Parameters
new_refs:Mapping[Ref, ObjectID | None]A mapping of ref names to targets; if a target is None that means remove the ref
def as_dict(self, base: Ref | None = None) -> dict[Ref, ObjectID]:

Return the contents of this container as a dictionary.

def follow(self, name: Ref) -> tuple[list[Ref], ObjectID | None]:

Follow a reference name.

Returns: a tuple of (refnames, sha), wheres refnames are the names of
references in the chain
def get_packed_refs(self) -> dict[Ref, ObjectID]:

Get contents of the packed-refs file.

Returns: Dictionary mapping ref names to SHA1s

Note: Will return an empty dictionary when no packed-refs file is
present.
def get_peeled(self, name: Ref) -> ObjectID | None:

Return the cached peeled value of a ref, if available.

Returns: The peeled value of the ref. If the ref is known not point to
a tag, this will be the SHA the ref refers to. If the ref may point to a tag, but no cached information is available, None is returned.
Parameters
name:RefName of the ref to peel
Returns
ObjectID | NoneUndocumented
def get_symrefs(self) -> dict[Ref, Ref]:

Get a dict with all symrefs in this container.

Returns: Dictionary mapping source ref to target ref

def import_refs(self, base: Ref, other: Mapping[Ref, ObjectID | None], committer: bytes | None = None, timestamp: bytes | None = None, timezone: bytes | None = None, message: bytes | None = None, prune: bool = False):

Import refs from another repository.

Parameters
base:RefBase ref to import into (e.g., b'refs/remotes/origin')
other:Mapping[Ref, ObjectID | None]Dictionary of refs to import
committer:bytes | NoneOptional committer for reflog
timestamp:bytes | NoneOptional timestamp for reflog
timezone:bytes | NoneOptional timezone for reflog
message:bytes | NoneOptional message for reflog
prune:boolIf True, remove refs not in other
def keys(self, base: Ref | None = None) -> set[Ref]:

Refs present in this container.

Returns: An unsorted set of valid refs in this container, including
packed refs.
Parameters
base:Ref | NoneAn optional base to return refs under.
Returns
set[Ref]Undocumented
def pack_refs(self, all: bool = False):

Pack loose refs into packed-refs file.

Parameters
all:boolIf True, pack all refs. If False, only pack tags.
def read_loose_ref(self, name: Ref) -> bytes | None:

Read a loose reference and return its contents.

Returns: The contents of the ref file, or None if it does
not exist.
Parameters
name:Refthe refname to read
Returns
bytes | NoneUndocumented
def read_ref(self, refname: Ref) -> bytes | None:

Read a reference without following any references.

Returns: The contents of the ref file, or None if it does
not exist.
Parameters
refname:RefThe name of the reference
Returns
bytes | NoneUndocumented
def remove_if_equals(self, name: Ref, old_ref: ObjectID | None, committer: bytes | None = None, timestamp: int | None = None, timezone: int | None = None, message: bytes | None = None) -> bool:

Remove a refname only if it currently equals old_ref.

This method does not follow symbolic references, even if applicable for the subclass. It can be used to perform an atomic compare-and-delete operation.

Returns: True if the delete was successful, False otherwise.

Parameters
name:RefThe refname to delete.
old_ref:ObjectID | NoneThe old sha the refname must refer to, or None to delete unconditionally.
committer:bytes | NoneOptional committer name/email
timestamp:int | NoneOptional timestamp
timezone:int | NoneOptional timezone
message:bytes | NoneMessage for reflog
Returns
boolUndocumented
def set_if_equals(self, name: Ref, old_ref: ObjectID | None, new_ref: ObjectID, committer: bytes | None = None, timestamp: int | None = None, timezone: int | None = None, message: bytes | None = None) -> bool:

Set a refname to new_ref only if it currently equals old_ref.

This method follows all symbolic references if applicable for the subclass, and can be used to perform an atomic compare-and-swap operation.

Returns: True if the set was successful, False otherwise.

Parameters
name:RefThe refname to set.
old_ref:ObjectID | NoneThe old sha the refname must refer to, or None to set unconditionally.
new_ref:ObjectIDThe new sha the refname will refer to.
committer:bytes | NoneOptional committer name/email
timestamp:int | NoneOptional timestamp
timezone:int | NoneOptional timezone
message:bytes | NoneMessage for reflog
Returns
boolUndocumented
def set_symbolic_ref(self, name: Ref, other: Ref, committer: bytes | None = None, timestamp: int | None = None, timezone: int | None = None, message: bytes | None = None):

Make a ref point at another ref.

Parameters
name:RefName of the ref to set
other:RefName of the ref to point at
committer:bytes | NoneOptional committer name/email
timestamp:int | NoneOptional timestamp
timezone:int | NoneOptional timezone
message:bytes | NoneOptional message
def subkeys(self, base: Ref) -> set[Ref]:

Refs present in this container under a base.

Returns: A set of valid refs in this container under the base; the base
prefix is stripped from the ref names returned.
Parameters
base:RefThe base to return refs under.
Returns
set[Ref]Undocumented
def _check_refname(self, name: Ref):

Ensure a refname is valid and lives in refs or is HEAD.

HEAD is not a valid refname according to git-check-ref-format, but this class needs to be able to touch HEAD. Also, check_ref_format expects refnames without the leading 'refs/', but this class requires that so it cannot touch anything outside the refs dir (or HEAD).

Parameters
name:RefThe name of the reference.
Raises
KeyErrorif a refname is not HEAD or is otherwise not valid.
def _log(self, ref: bytes, old_sha: bytes | None, new_sha: bytes | None, committer: bytes | None = None, timestamp: int | None = None, timezone: int | None = None, message: bytes | None = None):

Undocumented

_logger =

Undocumented