Created
November 23, 2014 22:00
-
-
Save cstorey/619a6ca4789879b8e974 to your computer and use it in GitHub Desktop.
A trivial script to visualise a git history as a graphviz diagram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
from pygit2 import Repository, GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE | |
import pygit2 | |
from graphviz import Digraph | |
repository_path = pygit2.discover_repository(os.getcwd()) | |
repo = Repository(repository_path) | |
def nfmt(target): | |
return "N{0}".format(target.id) | |
g = Digraph(comment=repo.head.name, edge_attr={'dir': 'back'}) | |
for i, commit in enumerate(repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL)): | |
g.node(nfmt(commit), commit.message.split('\n')[0].strip()) | |
for p in commit.parents: | |
g.edge(nfmt(commit), nfmt(p)) | |
# if i > 2000: | |
# break | |
print g.source.encode('utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment