Skip to main content

Git-NetworkX

Port of https://github.com/hoduche/git-graph to NetworkX


Install

PyPi

pip install git-networkx

Git

pip install git+https://github.com/CircArgs/git-networkx.git

Demo

from networkx.drawing.nx_pydot import write_dot
from git_networkx import GitNX, Commit
#everything
All = 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 name
Commits = 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
[n for n in All if isinstance(n, Commit)]

Suppose you had a log like the following:

commit 9a99a4d85cb14005ca829e2cab8f626b4034b981 (HEAD -> master, dev)
Author: CircArgs <quebecname@gmail.com>
Date:   Fri Aug 14 22:05:30 2020 -0400

    I like dogs

commit 80798c310455976e08fedd9b367794692ebb54a6
Author: CircArgs <quebecname@gmail.com>
Date:   Fri Aug 14 22:04:58 2020 -0400

    add file2 with text

commit 8c7f9cea1f6323d793cd035e2178636d6ebf0a36
Author: CircArgs <quebecname@gmail.com>
Date:   Fri Aug 14 22:04:28 2020 -0400

    add file 1

then

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')]

Nodes

This table shows what nodes can be in a graph. The Letters denote the filters for creation of the graph as the second positional argument to git_networkx.GitNX i.e. the nodes argument.

As shown in above examples, the DiGraph from GitNX can be filtered by checking isinstance against the Node Classes below or by filtering by a an instance of one of the classes.

Overall Node Class: 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

By default all nodes are added to the DiGraph.

# you can get your commits, branches and the head of your local repo simply with lch
G=GitNX('../git_networkx_test/', "lch")

Metadata

Release files for git-networkx 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-networkx 2.3.0
File Size Uploaded
git-networkx-2.3.0.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for git-networkx 2.3.0
File Interpreter ABI Platform
git_networkx-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / git-networkx-2.3.0.tar.gz

Download URL git-networkx-2.3.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dd2d93f3e4091fecab2bbb61b8cac594f13ef1eac25f1fb727cef85b61375c14
BLAKE2b-256 checksum
How to use checksums
439da4a017a082aff4ed7310e982f850e12e5b02a53f4fb7719ce26415ae1612
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.6 Linux/5.4.0-42-generic

Release files / git_networkx-2.3.0-py3-none-any.whl

Download URL git_networkx-2.3.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd22311aec3bada787c21eb5610e06adef7f21cb1a14071ffa65e4d49cc7ee4f
BLAKE2b-256 checksum
How to use checksums
e404b19d2b34458e9b8f6634bfbe39d7912528c0bc80b756238957a758167f58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.6 Linux/5.4.0-42-generic

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 release files

2.2.0

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page