maggit.db package¶
This module contains all the low level classs to handle a git repository.
Class defined in this module use io functions and provide a more consistant API to access content of the git repository.
Most users will not use those object directly but better use the high level API provided by the maggit package itself.
maggit.db.db module¶
-
class
maggit.db.db.
Gitdb
(rootdir)¶ Bases:
object
The Gitdb, unify all loose/pack io function to provide a coherent access to content of a git repository.
A Gitdb handle only the reading of git objects. Not the references, remotes, ...
Parameters: rootdir (path) – The path of the objects directory (.git/objects) -
blob_content
(sha)¶ Read and parse a object assuming it is a blob.
Parameters: sha – The sha of the object. Returns: The content of the blob (bytes). Raises: ValueError
– If the object is not a blob.
-
blob_write
(content)¶
-
commit_content
(sha)¶ Read and parse a object assuming it is a commit.
Parameters: sha – The sha of the object. Returns: A tuple (tree, parents, message, author, committer) where: - tree is the sha of the tree object of the commit(unhexlified bytes).
- parents is a list of sha of the parents commit.
- message is the message of the commit.
- author is the name (b’name <email> timestamp’) of the author.
- author is the name (b’name <email> timestamp’) of the committer.
Return type: bytes, list[bytes], bytes, bytes, bytes Raises: ValueError
– If the object is not a commit.
-
commit_write
(treesha, message, author, authorDate, committer, committerDate, parents=[])¶
-
gen_pack_list
()¶
-
get_full_sha
(prefix)¶ Return the full Sha of the prefix
Parameters: prefix (bytes) – The beginning of a sha. Returns: The corresponding (bytes). - Exemples:
>>> repo.get_full_sha(b'bf09f0a9') <Sha b'bf09f0a9...'>
Raises: :Exception
– If number of object corresponding to prefix is not equal to one.
-
get_pack
(sha)¶ Get a pack containing the sha
Parameters: sha – The sha of the object Returns: class:~maggit.io.pack.GitPack containing the sha Return type: The
-
object_content
(sha)¶
-
object_exists
(sha)¶ Return True if the sha exists in the db
-
object_type
(sha)¶ Return the type of the object associated to sha.
Parameters: sha – The sha of the object. Returns: The type of the object.
-
tag_content
(sha)¶ Read and parse a object assuming it is a tag.
Parameters: sha – The sha of the object. Returns: A tuple (object, objecttype, tag, tagger, message) where: - object is the sha of the tagged object (unhexlified bytes).
- objecttype is the type of the tagged object.
- tag is the name of the tag.
- tagger is the name (b’name <email> timestamp’) of the tagger.
- message is the message of the tag.
Return type: bytes, bytes, bytes, bytes, bytes Raises: ValueError
– If the object is not a tag.
-
tag_write
(objectsha, tag, tagger, tagDate, message)¶
-
tree_content
(sha)¶ Read and parse a object assuming it is a tree.
Parameters: sha – The sha of the object. Returns: A list of (path, (mode, sha)) where : - path is the name of the entry.
- mode is the git mode.
- sha is the sha of the blob/tree object.
Return type: List[Tuple[bytes, Tuple[bytes, bytes]]] Raises: ValueError
– If the object is not a tree.
-
tree_write
(entries)¶
-
maggit.db.repo module¶
-
class
maggit.db.repo.
Repo
(gitdir=None, disable_directoryLooking=False, bare=False)¶ This is the low level Repository class.
The repo make the link between all other low level subsystems and recreate a coherent database.
Parameters: - gitdir (path) –
The directory path of the repository,
If is None, the current working directory is assumed.
- disable_directoryLooking (bool) – If True, assume that the gitdir is a valid path so do not search for a valid git repository in parents and gitdir must not be None.
- bare (bool) – Does the repository is a bare one. Only relevant if disable_directoryLooking is True. Else, the bare attribute is detected from the git repository structure.
-
HEAD
¶ The current checkouted branch
-
branches
¶ A iterator of branches in the repo
-
check_ref_exists
(ref)¶ Check that a ref exist in the git bdd.
Parameters: ref (str) – the ref to check. Returns: True if the ref exists, else False Return type: bool
-
get_full_sha
(value)¶ Return the full sha of the value
-
classmethod
get_git_dir
(dirToCheck=None)¶
-
get_peel_ref_sha
(ref)¶
-
get_ref_sha
(ref)¶ Return the sha corresponding to the ref.
Parameters: ref (str) – the ref to get. Returns: The sha corresponding to the ref Return type: bytes
-
classmethod
init_repo
(gitdir, bare=False)¶ Instantiate a new git repo at the given location.
A iterator of tags in the repo
- gitdir (path) –