Skip to content

Instantly share code, notes, and snippets.

@darabos
Created June 29, 2020 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darabos/3d8a8bf790deda987efa3b6f726b08d4 to your computer and use it in GitHub Desktop.
Save darabos/3d8a8bf790deda987efa3b6f726b08d4 to your computer and use it in GitHub Desktop.
Script for creating a graph of files from a Git history.
'''Creates a graph of source files connected by cooccurrence in commits.
git log --oneline --name-only | python git-to-graph.py > graph.csv
'''
import sys
import re
print('file1,file2,commit')
commit = None
files = []
for line in sys.stdin:
if re.match('[0-9a-f]{9} ', line):
if commit and len(files) < 10:
for f1 in files:
for f2 in files:
if f1 != f2:
print(f'"{f1}","{f2}","{commit}"')
commit = line[10:].strip().replace('"', '\\"')
files = []
else:
files.append(line.strip().replace('"', '\\"'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment