Git图形到networkx
git-networkx的Python项目详细描述
Git网络X
https://github.com/hoduche/git-graph到NetworkX
安装
PyPi
pip install git-networkx
Git
pip install git+https://github.com/CircArgs/git-networkx.git
演示
fromnetworkx.drawing.nx_pydotimportwrite_dotfromgit_networkximportGitNX,Commit#everythingAll=GitNX('my/repo/path/that/has/a/git/directory')#networkx Digraph representing all nodes of the git repo#Commits#notice the path does not have to be .git in case you have used a different nameCommits=GitNX('my/repo/path/located/in/.got',"c")#networkx Digraph representing only commits of the git repo#again, the results of GitNX is just a networkx.DiGraph and as such you can do anything you would on such an object[nforninAllifisinstance(n,Commit)]
假设您有如下日志:
^{pr2}$那么
G=GitNX(".","lch")print(list(G.neighbors(Commit("80798c310455976e08fedd9b367794692ebb54a6"))))# [Commit('8c7f9cea1f6323d793cd035e2178636d6ebf0a36')]print(list(G.predecessors(Commit("80798c310455976e08fedd9b367794692ebb54a6"))))# [Commit('9a99a4d85cb14005ca829e2cab8f626b4034b981')]print(list(G.predecessors(Commit('9a99a4d85cb14005ca829e2cab8f626b4034b981'))))# [LocalBranch('dev'), LocalBranch('master')]
节点
此表显示了图形中可以包含哪些节点。Letter
表示用于创建图形的过滤器,作为git_networkx.GitNX
的第二个位置参数,即nodes
参数。在
如上面的例子所示,来自GitNX
的DiGraph
可以通过检查下面的节点类isinstance
进行过滤,或者通过一个类的实例进行过滤。在
整体节点类:GitNode
Node kind | Letter | Node Class | Node kind | Letter | Node Class |
---|---|---|---|---|---|
blob | b | Blob | remote branch | r | RemoteBranch |
tree | t | Tree | remote head | d | RemoteHead |
commit | c | Commit | remote server | s | RemoteServer |
local branch | l | LocalBranch | annotated tag | a | AnnotatedTag |
local head | h | LocalHead | tag | g | Tag |
默认情况下,所有节点都添加到有向图中。在
# you can get your commits, branches and the head of your local repo simply with lchG=GitNX('../git_networkx_test/',"lch")
- 项目
标签: