| 1 | package Git::Repo::Commits; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use Carp; | ||
| 6 | use Git; | ||
| 7 | |||
| 8 | use version; our $VERSION = qv('0.1.0'); # Work with a few files | ||
| 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 | my $class = shift; | ||
| 20 | my $dir = shift || croak "Need a repo directory"; | ||
| 21 | my $files_arrayref = shift; | ||
| 22 | my ($repo_name) = ($dir =~ m{/([^/]+)/?$} ); | ||
| 23 | my $repo = Git->repository (Directory => $dir); | ||
| 24 | my @these_revs; | ||
| 25 | if ( $files_arrayref ) { | ||
| 26 | @these_revs = $repo->command('rev-list', '--all', '--', join(" ", @$files_arrayref)); | ||
| 27 | } else { | ||
| 28 | @these_revs = $repo->command('rev-list', '--all'); | ||
| 29 | } | ||
| 30 | my @commit_info; | ||
| 31 | for my $commit ( reverse @these_revs ) { | ||
| 32 | my $commit_info = $repo->command('show', '--pretty=fuller', $commit); | ||
| 33 | my @files = ($commit_info =~ /\+\+\+\s+b\/(.+)/g); | ||
| 34 | my ($author) = ($commit_info =~ /Author:\s+(.+)/); | ||
| 35 | my ($commit) = ($commit_info =~ /Commit:\s+(.+)/); | ||
| 36 | my ($commit_date) = ($commit_info =~ /CommitDate:\s+(.+)/); | ||
| 37 | push @commit_info, { files => \@files, | ||
| 38 | author => $author, | ||
| 39 | commit => $commit, | ||
| 40 | commit_date => $commit_date}; | ||
| 41 | } | ||
| 42 | my $commits = { _repo => $dir, | ||
| 43 | _name => $repo_name, | ||
| 44 | _commits => \@commit_info, | ||
| 45 | _hashes => \@these_revs}; | ||
| 46 | return bless $commits, $class; | ||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | sub commits { | ||
| 51 | my $self = shift; | ||
| 52 | return $self->{'_commits'}; | ||
| 53 | } | ||
| 54 | |||
| 55 | sub hashes { | ||
| 56 | my $self = shift; | ||
| 57 | return $self->{'_hashes'}; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub name { | ||
| 61 | my $self = shift; | ||
| 62 | 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. |