| 1 | package App::KGB::Client::Subversion; | ||
| 2 | 1 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | # vim: ts=4:sw=4:et:ai:sts=4 | ||
| 5 | # | ||
| 6 | # KGB - an IRC bot helping collaboration | ||
| 7 | # Copyright © 2008 Martina Ferrari | ||
| 8 | # Copyright © 2009,2010 Damyan Ivanov | ||
| 9 | # | ||
| 10 | # This program is free software; you can redistribute it and/or modify it under | ||
| 11 | # the terms of the GNU General Public License as published by the Free Software | ||
| 12 | # Foundation; either version 2 of the License, or (at your option) any later | ||
| 13 | # version. | ||
| 14 | # | ||
| 15 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 17 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 18 | # details. | ||
| 19 | # | ||
| 20 | # You should have received a copy of the GNU General Public License along with | ||
| 21 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
| 22 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 23 | |||
| 24 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | our $VERSION = 1.27; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | App::KGB::Client::Subversion - KGB interface to Subversion | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | use App::KGB::Client::Subversion; | ||
| 36 | my $client = App::KGB::Client::Subversion( | ||
| 37 | # common App::KGB::Client parameters | ||
| 38 | repo_id => 'my-repo', | ||
| 39 | ... | ||
| 40 | # Subversion-specific | ||
| 41 | repo_path => '/svn/project', | ||
| 42 | revision => 42, | ||
| 43 | ); | ||
| 44 | $client->run; | ||
| 45 | |||
| 46 | =head1 DESCRIPTION | ||
| 47 | |||
| 48 | B<App::KGB::Client::Subversion> provides Subversion-specific retrieval of | ||
| 49 | commits and changes for L<App::KGB::Client>. | ||
| 50 | |||
| 51 | =head1 CONSTRUCTOR | ||
| 52 | |||
| 53 | =head2 B<new> ( { initializers } ) | ||
| 54 | |||
| 55 | Standard constructor. Accepts inline hash with initial field values. | ||
| 56 | |||
| 57 | =head1 FIELDS | ||
| 58 | |||
| 59 | App:KGB::Client::Subversion defines two additional fields: | ||
| 60 | |||
| 61 | =over | ||
| 62 | |||
| 63 | =item B<repo_path> (B<mandatory>) | ||
| 64 | |||
| 65 | Physical path to Subversion repository. | ||
| 66 | |||
| 67 | =item B<revision> | ||
| 68 | |||
| 69 | The revision about which to notify. If omitted defaults to the last revision | ||
| 70 | of the repository. | ||
| 71 | |||
| 72 | =back | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =over | ||
| 77 | |||
| 78 | =item describe_commit | ||
| 79 | |||
| 80 | The first time this method is called, it retrieves commit number and repository | ||
| 81 | path from command-line parameters and returns an instance of | ||
| 82 | L<App::KGB::Commit> class describing the commit. | ||
| 83 | |||
| 84 | All subsequential invocations return B<undef>. | ||
| 85 | |||
| 86 | =back | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | require v5.10.0; | ||
| 91 | 1 | ▶ | use base 'App::KGB::Client'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 92 | 1 | ▶ | use App::KGB::Change; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 93 | 1 | ▶ | use App::KGB::Commit; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 94 | 1 | ▶ | use Carp qw(confess); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 95 | 0 | ▶ | use SVN::Core; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 96 | use SVN::Fs; | ||
| 97 | use SVN::Repos; | ||
| 98 | __PACKAGE__->mk_accessors(qw( _called repo_path revision )); | ||
| 99 | |||
| 100 | use constant rev_prefix => 'r'; | ||
| 101 | |||
| 102 | sub new { | ||
| 103 | my $class = shift; | ||
| 104 | my $self = $class->SUPER::new(@_); | ||
| 105 | $self->_called(0); | ||
| 106 | |||
| 107 | defined( $self->repo_path ) | ||
| 108 | or confess "'repo_path' is mandatory"; | ||
| 109 | |||
| 110 | return $self; | ||
| 111 | } | ||
| 112 | |||
| 113 | sub describe_commit { | ||
| 114 | my ($self) = @_; | ||
| 115 | |||
| 116 | return undef if $self->_called; | ||
| 117 | |||
| 118 | my ( $author, $log, @changes ); | ||
| 119 | |||
| 120 | # Shut up the perl compiler warnings | ||
| 121 | if ( $SVN::Fs::PathChange::modify | ||
| 122 | and $SVN::Fs::PathChange::add | ||
| 123 | and $SVN::Fs::PathChange::delete | ||
| 124 | and $SVN::Fs::PathChange::replace ) | ||
| 125 | { | ||
| 126 | } | ||
| 127 | |||
| 128 | my $repo = SVN::Repos::open( $self->repo_path ); | ||
| 129 | my $fs = $repo->fs or die $!; | ||
| 130 | |||
| 131 | $self->revision( $fs->youngest_rev ) unless defined( $self->revision ); | ||
| 132 | $log = $fs->revision_prop( $self->revision, "svn:log" ); | ||
| 133 | $author = $fs->revision_prop( $self->revision, "svn:author" ); | ||
| 134 | |||
| 135 | my $root = $fs->revision_root( $self->revision ); | ||
| 136 | my $changed = $root->paths_changed(); | ||
| 137 | foreach ( keys %$changed ) { | ||
| 138 | my $k = $changed->{$_}->change_kind(); | ||
| 139 | if ( $k == $SVN::Fs::PathChange::modify ) { | ||
| 140 | $k = "M"; | ||
| 141 | } | ||
| 142 | elsif ( $k == $SVN::Fs::PathChange::add ) { | ||
| 143 | $k = "A"; | ||
| 144 | } | ||
| 145 | elsif ( $k == $SVN::Fs::PathChange::delete ) { | ||
| 146 | $k = "D"; | ||
| 147 | } | ||
| 148 | elsif ( $k == $SVN::Fs::PathChange::replace ) { | ||
| 149 | $k = "R"; | ||
| 150 | } | ||
| 151 | |||
| 152 | my $pm = $changed->{$_}->prop_mod(); | ||
| 153 | |||
| 154 | push @changes, | ||
| 155 | App::KGB::Change->new( | ||
| 156 | { action => $k, | ||
| 157 | prop_change => $pm, | ||
| 158 | path => $_, | ||
| 159 | } | ||
| 160 | ); | ||
| 161 | } | ||
| 162 | |||
| 163 | $self->_called(1); | ||
| 164 | |||
| 165 | return App::KGB::Commit->new( | ||
| 166 | { id => $self->revision, | ||
| 167 | changes => \@changes, | ||
| 168 | author => $author, | ||
| 169 | author_name => $self->_get_full_user_name($author), | ||
| 170 | log => $log, | ||
| 171 | } | ||
| 172 | ); | ||
| 173 | } | ||
| 174 | |||
| 175 | 1; | ||