| 1 | package VCS::Which::Plugin::Bazaar; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # Created on: 2009-05-16 16:58:36 | ||||||||||||||||||||||||||||||||
| 4 | # Create by: ivan | ||||||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use version; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use File::chdir; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Contextual::Return; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | extends 'VCS::Which::Plugin'; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = version->new('0.6.9'); | |||||||||||||||||||||||||||||||
| 23 | 2 | our $name = 'Bazaar'; | |||||||||||||||||||||||||||||||
| 24 | 2 | our $exe = 'bzr'; | |||||||||||||||||||||||||||||||
| 25 | 2 | our $meta = '.bzr'; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub installed { | ||||||||||||||||||||||||||||||
|
Subroutine
installed: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | return $self->_installed if defined $self->_installed; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 1 | for my $path (split /[:;]/, $ENV{PATH}) { | |||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | next if !-x "$path/$exe"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | return $self->_installed( 1 ); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 1 | return $self->_installed( 0 ); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 21 | ▶ | sub used { | ||||||||||||||||||||||||||||||
|
Subroutine
used: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 21 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 21 | ▶ | if (-f $dir) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | $dir = path($dir)->parent; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 21 | ▶ | croak "$dir is not a directory!" if !-d $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 20 | my $current_dir = path($dir)->absolute; | |||||||||||||||||||||||||||||||
| 51 | 20 | my $level = 1; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 20 | ▶ | while ($current_dir) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 131 | ▶ | if ( -d "$current_dir/$meta" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 0 | $self->_base( $current_dir ); | |||||||||||||||||||||||||||||||
| 56 | 0 | return $level; | |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 131 | $level++; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | # check that we still have a parent directory | ||||||||||||||||||||||||||||||||
| 62 | 131 | ▶ | last if $current_dir eq $current_dir->parent; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 111 | $current_dir = $current_dir->parent; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 20 | return 0; | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub uptodate { | ||||||||||||||||||||||||||||||
|
Subroutine
uptodate: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 71 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $dir ||= $self->_base; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dir ||= $self->_base
MC/DC0%0/2
$dir ||= $self->_base
$dir
$self->_base
Truth table0%0/3
A ||= B
A= $dirB= $self->_base
| |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | croak "'$dir' is not a directory!" if !-e $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | local $CWD = $dir; | |||||||||||||||||||||||||||||||
| 78 | 0 | my $ans = `$exe status`; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return $ans ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub pull { | ||||||||||||||||||||||||||||||
|
Subroutine
pull: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 84 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $dir ||= $self->_base; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dir ||= $self->_base
MC/DC0%0/2
$dir ||= $self->_base
$dir
$self->_base
Truth table0%0/3
A ||= B
A= $dirB= $self->_base
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | croak "'$dir' is not a directory!" if !-e $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | local $CWD = $dir; | |||||||||||||||||||||||||||||||
| 91 | 0 | return !system "$exe pull > /dev/null 2> /dev/null"; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub cat { | ||||||||||||||||||||||||||||||
|
Subroutine
cat: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $file, $revision) = @_; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( $revision && $revision =~ /^-\d+$/xms ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$revision and $revision =~ /^-\d+$/msx
MC/DC0%0/2
$revision and $revision =~ /^-\d+$/msx
$revision
$revision =~ /^-\d+$/msx
Truth table0%0/3
A and B
A= $revisionB= $revision =~ /^-\d+$/msx
| |||||||||||||||||||||||||||||||||
| 98 | 0 | my @versions = reverse `$exe log -q $file` =~ /^ revno: \s+ (\d+)/gxms; | |||||||||||||||||||||||||||||||
| 99 | 0 | $revision = $versions[$revision]; | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | elsif ( !defined $revision ) { | ||||||||||||||||||||||||||||||||
| 102 | 0 | $revision = ''; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $revision &&= "-r$revision"; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$revision &&= "-r$revision"
MC/DC0%0/1
$revision &&= "-r$revision"
$revision
Truth table0%0/2
A
A= $revision
| |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | return `$exe cat $revision $file`; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 0 | my $args = join ' ', map {"'$_'"} @args; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | return | ||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | SCALAR { scalar `$exe log $args` } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | ARRAYREF { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 118 | 0 | my @raw_log = `$exe log $args`; | |||||||||||||||||||||||||||||||
| 119 | 0 | my @log; | |||||||||||||||||||||||||||||||
| 120 | 0 | my $line = ''; | |||||||||||||||||||||||||||||||
| 121 | 0 | for my $raw (@raw_log) { | |||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $raw eq ( '-' x 60 ) . "\n" && $line ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$raw eq "------------------------------------------------------------\n" and $line
MC/DC0%0/2
$raw eq "------------------------------------------------------------\n" and $line
$raw eq "------------------------------------------------------------\n"
$line
Truth table0%0/3
A and B
A= $raw eq "------------------------------------------------------------\n"B= $line
| |||||||||||||||||||||||||||||||||
| 123 | 0 | CORE::push @log, $line; | |||||||||||||||||||||||||||||||
| 124 | 0 | $line = ''; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | elsif ( $raw ne ( '-' x 60 ) . "\n" ) { | ||||||||||||||||||||||||||||||||
| 127 | 0 | $line .= $raw; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | 0 | return \@log; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | HASHREF { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 134 | 0 | my $logs = `$exe log $args`; | |||||||||||||||||||||||||||||||
| 135 | 0 | my @logs = split /^-+\n/xms, $logs; | |||||||||||||||||||||||||||||||
| 136 | 0 | shift @logs; | |||||||||||||||||||||||||||||||
| 137 | 0 | my $num = @logs; | |||||||||||||||||||||||||||||||
| 138 | 0 | my %log; | |||||||||||||||||||||||||||||||
| 139 | 0 | for my $log (@logs) { | |||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | next if $log =~ /--include-merges/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | 0 | my ($details, $description) = $log =~ /^(.*)\nmessage:\s*(.*)$/xms; | |||||||||||||||||||||||||||||||
| 142 | 0 | $description =~ s/\s+\Z//xms; | |||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (!defined $details) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | 0 | warn "Error in reading line:\n$log\n"; | |||||||||||||||||||||||||||||||
| 145 | 0 | next; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | 0 | my %details = map {split /:\s+/, $_, 2} split /\n/, $details, 5; | |||||||||||||||||||||||||||||||
| 148 | $log{$num--} = { | ||||||||||||||||||||||||||||||||
| 149 | rev => $details{revno}, | ||||||||||||||||||||||||||||||||
| 150 | Author => $details{committer}, | ||||||||||||||||||||||||||||||||
| 151 | Date => $details{timestamp}, | ||||||||||||||||||||||||||||||||
| 152 | 0 | description => $description, | |||||||||||||||||||||||||||||||
| 153 | }, | ||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | 0 | return \%log; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | 0 | } | |||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 2 | 1; | |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||||||