Last active
April 28, 2019 09:54
-
-
Save kuniyoshi/9916bf0b6ab57141e1e9b70f131ad71d to your computer and use it in GitHub Desktop.
git log --format="BEGIN%nCO %H%nDA %aI %an" \*.cs | ./parse_commit.pl
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/env perl -s | |
use 5.10.0; | |
use utf8; | |
use strict; | |
use warnings; | |
use open qw( :utf8 :std ); | |
use Data::Dumper; | |
my $context = Context->new( ); | |
while ( <> ) { | |
chomp( my $line = $_ ); | |
if ( $line eq "BEGIN" ) { | |
say $_ | |
for $context->changes( ); | |
$context = Context->new( ); | |
next; | |
} | |
$context->add( $line ); | |
} | |
say $_ | |
for $context->changes( ); | |
exit; | |
package Context; | |
sub new { | |
my $class = shift; | |
my $self = bless { changes => [ ] }, $class; | |
return $self; | |
} | |
sub changes { | |
my $self = shift; | |
return map { join "\t", @{ $self }{ qw( commit date_time author ) }, @{ $_ }{ qw( added deleted filename ) } } | |
@{ $self->{changes} }; | |
} | |
sub add { | |
my $self = shift; | |
my $line = shift; | |
if ( $line =~ m{\A DA \b}msx ) { | |
my( undef, $date_time, $author ) = split m{\t}, $line; | |
$self->{date_time} = $date_time; | |
$self->{author} = $author; | |
return; | |
} | |
if ( $line =~ m{\A (\d+) \s+ (\d+) \s+ (.*) }msx ) { | |
my( $added, $deleted, $filename ) = ( $1, $2, $3 ); | |
push @{ $self->{changes} }, { | |
added => $added, | |
deleted => $deleted, | |
filename => $filename, | |
}; | |
return; | |
} | |
if ( $line =~ m{\A CO \s+ (.*) \z}msx ) { | |
$self->{commit} = $1; | |
return; | |
} | |
if ( $line eq "" ) { | |
return; | |
} | |
if ( $line =~ m{\A \s }msx ) { | |
return; | |
} | |
warn "Could not parse line: [$line], in context: ", | |
Data::Dumper->new( [ $self ] ) | |
->Terse( 1 ) | |
->Dump; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: literal tab exists in format