File Coverage

lib/Git/Repo/Commits.pm
Criterion Covered Total %
statement 40 40 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 4 4 100.0
total 57 58 98.2


line stmt bran cond sub pod time code
1             package Git::Repo::Commits;
2              
3 1     1   130419 use warnings;
  1         2  
  1         46  
4 1     1   6 use strict;
  1         1  
  1         21  
5 1     1   5 use Carp;
  1         2  
  1         69  
6 1     1   5 use Git;
  1         1  
  1         36  
7              
8 1     1   578 use version; our $VERSION = qv('0.1.1'); # Work with a few files
  1         2058  
  1         7  
9              
10             # Other recommended modules (uncomment to use):
11             # use IO::Prompt;
12             # use Perl6::Export;
13             # use Perl6::Slurp;
14             # use Perl6::Say;
15              
16              
17             # Module implementation here
18             sub new {
19 4     4 1 67539 my $class = shift;
20 4   66     104 my $dir = shift || croak "Need a repo directory";
21 3         19 my $files_arrayref = shift;
22 3         34 my ($repo_name) = ($dir =~ m{/([^/]+)/?$} );
23 3         72 my $repo = Git->repository (Directory => $dir);
24 3         32460 my @these_revs;
25 3 100       32 if ( $files_arrayref ) {
26 1         41 @these_revs = $repo->command('rev-list', '--all', '--', join(" ", @$files_arrayref));
27             } else {
28 2         45 @these_revs = $repo->command('rev-list', '--all');
29             }
30 3         18538 my @commit_info;
31 3         43 for my $commit ( reverse @these_revs ) {
32 6         109 my $commit_info = $repo->command('show', '--pretty=fuller', $commit);
33 6         36611 my @files = ($commit_info =~ /\+\+\+\s+b\/(.+)/g);
34 6         87 my ($author) = ($commit_info =~ /Author:\s+(.+)/);
35 6         81 my ($commit) = ($commit_info =~ /Commit:\s+(.+)/);
36 6         46 my ($commit_date) = ($commit_info =~ /CommitDate:\s+(.+)/);
37 6         210 push @commit_info, { files => \@files,
38             author => $author,
39             commit => $commit,
40             commit_date => $commit_date};
41             }
42 3         81 my $commits = { _repo => $dir,
43             _name => $repo_name,
44             _commits => \@commit_info,
45             _hashes => \@these_revs};
46 3         221 return bless $commits, $class;
47              
48             }
49              
50             sub commits {
51 2     2 1 1251 my $self = shift;
52 2         16 return $self->{'_commits'};
53             }
54              
55             sub hashes {
56 2     2 1 2870 my $self = shift;
57 2         65 return $self->{'_hashes'};
58             }
59              
60             sub name {
61 2     2 1 156 my $self = shift;
62 2         91 return $self->{'_name'};
63             }
64            
65              
66             1; # Magic true value required at end of module
67             __END__
68              
69             =head1 NAME
70              
71             Git::Repo::Commits - Get all commits in a repository
72              
73              
74             =head1 VERSION
75              
76             This document describes Git::Repo::Commits version 0.0.7
77              
78              
79             =head1 SYNOPSIS
80              
81             use Git::Repo::Commits;
82              
83             my $commits = new Git::Repo::Commits /home/is/where/the/repo/is
84              
85            
86             =head1 DESCRIPTION
87              
88             =head2 new $repository
89              
90             Creates an object with information about all commits
91              
92             =head2 commits
93              
94             Returns an array with commit information, an array item per commit, in
95             the shape
96              
97             { author => $author,
98             committer => $committer,
99             commit_date => $date,
100             files => \@files }
101              
102             =head2 hashes
103              
104             Returns an array with the hashes of all commits in the repo.
105              
106             =head2 name
107              
108             Returns the name of the directory, which usually is also the name of the repo.
109              
110              
111             =head1 CONFIGURATION AND ENVIRONMENT
112              
113             Git::Repo::Commits requires no configuration files or environment
114             variables. It might be the case that git is not installed and this
115             fails, but probably not.
116              
117              
118             =head1 DEPENDENCIES
119              
120             Depends on L<Git>, which should be available either from your git
121             installation or from CPAN.
122              
123              
124             =head2 SEE ALSO
125              
126             L<Git::Raw> has an object oriented interface to repositories, including a class L<Git::Raw::Commit> to access commits.
127              
128             =head1 BUGS AND LIMITATIONS
129              
130             No bugs have been reported.
131              
132             Please report any bugs or feature requests to
133             C<bug-git-repo-commits@rt.cpan.org>, or through the web interface at
134             L<http://rt.cpan.org>, or, even better, at the
135             L<https://github.com/JJ/perl-git-commit/issues> in GitHub.
136              
137              
138             =head1 AUTHOR
139              
140             JJ C<< <JMERELO@cpan.org> >>
141              
142              
143             =head1 LICENCE AND COPYRIGHT
144              
145             Copyright (c) 2017, JJ C<< <JMERELO@cpan.org> >>. All rights reserved.
146              
147             This module is free software; you can redistribute it and/or
148             modify it under the same terms as Perl itself. See L<perlartistic>.
149              
150              
151             =head1 DISCLAIMER OF WARRANTY
152              
153             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
154             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
155             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
156             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
157             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
158             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
159             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
160             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
161             NECESSARY SERVICING, REPAIR, OR CORRECTION.
162              
163             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
164             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
165             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
166             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
167             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
168             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
169             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
170             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
171             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
172             SUCH DAMAGES.