lib/Git/Repo/Commits.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 100% 2 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 4 / 4 totaltotal 88.7% 55 / 62 SCAR 13.9
CC
4
Cov
91%
new
4.0
name
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Git/Repo/Commits.pm ↑ Summary
1 package Git::Repo::Commits;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use version; our $VERSION = qv('0.1.0'); # Work with a few files
Subroutine BEGIN: called CC=1 SCAR=0.0
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 2 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
20 2 ▶ my $dir = shift || croak "Need a repo directory";
Condition33%1/3
shift() || croak('Need a repo directory')
l!l&&r!l&&!r
200
MC/DC0%0/2
shift() || croak('Need a repo directory')
shift() croak('Need a repo directory')
Truth table33%1/3
A || B
A= shift()B= croak('Need a repo directory')
ABresult
1X1
011
000
21 2 my $files_arrayref = shift;
22 2 my ($repo_name) = ($dir =~ m{/([^/]+)/?$} );
23 2 my $repo = Git->repository (Directory => $dir);
24 2 my @these_revs;
25 2 ▶ if ( $files_arrayref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($files_arrayref) { } 1 1 2
26 1 @these_revs = $repo->command('rev-list', '--all', '--', join(" ", @$files_arrayref));
27 } else {
28 1 @these_revs = $repo->command('rev-list', '--all');
29 }
30 2 my @commit_info;
31 2 for my $commit ( reverse @these_revs ) {
32 4 my $commit_info = $repo->command('show', '--pretty=fuller', $commit);
33 4 my @files = ($commit_info =~ /\+\+\+\s+b\/(.+)/g);
34 4 my ($author) = ($commit_info =~ /Author:\s+(.+)/);
35 4 my ($commit) = ($commit_info =~ /Commit:\s+(.+)/);
36 4 my ($commit_date) = ($commit_info =~ /CommitDate:\s+(.+)/);
37 4 push @commit_info, { files => \@files,
38 author => $author,
39 commit => $commit,
40 commit_date => $commit_date};
41 }
42 2 my $commits = { _repo => $dir,
43 _name => $repo_name,
44 _commits => \@commit_info,
45 _hashes => \@these_revs};
46 2 return bless $commits, $class;
47  
48 }
49  
50 sub commits {
51 2 ▶ my $self = shift;
Subroutine commits: called CC=1 SCAR=0.0
Pod documented
52 2 return $self->{'_commits'};
53 }
54  
55 sub hashes {
56 2 ▶ my $self = shift;
Subroutine hashes: called CC=1 SCAR=0.0
Pod documented
57 2 return $self->{'_hashes'};
58 }
59  
60 sub name {
61 0 ▶ my $self = shift;
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
62 0 return $self->{'_name'};
63 }
64
65  
66 1 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.
« blib/lib/Git/Repo/Commits.pm ↑ Summary