git2dot.git2dot module

git2dot library

class git2dot.git2dot.GitDigraph(*args, **kwargs)[source]

Bases: graphviz.dot.Digraph

Directed graph source code in the DOT language.

Eats git objs (self.addGitObj), git refs (self.addGitRef) and inserts edges (addGitEdge).

addGitEdge(parent, child, **kwargs)[source]

Add a ‘parent’ –> ‘child’ edge.

Parameters:
  • parent (str) – label (ID) of the parent
  • child (str) – label (ID) of the parent

If the ‘parent’ –> ‘child’ edge is already added, nothing happens.

addGitObj(gitObj)[source]

Add a git-obj node.

Parameters:
  • gitObj (git.objects.base.Object) – git-object
  • tarverse (bool) – if True do traverse (default: False)

The object (node) and all it’s edges to parents will be added. If the git-obj is already added, nothing happens. The node ID is taken from the hexsha of the git-obj (GitFormatter.getID())

addGitRef(gitRef, traverse=False)[source]

Add a git-ref node to the graph

Parameters:
  • gitRef (git.refs.reference.Reference) – git-ref
  • tarverse (bool) – if True do traverse (default: False)

The git-ref (node), the object (node) it points to and the edge will be added. If the git-ref is already added, nothing happens. The node ID is the path (e.g. refs/heads/master) of the git-ref (GitFormatter.getID()).

The bool argument ‘traverse’ can be used to control whether a traversal should be carried out.

dumpGraph()[source]

dump all git nodes & edges

pipe(*args, **kwargs)[source]
save(*args, **kwargs)[source]
class git2dot.git2dot.GitFormatter(git_item, styles)[source]

Bases: object

Formating git/graphviz nodes & edges

DATE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
LABELS = {'ref': '<%(path)s>', 'branch': '<<B>branch<BR/>%(name)s</B>>', 'commit': '<%(hexsha:short)s:<B>%(message:short)s</B><BR/> %(author.name)s %(committed_date)s>', 'head': '<<B>HEAD<BR/>%(name)s</B>>'}
NODE_ATTRS = {'ref': {'fillcolor': '%(REF_COLOR)s'}, 'branch': {'fillcolor': '%(BRANCH_COLOR)s'}, 'commit': {}, 'head': {'fillcolor': '%(HEAD_COLOR)s'}}
SHA_SHORT_LENGTH = 6
dumpNode(graph)[source]

generate DOT node

classmethod escape(s)[source]

Replace special characters “&”, “<” and “>” to HTML-safe sequences.

getAttrs()[source]

get DOT attributes of this node

getID()[source]

get ID of this DOT node

getLabel()[source]

get label of this DOT node

type

type of this node (branch, head, commit, ..)