Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created April 15, 2019 06:01
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 andrewsolomon/29d38ed4276e9a042c4b9664b59d9e11 to your computer and use it in GitHub Desktop.
Save andrewsolomon/29d38ed4276e9a042c4b9664b59d9e11 to your computer and use it in GitHub Desktop.
Transforming a git repository into a co-modification graph
#!/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