Advertisement
Guest User

Forensic Versioning

a guest
Oct 3rd, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.86 KB | None | 0 0
  1. use strict;
  2. use File::Basename;
  3. use Digest::SHA;
  4. use File::Copy;
  5.  
  6. my $files;
  7. while (<>) {
  8.         chomp;
  9.         my @line = split(/ /, $_, 8);
  10.         my ($name,$path) = fileparse($line[7]);
  11.         open (my $fh, '<', $path . $name) or die "$!";
  12.         my $sha = Digest::SHA->new('sha1');
  13.         $sha->addfile($fh);
  14.         push(@{$files->{$name}->{$sha->hexdigest}}, [ $line[7], $line[5] ] );
  15. }
  16.  
  17. for my $file (sort keys %$files) {
  18.         for my $hash (sort keys %{$files->{$file}}) {
  19.                 copy($files->{$file}->{$hash}[0][0], '.') or die $!;
  20.                 my $commitMessage;
  21.                 for (@{$files->{$file}->{$hash}}) {
  22.                         $commitMessage .= ( join("\t", @$_, ) . "\n" );
  23.                 }
  24.                 system('git', 'add', $file);
  25.                 system('git', 'commit', '-m', $commitMessage);
  26.         }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement