ShipIt/VC/SVN.pm

filter: Statementstmt 28.2% 22 / 78 Branchbran 16.6% 4 / 24 Conditioncond 28.5% 2 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 38.4% 5 / 13 Podpod 62.5% 5 / 8 totaltotal 29.1% 39 / 134 CC 18 SCAR 29.8
CC
18
Cov
26%
exists_tagged_version
42.0
commit
42.0
tag_version
12.0
CRAP 19.7
« ShipIt/Util.pm ↑ Summary ShipIt/Step/FindVersion.pm »
1 package ShipIt::VC::SVN;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use base 'ShipIt::VC';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶sub command { 'svn' }
Subroutine command: not called CC=1 SCAR=6.9
Pod undocumented
7  
8 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
9 0 my ($class, $conf) = @_;
10 0 my $self = bless {}, $class;
11 0 $self->{tagpattern} = $conf->value( $self->command . ".tagpattern" );
12  
13 0 my $command = $self->command;
14 0 ▶ my $url = $self->find_url
Branch: 1 branch
BranchTrueFalseTotal
my $url = $self->find_url or die "Failed to run $command, or this isn't an $command working copy" 0 0 0
15 or die "Failed to run $command, or this isn't an $command working copy";
16 0 $self->{url} = $url;
17  
18 0 $self->{dir_exists} = {}; # url -> 1 (url exists, learned from svn ls)
19 0 $self->{dir_listed} = {}; # url -> 1 (have we do svn ls on url?)
20 0 return $self;
21 }
22  
23 0 ▶sub find_url {
Subroutine find_url: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my $self = shift;
25 0 my $info = `svn info`;
26 0 ($info =~ /^URL: (.+)/m)[0];
27 }
28  
29 =head1 NAME
30  
31 ShipIt::VC::SVN -- ShipIt's subversion support
32  
33 =head1 CONFIGURATION
34  
35 In your .shipit configuration file, the following options are recognized:
36  
37 =over
38  
39 =item B<svn.tagpattern>
40  
41 A pattern which ultimately expands into the absolute subversion URL for a tagged version. If the pattern isn't already absolute, the conventional "tags" directory is used as a base. The pattern has one magic variable, %v, which expands to the version number being tagged. If no %v is found, it's placed at the end.
42  
43 Example legit values:
44  
45 =over 8
46  
47 =item http://example.com/svn/tags/MyProject-%v
48  
49 =item MyProject-%v
50  
51 Both the above are equivalent.
52  
53 =item (nothing)
54  
55 Will automatically add %v to the end (of nothing), then auto-find your
56 'tags' URL, resulting in a final URL of:
57  
58 http://example.com/svn/tags/%v
59  
60 If your svn repo hosts more than one project, this default URL could
61 be bad, as the tagged directory has no project name in it.
62  
63 =back
64  
65 =back
66  
67 =cut
68  
69 0 ▶sub exists_tagged_version {
Subroutine exists_tagged_version: not called CC=6 SCAR=37.4
Pod documented
70 0 my ($self, $ver) = @_;
71  
72 0 my $command = $self->command;
73 0 my $url = $self->_tag_url_of_version($ver);
74 0 ▶ die "bogus chars in $command url" if $url =~ /[ \`\&\;]/;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ /[ \`\&\;]/ 0 0 0
75  
76 0 my $tag_base = $url;
77 0 ▶ $tag_base =~ s!/[^/]+$!! or die;
Branch: 1 branch
BranchTrueFalseTotal
$tag_base =~ s[/[^/]+$][] or die 0 0 0
78 0 ▶ unless ($self->{dir_listed}{$tag_base}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir_listed"}{$tag_base}++) 0 0 0
79 0 foreach my $f (`$command ls $tag_base`) {
80 0 chomp $f;
81 0 $self->{dir_exists}{"$tag_base/$f"} = 1;
82 }
83 }
84  
85 0 ▶ return $self->{dir_exists}{$url} || $self->{dir_exists}{"$url/"};
Condition0%0/3
$self->{'dir_exists'}{$url} || $self->{'dir_exists'}{"$url/"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'dir_exists'}{$url} || $self->{'dir_exists'}{"$url/"}
$self->{'dir_exists'}{$url} $self->{'dir_exists'}{"$url/"}
Truth table0%0/3
A || B
A= $self->{'dir_exists'}{$url}B= $self->{'dir_exists'}{"$url/"}
ABresult
1X1
011
000
86 }
87  
88 # returns tag url of a given version, with no trailing slash
89 4 ▶sub _tag_url_of_version {
Subroutine _tag_url_of_version: called CC=4 SCAR=13.9
90 4 my ($self, $ver) = @_;
91 4 ▶ my $url = $self->{tagpattern} || '';
Condition100%2/2
$self->{'tagpattern'} || ''
l!l
31
MC/DC100%1/1
$self->{'tagpattern'} || ''
$self->{'tagpattern'}
Truth table100%2/2
A
A= $self->{'tagpattern'}
Aresult
11
00
92 4 ▶ unless ($url =~ m!^[\w\+]+://!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url =~ m[^[\w\+]+://]) 3 1 4
93 3 $url = $self->_tag_base . $url;
94 }
95 4 ▶ $url .= "%v" unless $url =~ /\%v/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ /\%v/i 1 3 4
96 4 $url =~ s/\%v/$ver/ig;
97 4 $url =~ s!/+$!!;
98 4 return $url;
99 }
100  
101 4 ▶sub _tag_base {
Subroutine _tag_base: called CC=1 SCAR=0.0
102 4 my ($self) = @_;
103 4 my $url = $self->{url};
104 4 $url =~ s!/trunk.*!/tags/!;
105 4 return $url;
106 }
107  
108 0 ▶sub commit {
Subroutine commit: not called CC=6 SCAR=37.4
Pod documented
109 0 my ($self, $msg) = @_;
110  
111 0 my $command = $self->command;
112  
113 # any locally-added files not in svn?
114 0 my $unk;
115 0 my $changed = 0;
116 0 foreach (`$command st`) {
117 0 $changed++;
118 0 ▶ next unless /^\?/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^\?/ 0 0 0
119 0 $unk .= $_;
120 }
121 0 ▶ if ($unk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unk) 0 0 0
122 0 die "Unknown local files:\n$unk\n\nUpdate $command:ignore with:\n\t$command pe svn:ignore .\n";
123 0 exit(1);
124 }
125  
126 0 ▶ unless ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($changed) 0 0 0
127 0 warn "No locally changed files, skipping commit\n";
128 0 return;
129 }
130  
131 # commit
132 0 my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg');
133 0 print $tmp_fh $msg;
134 0 my $tmp_fn = "$tmp_fh";
135 0 ▶ system($command, "ci", "--file", $tmp_fn) and die "Commit failed.\n";
Branch: 1 branch
BranchTrueFalseTotal
system $command, "ci", "--file", $tmp_fn and die "Commit failed.\n" 0 0 0
136 }
137  
138 0 ▶sub local_diff {
Subroutine local_diff: not called CC=1 SCAR=6.9
Pod documented
139 0 my ($self, $file) = @_;
140 0 my $command = $self->command;
141 0 return `$command diff $file`;
142 }
143  
144 0 ▶sub tag_version {
Subroutine tag_version: not called CC=3 SCAR=24.8
Pod documented
145 0 my ($self, $ver, $msg) = @_;
146 0 ▶ $msg ||= "Tagging version $ver.\n";
Condition0%0/2
$msg ||= "Tagging version $ver.\n"
l!l
00
MC/DC0%0/1
$msg ||= "Tagging version $ver.\n"
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
147 0 my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg');
148 0 print $tmp_fh $msg;
149 0 my $tmp_fn = "$tmp_fh";
150 0 my $tag_url = $self->_tag_url_of_version($ver);
151 0 ▶ system($self->command, "copy", "--file", $tmp_fn, $self->{url}, $tag_url)
Branch: 1 branch
BranchTrueFalseTotal
system $self->command, "copy", "--file", $tmp_fn, $self->{"url"}, $tag_url and die "Tagging of version '${ver}' failed.\n" 0 0 0
152 and die "Tagging of version '$ver' failed.\n";
153 }
154  
155 0 ▶sub are_local_diffs {
Subroutine are_local_diffs: not called CC=2 SCAR=17.9
Pod documented
156 0 my ($self) = @_;
157 0 my $command = $self->command;
158 0 my $diff = `$command diff`;
159 0 ▶ return $diff =~ /\S/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$diff =~ /\S/ ? : 0 0 0
160 }
161  
162 2 1;
163  
164  
« ShipIt/Util.pm ↑ Summary ShipIt/Step/FindVersion.pm »