| 1 | package App::KGB::Client::CVS; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = 1.23; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # vim: ts=4:sw=4:et:ai:sts=4 | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # KGB - an IRC bot helping collaboration -- CVS support | ||||||||||||||||||||||||||||
| 12 | # Copyright © 2012 Damyan Ivanov | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 15 | # the terms of the GNU General Public License as published by the Free Software | ||||||||||||||||||||||||||||
| 16 | # Foundation; either version 2 of the License, or (at your option) any later | ||||||||||||||||||||||||||||
| 17 | # version. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||||||||||||||||||
| 20 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||||||||||||||||||
| 21 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||||||||||||||||||||||||||||
| 22 | # details. | ||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | # You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||
| 25 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||||||||||||||||||||||||||||
| 26 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | App::KGB::Client::CVS - KGB interface to CVS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | use App::KGB::Client::CVS; | ||||||||||||||||||||||||||||
| 35 | my $client = App::KGB::Client::CVS( | ||||||||||||||||||||||||||||
| 36 | # common App::KGB::Client parameters | ||||||||||||||||||||||||||||
| 37 | repo_id => 'my-repo', | ||||||||||||||||||||||||||||
| 38 | ... | ||||||||||||||||||||||||||||
| 39 | # CVS-specific | ||||||||||||||||||||||||||||
| 40 | cvs_root => $ENV{CVSROOT}, | ||||||||||||||||||||||||||||
| 41 | author => $ENV{USER}, | ||||||||||||||||||||||||||||
| 42 | directory => 'module/dir', | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | $client->run; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | B<App::KGB::Client::CVS> provides CVS-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::CVS defines the following additional fields: | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =over | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item B<cvs_root> (B<mandatory>) | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Physical path to the CVS root directory. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =item B<author> | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | The user name of the commit author. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =item B<directory> | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Relative (to CVS root) path to the directory this change is in. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | As a convention, the first path member is taken as a module. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 METHODS | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =over | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =item describe_commit | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | The first time this method is called, it parses STDIN and determines commit | ||||||||||||||||||||||||||||
| 86 | contents, returning an instance of L<App::KGB::Commit> class describing the | ||||||||||||||||||||||||||||
| 87 | commit. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | All subsequential invocations return B<undef>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | require v5.10.0; | |||||||||||||||||||||||||||
| 96 | 1 | ▶ | use base 'App::KGB::Client'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | use App::KGB::Change; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | use App::KGB::Commit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | 1 | __PACKAGE__->mk_accessors(qw( _called author cvs_root directory )); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 104 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 105 | 0 | $self->_called(0); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | defined( $self->cvs_root ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | or confess "'cvs_root' is mandatory"; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | return $self; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | use Fcntl qw(:flock); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub describe_commit { | ||||||||||||||||||||||||||
|
Subroutine
describe_commit: not called CC=29 SCAR=67.7
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return undef if $self->_called; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my $merge_file = File::Spec->catfile( $self->cvs_root, 'CVSROOT', | |||||||||||||||||||||||||||
| 121 | sprintf( 'kgb-client-%d-%d.tmp', $<, getpgrp() ) ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | open(MERGE, ">>$merge_file") or die "Unable to open $merge_file: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $first_dir_in_commit = flock( MERGE, LOCK_EX | LOCK_NB ); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my ( $tag, $log, @changes ); | |||||||||||||||||||||||||||
| 128 | # the first element is module, the rest - directory path | ||||||||||||||||||||||||||||
| 129 | 0 | my ($module, $dir) = $self->directory =~ m{([^/]+)(/.+)?}; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | $dir //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dir //= ""
MC/DC0%0/1
$dir //= ""
$dir
Truth table0%0/2
A
A= $dir
| |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $dir .= '/' if $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | while ( defined( my $line = <> ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $tag = $1, next if $line =~ /^\s*Tag: ([a-zA-Z0-9_-]+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( $line =~ /^Added Files:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV)
$line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
| |||||||||||||||||||||||||||||
| 138 | 0 | my $files = $1; | |||||||||||||||||||||||||||
| 139 | push @changes, | ||||||||||||||||||||||||||||
| 140 | App::KGB::Change->new( | ||||||||||||||||||||||||||||
| 141 | { action => 'A', | ||||||||||||||||||||||||||||
| 142 | path => "$dir$_", | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | ) for split( /\s+/, $files ); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | redo; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( $line =~ /^Modified Files:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV)
$line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
| |||||||||||||||||||||||||||||
| 150 | 0 | my $files = $1; | |||||||||||||||||||||||||||
| 151 | push @changes, | ||||||||||||||||||||||||||||
| 152 | App::KGB::Change->new( | ||||||||||||||||||||||||||||
| 153 | { action => 'M', | ||||||||||||||||||||||||||||
| 154 | path => "$dir$_", | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 0 | ) for split( /\s+/, $files ); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 0 | redo; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $line =~ /^Removed Files:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV)
$line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
| |||||||||||||||||||||||||||||
| 162 | 0 | my $files = $1; | |||||||||||||||||||||||||||
| 163 | push @changes, | ||||||||||||||||||||||||||||
| 164 | App::KGB::Change->new( | ||||||||||||||||||||||||||||
| 165 | { action => 'D', | ||||||||||||||||||||||||||||
| 166 | path => "$dir$_", | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | ) for split( /\s+/, $files ); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | 0 | redo; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | last if $line =~ /^Log Message/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | while(defined(my $line = <>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | $log .= $line; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $root = $self->cvs_root; | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | $log =~ s{$root/}{} if $log; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | print MERGE "$_\n" for @changes; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | unless ($first_dir_in_commit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | close(MERGE); | |||||||||||||||||||||||||||
| 186 | 0 | return undef; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return if fork(); # parent process exits | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | #warn "$$ waiting\n"; | ||||||||||||||||||||||||||||
| 192 | # wait for the merge file to settle | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | while( time() - (stat(MERGE))[9] < 3 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | sleep(1); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | close(MERGE); | |||||||||||||||||||||||||||
| 198 | 0 | ▶ | open(MERGE, $merge_file) or die "Error reopening $merge_file: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | unlink $merge_file or warn "Error removing $merge_file: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | @changes = (); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | while ( defined( my $line = <MERGE> ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | chomp($line); | |||||||||||||||||||||||||||
| 205 | 0 | push @changes, App::KGB::Change->new($line); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | close(MERGE); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | $self->_called(1); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | return App::KGB::Commit->new( | |||||||||||||||||||||||||||
| 212 | { changes => \@changes, | ||||||||||||||||||||||||||||
| 213 | author => $self->author, | ||||||||||||||||||||||||||||
| 214 | author_name => $self->_get_full_user_name( $self->author ), | ||||||||||||||||||||||||||||
| 215 | log => $log, | ||||||||||||||||||||||||||||
| 216 | module => $module, | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 1 | 1; | |||||||||||||||||||||||||||