Created
April 15, 2019 06:01
-
-
Save andrewsolomon/29d38ed4276e9a042c4b9664b59d9e11 to your computer and use it in GitHub Desktop.
Transforming a git repository into a co-modification graph
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
#!/usr/bin/perl | |
# Converts a gitlog file to a list of edges in an undirected weighted graph | |
# Author: Aron Lurie | |
# Date: 2018-08-15 | |
# Usage: git log --pretty=oneline --name-only | perl git.pl > mylogfile.txt | |
my @files = (); | |
my %adjacent = (); | |
while (<STDIN>) { | |
chomp; | |
if ($_ =~ /[a-f0-9]{40} /) { | |
if (@files) { | |
for my $filename (@files) { | |
for my $other_filename (@files) { | |
next if ($filename > $other_filename); | |
$adjacent{$filename}{$other_filename}++; | |
} | |
} | |
} | |
@files = (); | |
} else { | |
push @files, $_; | |
} | |
} | |
for my $filename (keys %adjacent) { | |
for my $other_filename (keys %{ $adjacent{$filename} }) { | |
my $conn = $adjacent{$filename}{$other_filename}; | |
print join(",", ($filename, $other_filename, 1000/$conn)), "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment