Skip to content

Commit 5de67af

Browse files
committed
when parsing a commit, split up the author and committer fields into name, email and commit time. This adds two new DateTime fields, authored_time and committed_time to ::Commit and changes the type of the author and committer fields to Git::PurePerl::Actor, which is an object with name and email fields (thanks to martijn)
1 parent 585d099 commit 5de67af

File tree

6 files changed

+58
-32
lines changed

6 files changed

+58
-32
lines changed

Diff for: CHANGES

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Revision history for Perl module Git::PurePerl:
44
- allow subdirectories in .git/refs/*/ (thanks to martijn)
55
- run protocol.t test with --base-path to not care about where
66
on the filesystem the checkout is (thanks to martijn)
7+
- when parsing a commit, split up the author and committer
8+
fields into name, email and commit time. This adds two new
9+
DateTime fields, authored_time and committed_time to ::Commit
10+
and changes the type of the author and committer fields to
11+
Git::PurePerl::Actor, which is an object with name and
12+
email fields (thanks to martijn)
713

814
0.40 Fri Mar 13 15:29:02 GMT 2009
915
- Skip protocol tests on Win32 (thanks to fayland)

Diff for: Makefile.PL

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WriteMakefile(
1313
'Compress::Raw::Zlib' => '0',
1414
'Compress::Zlib' => '0',
1515
'Data::Stream::Bulk' => '0',
16+
'DateTime' => '0',
1617
'Digest::SHA1' => '0',
1718
'File::Find::Rule' => '0',
1819
'IO::Digest', => '0',

Diff for: lib/Git/PurePerl.pm

+2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use Compress::Zlib qw(uncompress);
66
use Data::Stream::Bulk;
77
use Data::Stream::Bulk::Array;
88
use Data::Stream::Bulk::Path::Class;
9+
use DateTime;
910
use Digest::SHA1;
1011
use File::Find::Rule;
12+
use Git::PurePerl::Actor;
1113
use Git::PurePerl::DirectoryEntry;
1214
use Git::PurePerl::Loose;
1315
use Git::PurePerl::Object;

Diff for: lib/Git/PurePerl/Object/Commit.pm

+26-7
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ has 'kind' =>
88
( is => 'ro', isa => 'ObjectKind', required => 1, default => 'commit' );
99
has 'tree_sha1' => ( is => 'rw', isa => 'Str', required => 0 );
1010
has 'parent_sha1' => ( is => 'rw', isa => 'Str', required => 0 );
11-
has 'author' => ( is => 'rw', isa => 'Str', required => 0 );
12-
has 'committer' => ( is => 'rw', isa => 'Str', required => 0 );
13-
has 'comment' => ( is => 'rw', isa => 'Str', required => 0 );
11+
has 'author' => ( is => 'rw', isa => 'Git::PurePerl::Actor', required => 0 );
12+
has 'authored_time' => ( is => 'rw', isa => 'DateTime', required => 0 );
13+
has 'committer' =>
14+
( is => 'rw', isa => 'Git::PurePerl::Actor', required => 0 );
15+
has 'committed_time' => ( is => 'rw', isa => 'DateTime', required => 0 );
16+
has 'comment' => ( is => 'rw', isa => 'Str', required => 0 );
1417

1518
__PACKAGE__->meta->make_immutable;
1619

1720
my %method_map = (
18-
'tree' => 'tree_sha1',
19-
'parent' => 'parent_sha1',
21+
'tree' => 'tree_sha1',
22+
'parent' => 'parent_sha1',
23+
'author' => 'authored_time',
24+
'committer' => 'committed_time'
2025
);
2126

2227
sub BUILD {
@@ -26,8 +31,22 @@ sub BUILD {
2631
while ( my $line = shift @lines ) {
2732
last unless $line;
2833
my ( $key, $value ) = split ' ', $line, 2;
29-
$key = $method_map{$key} || $key;
30-
$self->$key($value);
34+
if ( $key eq 'committer' or $key eq 'author' ) {
35+
my @data = split ' ', $value;
36+
my ( $email, $epoch, $tz ) = splice( @data, -3 );
37+
$email = substr( $email, 1, -1 );
38+
my $name = join ' ', @data;
39+
my $actor
40+
= Git::PurePerl::Actor->new( name => $name, email => $email );
41+
$self->$key($actor);
42+
$key = $method_map{$key};
43+
my $dt
44+
= DateTime->from_epoch( epoch => $epoch, time_zone => $tz );
45+
$self->$key($dt);
46+
} else {
47+
$key = $method_map{$key} || $key;
48+
$self->$key($value);
49+
}
3150
}
3251
$self->comment( join "\n", @lines );
3352
}

Diff for: t/protocol.t

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ BEGIN {
77
if ( $^O eq 'MSWin32' ) {
88
plan skip_all => 'Windows does NOT have git-daemon yet';
99
}
10-
plan tests => 12;
10+
plan tests => 14;
1111
}
1212
use Git::PurePerl;
1313
use IO::File;
@@ -36,8 +36,8 @@ is( $commit->size, 256 );
3636
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
3737
is( $commit->tree_sha1, '37b4fcd62571f07408e830f455268891f95cecf5' );
3838
like( $commit->parent_sha1, qr/^[a-z0-9]{40}$/ );
39-
like( $commit->author,
40-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
41-
like( $commit->committer,
42-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
43-
is( $commit->comment, 'add again' );
39+
is( $commit->author->name, 'Your Name Comes Here' );
40+
is( $commit->author->email, '[email protected]' );
41+
is( $commit->committer->name, 'Your Name Comes Here' );
42+
is( $commit->committer->email, '[email protected]' );
43+
is( $commit->comment, 'add again' );

Diff for: t/simple.t

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!perl
22
use strict;
33
use warnings;
4-
use Test::More tests => 186;
4+
use Test::More tests => 198;
55
use Git::PurePerl;
66
use Path::Class;
77

@@ -18,11 +18,13 @@ foreach my $directory qw(test-project test-project-packs test-project-packs2)
1818
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
1919
is( $commit->tree_sha1, '37b4fcd62571f07408e830f455268891f95cecf5' );
2020
like( $commit->parent_sha1, qr/^[a-z0-9]{40}$/ );
21-
like( $commit->author,
22-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
23-
like( $commit->committer,
24-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
25-
is( $commit->comment, 'add again' );
21+
isa_ok( $commit->author, 'Git::PurePerl::Actor' );
22+
isa_ok( $commit->committer, 'Git::PurePerl::Actor' );
23+
is( $commit->author->name, 'Your Name Comes Here' );
24+
is( $commit->committer->name, 'Your Name Comes Here' );
25+
isa_ok( $commit->authored_time, 'DateTime' );
26+
is( $commit->authored_time->month, 11 );
27+
is( $commit->comment, 'add again' );
2628

2729
my $tree = $commit->tree;
2830
is( $tree->kind, 'tree' );
@@ -48,11 +50,9 @@ hello world, again
4850
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
4951
is( $commit->tree_sha1, 'd0492b368b66bdabf2ac1fd8c92b39d3db916e59' );
5052
like( $commit->parent_sha1, qr/^[a-z0-9]{40}$/ );
51-
like( $commit->author,
52-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
53-
like( $commit->committer,
54-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
55-
is( $commit->comment, 'add emphasis' );
53+
is( $commit->author->email, '[email protected]' );
54+
is( $commit->committer->email, '[email protected]' );
55+
is( $commit->comment, 'add emphasis' );
5656

5757
$tree = $commit->tree;
5858
is( $tree->kind, 'tree' );
@@ -75,14 +75,12 @@ hello world, again
7575
is( $commit->kind, 'commit' );
7676
is( $commit->size, 213 );
7777
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
78-
is( $commit->tree_sha1, '92b8b694ffb1675e5975148e1121810081dbdffe' );
79-
is( $commit->parent_sha1, undef );
80-
is( $commit->parent, undef );
81-
like( $commit->author,
82-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
83-
like( $commit->committer,
84-
qr/^Your Name Comes Here <you\@yourdomain.example.com>/ );
85-
is( $commit->comment, 'initial commit' );
78+
is( $commit->tree_sha1, '92b8b694ffb1675e5975148e1121810081dbdffe' );
79+
is( $commit->parent_sha1, undef );
80+
is( $commit->parent, undef );
81+
is( $commit->author->name, 'Your Name Comes Here' );
82+
is( $commit->committer->name, 'Your Name Comes Here' );
83+
is( $commit->comment, 'initial commit' );
8684

8785
$tree = $commit->tree;
8886
is( $tree->kind, 'tree' );

0 commit comments

Comments
 (0)