maggit package api

class maggit.Sha

Bases: bytes

A Sha is a git sha. It means that it is the identifier of a git object.

Sha are store in Maggit as a 20 bytes len.

hexbytes

The sha as a hexlified bytes

hexstr

The sha as a hexlified str

class maggit.Repo(gitdir=None, disable_directoryLooking=False, bare=False)

Bases: maggit.db.repo.Repo

This is the central piece of a git repository.

HEAD

The current checkouted branch

branches

A dict 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_blob(sha)

Get a blob object for the sha.

Parameters:sha (Sha) – The sha of the blob.
Returns:class:~maggit.git_objects.Blob object for this sha.
Return type:A
Raises::Exception – If sha doesn’t name a blob object.
get_commit(sha)

Get a commit object for the sha.

Parameters:sha (Sha) – The sha of the commit.
Returns:class:~maggit.repo.Commit object for this sha.
Return type:A
Raises::Exception – If sha doesn’t name a commit object.
get_full_sha(prefix)

Return the full Sha of the prefix

Parameters:prefix (bytes) – The beginning of a sha.
Returns:class:~maggit.Sha corresponding.
Return type:The
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_git_dir(dirToCheck=None)
get_object(sha, type_=None)

Get a git object for the sha.

Parameters:
  • sha (Sha) – The sha of the object.
  • type (ObjectType or None) – The type of the object. If this is None (or not set), the type is detected automatically.
Returns:

class:~maggit.git_objects.GitObject object for this sha.

Return type:

A

Raises:

:Exception – If sha doesn’t name a object.

get_peel_ref_sha(ref)
get_ref_sha(name)

Return the Sha corresponding to the reference name

Parameters:name (str) – The reference name.
Returns:class:~maggit.Sha corresponding.
Return type:The
Exemples:
>>> repo.get_ref_sha('master')
<Sha >
Raises::Exception – If number of object corresponding to prefix is not equal to one.
get_tag(sha)

Get a tag object for the sha.

Parameters:sha (Sha) – The sha of the tag.
Returns:class:~maggit.git_objects.Tag object for this sha.
Return type:A
Raises::Exception – If sha doesn’t name a tag object.
get_tree(sha)

Get a tree object for the sha.

Parameters:sha (Sha) – The sha of the tree.
Returns:class:~maggit.git_objects.Tree object for this sha.
Return type:A
Raises::Exception – If sha doesn’t name a tree object.
init_repo(gitdir, bare=False)

Instantiate a new git repo at the given location.

tags

A dict of tags in the repo

class maggit.ObjectType

This is a enum listing possible type for a git object.

class maggit.repo.Entry(repo, commit, path, mode, gitObject)

A Entry represent a entry (file or directory) at a specific time.

We can somehow see a repository as a complex 2 dimentionnal array. Commits (and so the history) are rows. Files (and Trees) are columns.

In this situations, Entry are the cells of this array.

get_first_appearance()

Get the commit who firstly introduce the current version of the change.

Returns:class:~maggit.repo.Commit
Return type:A
parents

The previous versions of the files.

Previous versions can be equal to the current one if the current commit introduce no change on this file.

The length of the parents will most of the time be 1 but may be greater in case of merge.

class maggit.repo.Commit(repo, sha)
get_file(path)

Get an entry corresponding to the path in the commit

Parameters:path (str or Path) – The path of the file to look at.
Returns:class:~maggit.repo.Entry corresponding.
Return type:A
Raise:
KeyError if the path is not existing.
get_first_appearance(path)

Return the commit where the present version of path was introduce.

Parameters:path (str or path) – The path of the file.
Returns:class:maggit.repo.Commit
Return type:A
Exemples:
>>> first_appearance_commit = this_commit.get_first_appearance(path)
>>> # first_appearance_commit is the first one, so previous version differs
>>> parent = first_appearance_commit.parents[0]
>>> assert first_appearance_commit.get_file(path).gitObject != parent.get_file(path).gitObject
>>> # from this_commit to first_appearance_commit, there is no change
>>> current = this_commit
>>> while current != first_appearance_commit:
...     assert current.get_file(path).gitObject == this_commit.get_file(path).gitObject
...     current = current.parents[0]
get_first_appearances(root=None, depthLimit=None)

Return the first appearances for all entry in root.

This is mostly equivalent to {path:commit.get_first_appearance(path) for path in commit.tree.entries} (if root is None). But a way more performant as diving into history is made once.

Parameters:
  • root (str or Path) – In wich subdirectory we must look.
  • depthLimit (int) – The commit limit number we go in history If depthLimit is specified, and for a entry the first appearance is older than depthLimit, the entry will be present in the dictionnary with a None value.
Returns:

class:maggit.repo.Commit).

Return type:

A dict of (Path,

maggit.git_objects module

class maggit.git_objects.GitObject(repo, sha)

The base class for all git objects.

Git objects are conceptualy constant. However as we try to be lazy, slots are not fill at object creation and set when user read it. So GitObject are not constant but behave as if they were.

repo

Repo

The repo associated with the object.

sha

Sha

The sha of the object.

gitType

ObjectType

The type of the object.

class maggit.git_objects.Blob(repo, sha)

Bases: maggit.git_objects.GitObject

A blob object.

content

bytes

This is the content of the blob.

class maggit.git_objects.Tree(repo, sha)

Bases: maggit.git_objects.GitObject

A blob object.

entries

unmutable mapping

This is the entries of the tree.

class maggit.git_objects.Commit(repo, sha)

Bases: maggit.git_objects.GitObject

A commit object.

tree

maggit.git_objects.Tree

The tree object associated with the commit.

parents

tuple

The parents of the commits. Most of the time, there will only one parent. In case of branch merge, there will be more than one parent.

author

bytes

The author of the commit. (This is the raw content in the commit. This means that it is a bytes with the name, email and commit timestamp)

committer

bytes

The committer of the commit. (This is the raw content in the commit. This means that it is a bytes with the name, email and commit timestamp)

first_line

str

The first line of the commit message.

message

str

The full commit message (including the first line).

class maggit.git_objects.Tag(repo, sha)

Bases: maggit.git_objects.GitObject

A tag object.

object

GitObject

The git object tagged by this tag.

objectType

ObjectType

The type of the git object tagged by this tag.

tag

str

The name of the tag.

tagger

bytes

The person who create the tag. (This is the raw content in the tag. This means that it is a bytes with the name, email and tag timestamp)

first_line

str

The first line of the tag message.

message

str

The full tag message (including the first line).

maggit.refs module

class maggit.refs.Ref(repo, sha)

Bases: maggit.refs.BaseRef

commit
repo
sha
class maggit.refs.Branche(repo, branchName)

Bases: maggit.refs.BaseRef

commit
name
repo
sha
class maggit.refs.Tag(repo, tagName)

Bases: maggit.refs.BaseRef

commit
name
object
repo
sha