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 do_commit Create a new commit.
Method fetch Fetch objects into another repository.
Method fetch_objects Fetch the missing objects required for a set of revisions.
Method fetch_pack_data Fetch the pack data required for a set of revisions.
Method generate_pack_data Generate pack data objects for a set of wants/haves.
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_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_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 head Return the SHA1 pointed at by HEAD.
Method open_index Open the index for this repository.
Method parents_provider Undocumented
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_store Dictionary-like object for accessing the objects
Instance Variable refs Dictionary-like object with the refs in this repository
Method _add_graftpoints Add or modify graftpoints
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 _get_object Undocumented
Method _get_user_identity Determine the identity to use for new commits.
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):

Check if a specific Git object or ref is present.

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

Remove a ref.

Parameters
name:bytesName of the ref to remove
def __getitem__(self, name):

Retrieve a Git object by SHA1 or ref.

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

Parameters
name:Union[ObjectID, Ref]A Git object SHA1 or a ref name
Raises
KeyErrorwhen the specified ref or object does not exist
def __init__(self, object_store, refs):

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:BaseObjectStoreObject store to use
refs:RefsContainerRefs container to use
def __setitem__(self, name, value):

Set a ref.

Parameters
name:bytesref name
value:Union[ShaFile, bytes]Ref value - either a ShaFile object, or a hex sha
def do_commit(self, message=None, committer=None, author=None, commit_timestamp=None, commit_timezone=None, author_timestamp=None, author_timezone=None, tree=None, encoding=None, ref=b'HEAD', merge_heads=None, no_verify=False, sign=False):

Create a new commit.

If not specified, committer and author default to get_user_identity(..., 'COMMITTER') and get_user_identity(..., 'AUTHOR') respectively.

Parameters
message:Optional[bytes]Commit message
committer:Optional[bytes]Committer fullname
author:Optional[bytes]Author fullname
commit_timestampCommit timestamp (defaults to now)
commit_timezoneCommit timestamp timezone (defaults to GMT)
author_timestampAuthor timestamp (defaults to commit timestamp)
author_timezoneAuthor timestamp timezone (defaults to commit timestamp timezone)
tree:Optional[ObjectID]SHA1 of the tree root to use (if not specified the current index will be committed).
encoding:Optional[bytes]Encoding
ref:RefOptional ref to commit to (defaults to current branch)
merge_heads:Optional[List[ObjectID]]Merge heads (defaults to .git/MERGE_HEAD)
no_verify:boolSkip pre-commit and commit-msg hooks
sign:boolGPG Sign the commit (bool, defaults to False, pass True to use default GPG key, pass a str containing Key ID to use a specific GPG key)
Returns
New commit SHA1
def fetch(self, target, determine_wants=None, progress=None, depth=None):

Fetch objects into another repository.

Returns: The local refs

Parameters
targetThe target repository
determine_wantsOptional function to determine what refs to fetch.
progressOptional progress function
depthOptional shallow fetch depth
def fetch_objects(self, determine_wants, graph_walker, progress, get_tagged=None, depth=None):

Fetch the missing objects required for a set of revisions.

Returns: iterator over objects, with __len__ implemented

Parameters
determine_wantsFunction that takes a dictionary with heads and returns the list of heads to fetch.
graph_walkerObject 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.
progressSimple progress function that will be called with updated progress strings.
get_taggedFunction that returns a dict of pointed-to sha -> tag sha for including tags.
depthShallow fetch depth
def fetch_pack_data(self, determine_wants, graph_walker, progress, get_tagged=None, depth=None):

Fetch the pack data required for a set of revisions.

Returns: count and iterator over pack data

Parameters
determine_wantsFunction that takes a dictionary with heads and returns the list of heads to fetch.
graph_walkerObject 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.
progressSimple progress function that will be called with updated progress strings.
get_taggedFunction that returns a dict of pointed-to sha -> tag sha for including tags.
depthShallow fetch depth
def generate_pack_data(self, have, want, progress=None, ofs_delta=None):

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

Parameters
have:List[ObjectID]List of SHA1s of objects that should not be sent
want:List[ObjectID]List of SHA1s of objects that should be sent
progress:Optional[Callable[[str], None]]Optional progress reporting method
ofs_delta:Optional[bool]Whether OFS deltas can be included
def get_config(self):

Retrieve the config object.

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

Returns
ConfigFileUndocumented
def get_config_stack(self):

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

Returns
StackedConfigUndocumented
def get_description(self):

Retrieve the description for this repository.

Returns: String with the description of the repository
as set by the user.
def get_graph_walker(self, heads=None):

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:Optional[List[ObjectID]]Repository heads to use (optional)
Returns
ObjectStoreGraphWalkerUndocumented
def get_named_file(self, path):

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
Optional[BinaryIO]Undocumented
def get_object(self, sha):

Retrieve the object with the specified SHA.

Returns: A ShaFile object

Parameters
sha:bytesSHA to retrieve
Returns
ShaFileUndocumented
Raises
KeyErrorwhen the object can not be found
def get_parents(self, sha, commit=None):

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:bytesSHA of the commit for which to retrieve the parents
commit:Optional[Commit]Optional commit matching the sha
Returns
List[bytes]Undocumented
def get_peeled(self, ref):

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_refs(self):

Get dictionary with all refs.

Returns: A dict mapping ref names to SHA1s

Returns
Dict[bytes, bytes]Undocumented
def get_shallow(self):

Get the set of shallow commits.

Returns: Set of shallow commits.

Returns
Set[ObjectID]Undocumented
def get_walker(self, include=None, *args, **kwargs):

Obtain a walker for this repository.

Returns: A Walker object

Parameters
include:Optional[List[bytes]]Iterable of SHAs of commits to include along with their ancestors. Defaults to [HEAD]
*argsUndocumented
**kwargsUndocumented
excludeIterable of SHAs of commits to exclude along with their ancestors, overriding includes.
orderORDER_* constant specifying the order of results. Anything other than ORDER_DATE may result in O(n) memory usage.
reverseIf True, reverse the order of output, requiring O(n) memory.
max_entriesThe maximum number of entries to yield, or None for no limit.
pathsIterable of file or subtree paths to show entries for.
rename_detectordiff.RenameDetector object for detecting renames.
followIf True, follow path across renames/copies. Forces a default rename_detector.
sinceTimestamp to list commits after.
untilTimestamp to list commits before.
queue_clsA class to use for a queue of commits, supporting the iterator protocol. The constructor takes a single argument, the Walker.
def head(self):

Return the SHA1 pointed at by HEAD.

Returns
bytesUndocumented
def open_index(self):

Open the index for this repository.

Returns: The matching Index

Returns
IndexUndocumented
Raises
NoIndexPresentIf no index is present
def parents_provider(self):

Undocumented

Returns
ParentsProviderUndocumented
def set_description(self, description):

Set the description for this repository.

Parameters
descriptionText to set as description for this repository.
def update_shallow(self, new_shallow, new_unshallow):

Update the list of shallow objects.

Parameters
new_shallowNewly shallow objects
new_unshallowNewly no longer shallow objects
hooks: Dict[str, Hook] =

Undocumented

object_store =

Dictionary-like object for accessing the objects

refs =

Dictionary-like object with the refs in this repository

def _add_graftpoints(self, updated_graftpoints):

Add or modify graftpoints

Parameters
updated_graftpoints:Dict[bytes, List[bytes]]Dict of commit shas to list of parent shas
def _del_named_file(self, path):

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

Parameters
path:strUndocumented
def _determine_file_mode(self):

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

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

Returns
boolUndocumented
def _get_object(self, sha, cls):

Undocumented

def _get_user_identity(self, config, kind=None):

Determine the identity to use for new commits.

Parameters
config:StackedConfigUndocumented
kind:Optional[str]Undocumented
Returns
bytesUndocumented
def _init_files(self, bare):

Initialize a default set of named files.

Parameters
bare:boolUndocumented
def _put_named_file(self, path, contents):

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):

Undocumented

def _remove_graftpoints(self, to_remove=[]):

Remove graftpoints

Parameters
to_remove:List[bytes]List of commit shas
_graftpoints: Dict[bytes, List[bytes]] =
overridden in dulwich.repo.Repo

Undocumented