Skip to content

Commit c4bd5a5

Browse files
committed
Add support for parsing Git Commits with GPG Signatures
1 parent 695f1ba commit c4bd5a5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Revision history for Perl module Git::PurePerl:
22

3+
- Add decoding support for the new gpgsig commit header (Kent Fredric)
34
- Add basic documentation for Object::Commit (Kent Fredric)
45
- Add has_ancestor_sha1 method to Object::Commit (Kent Fredric)
56
- Add Git::PurePerl::Util with handy current_git_dir() util (Kent Fredric)

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ has 'committer' =>
1818
has 'committed_time' => ( is => 'rw', isa => 'DateTime', required => 0 );
1919
has 'comment' => ( is => 'rw', isa => 'Str', required => 0 );
2020
has 'encoding' => ( is => 'rw', isa => 'Str', required => 0 );
21+
has 'gpg_signature' => ( is => 'rw', isa => 'Str', required => 0 );
2122

2223
my %method_map = (
2324
'tree' => 'tree_sha1',
2425
'parent' => '_push_parent_sha1',
2526
'author' => 'authored_time',
26-
'committer' => 'committed_time'
27+
'committer' => 'committed_time',
28+
'gpgsig' => 'gpg_signature',
2729
);
2830

2931
sub BUILD {
@@ -32,6 +34,26 @@ sub BUILD {
3234
my @lines = split "\n", $self->content;
3335
my %header;
3436
while ( my $line = shift @lines ) {
37+
38+
# Apparent format is roughly:
39+
#
40+
# <token><space><DATA>
41+
# <space><DATA> # repeated
42+
#
43+
# And a line not leading with <space> ends the token.
44+
#
45+
# Though, at present, git itself has this special-cased for GPG Signatures.
46+
#
47+
# Its probably extendable to support any value of <token> though.
48+
if ( $line =~ /^gpgsig (.*$)/ ) {
49+
my $sig = "$1";
50+
while ( $line = $lines[0] ) {
51+
last unless $line =~ /^ (.*$)/;
52+
$sig .= "$1\n";
53+
shift @lines;
54+
}
55+
push @{ $header{gpgsig} }, $sig;
56+
}
3557
last unless $line;
3658
my ( $key, $value ) = split ' ', $line, 2;
3759
push @{$header{$key}}, $value;

0 commit comments

Comments
 (0)