blib/lib/VCS/LibCVS/Datum/Entry.pm

filter: Statementstmt 26.9% 17 / 63 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 31.2% 5 / 16 Podpod 100% 9 / 9 totaltotal 27.1% 31 / 114 CC 14 SCAR 36.9
CC
14
Cov
19%
new
110.0
get_tag
6.0
get_updated_time
6.0
CRAP 40.2
« blib/lib/VCS/LibCVS/Client/Connection/Pserver.pm ↑ Summary blib/lib/VCS/LibCVS/WorkingFile.pm »
1 #
2 # Copyright (c) 2003,2004,2005 Alexander Taler (dissent@0--0.org)
3 #
4 # All rights reserved. This program is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6 #
7  
8 package VCS::LibCVS::Datum::Entry;
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 VCS::LibCVS::Datum::Entry - A CVS datum for an RCS Entries Line
17  
18 =head1 SYNOPSIS
19  
20 $string = VCS::LibCVS::Datum::Entry->new("/Client.pm/1.14/Mon Dec 16 16:49:16 2002//");
21  
22 =head1 DESCRIPTION
23  
24 An RCS style Entries Line:
25  
26 / NAME / VERSION / CONFLICT / OPTIONS / TAG_OR_DATE
27  
28 This format is used in two places. The CVS/Entries file, and in data returned
29 by the server. The format can be slightly different in each of these cases.
30  
31 In particular, the server can return a CONFLICT of "+=" when a new conflict is
32 being reported, but this shouldn't be stored in the Entries file. Instead a
33 proper timestamp should be used.
34  
35 =head1 SUPERCLASS
36  
37 VCS::LibCVS::Datum
38  
39 =cut
40  
41 ###############################################################################
42 # Class constants
43 ###############################################################################
44  
45 1 ▶use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Datum/Entry.pm,v 1.19 2005/10/10 12:52:11 dissent Exp $ ';
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 1 ▶use vars ('@ISA');
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 @ISA = ("VCS::LibCVS::Datum");
49  
50 ###############################################################################
51 # Class variables
52 ###############################################################################
53  
54 ###############################################################################
55 # Private variables
56 ###############################################################################
57  
58 # $self->{Entry} the full entry line
59 # $self->{Type} the type of the entry, "Directory" or "File"
60 # $self->{FileName} the name of the file to which this entry refers
61 # $self->{Revision} the revision of the file
62 # $self->{Conflict} conflict info
63 # $self->{Merge} "No", "Merge" or "Conflict": if CVS merged the file
64 # $self->{Date} from conflict info. When CVS last changed the file
65 # in seconds since the epoch
66 # $self->{Options} any sticky options
67 # $self->{Tag} the sticky tag of the file
68  
69 ###############################################################################
70 # Class routines
71 ###############################################################################
72  
73 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
74 0 my $class = shift;
75 0 my $that = $class->SUPER::new(@_);
76  
77 0 ▶ if ($that->{Entry} =~ m|^D/([^/]+)////$|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($that->{'Entry'} =~ m[^D/([^/]+)////$]) { } 0 0 0
elsif ($that->{'Entry'} =~ m[^/([^/]+)/([-0-9.]+)/([^/]*)/([^/]*)/([^/]*)$]) { } 0 0 0
78 0 $that->{Type} = "Directory";
79 0 $that->{FileName} = $1;
80 } elsif ($that->{Entry} =~ m|^/([^/]+)/([-0-9.]+)/([^/]*)/([^/]*)/([^/]*)$|) {
81 0 $that->{Type} = "File";
82 0 $that->{FileName} = $1;
83 0 $that->{Revision} = $2;
84 0 $that->{Conflict} = $3;
85 0 $that->{Merge} = "No"; # default value
86 0 $that->{Date} = 0; # default value
87 0 $that->{Options} = $4;
88 0 $that->{Tag} = $5;
89  
90 # The Conflict field can look like this:
91 # // (empty) if the entry is being transmitted from the server
92 # /Initial <filename>/ if it's a newly added file
93 # /Result of merge/ if the file was merged without conflicts
94 # /Result of merge+Sun Apr 6 02:47:18 2003/ for conflicts on merge
95 # /+=/ for conflicts on merge, returned by server. (Date is same as file)
96 # /Sun Apr 6 02:24:57 2003/ to indicate when CVS made it up to date
97  
98 0 ▶ if ($that->{Conflict} =~ /^$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($that->{'Conflict'} =~ /^$/) { } 0 0 0
elsif ($that->{'Conflict'} =~ /^Initial .*$/) { } 0 0 0
elsif ($that->{'Conflict'} =~ /^Result of merge$/) { } 0 0 0
elsif ($that->{'Conflict'} =~ /^\+=$/) { } 0 0 0
elsif ($that->{'Conflict'} =~ /^Result of merge\+(.*)$/) { } 0 0 0
elsif ($that->{'Conflict'} =~ /^(.*)$/) { } 0 0 0
99 } elsif ($that->{Conflict} =~ /^Initial .*$/) {
100 confess "Initial $that->{FileName} has non-0 revision"
101 0 ▶ unless $that->{Revision} eq "0";
Branch: 1 branch
BranchTrueFalseTotal
unless $that->{"Revision"} eq 0 0 0 0
102 } elsif ($that->{Conflict} =~ /^Result of merge$/) {
103 0 $that->{Merge} = "Merge";
104 } elsif ($that->{Conflict} =~ /^\+=$/) {
105 0 $that->{Merge} = "Conflict";
106 } elsif ($that->{Conflict} =~ /^Result of merge\+(.*)$/) {
107 0 $that->{Merge} = "Conflict";
108 0 $that->{Date} = _date_to_secs($1);
109 } elsif ($that->{Conflict} =~ /^(.*)$/) {
110 0 $that->{Date} = _date_to_secs($1);
111 }
112  
113 } else {
114 0 confess "Badly formatted entry line: " . $that->{Entry};
115 }
116  
117 0 return $that;
118 }
119  
120 ###############################################################################
121 # Instance routines
122 ###############################################################################
123  
124 =head1 INSTANCE ROUTINES
125  
126 =head2 B<name()>
127  
128 $entry_name = $entry->name()
129  
130 =over 4
131  
132 =item return type: scalar string
133  
134 =back
135  
136 Returns the name of file to which the entry refers.
137  
138 =cut
139  
140 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
141 0 my $self = shift;
142 0 return $self->{FileName};
143 }
144  
145 =head2 B<get_tag()>
146  
147 $tag = $entry->get_tag()
148  
149 =over 4
150  
151 =item return type: VCS::LibCVS::Datum::TagSpec
152  
153 =back
154  
155 Returns the tagspec for this entry, or undef if there's no tag.
156  
157 =cut
158  
159 0 ▶sub get_tag {
Subroutine get_tag: not called CC=2 SCAR=17.9
Pod documented
160 0 my $self = shift;
161 0 ▶ return undef unless $self->{Tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Tag"} 0 0 0
162 0 return VCS::LibCVS::Datum::TagSpec->new($self->{Tag});
163 }
164  
165 =head2 B<get_revision()>
166  
167 $revision = $entry->get_revision()
168  
169 =over 4
170  
171 =item return type: VCS::LibCVS::Datum::RevisionNumber
172  
173 =back
174  
175 Returns the revision number of this entry
176  
177 =cut
178  
179 0 ▶sub get_revision {
Subroutine get_revision: not called CC=1 SCAR=6.9
Pod documented
180 0 my $self = shift;
181 # Remove the optional preceding '-', indicating scheduling for removal
182 0 my ($rev) = ($self->{Revision} =~ /^-?(.*)/);
183 0 return VCS::LibCVS::Datum::RevisionNumber->new($rev);
184 }
185  
186 =head2 B<is_file()>
187  
188 if ($entry->is_file()) {
189  
190 =over 4
191  
192 =item return type: boolean scalar
193  
194 =back
195  
196 Returns true if the entry represents a file
197  
198 =cut
199  
200 0 ▶sub is_file {
Subroutine is_file: not called CC=1 SCAR=6.9
Pod documented
201 0 my $self = shift;
202 0 return $self->{Type} eq "File";
203 }
204  
205 =head2 B<is_directory()>
206  
207 if ($entry->is_directory()) {
208  
209 =over 4
210  
211 =item return type: boolean scalar
212  
213 =back
214  
215 Returns true if the entry represents a directory
216  
217 =cut
218  
219 0 ▶sub is_directory {
Subroutine is_directory: not called CC=1 SCAR=6.9
Pod documented
220 0 my $self = shift;
221 0 return $self->{Type} eq "Directory";
222 }
223  
224 =head2 B<get_updated_time()>
225  
226 $date = $entry->get_updated_time()
227  
228 =over 4
229  
230 =item return type: time in seconds since the epoch
231  
232 =back
233  
234 Returns the time that this file was last made up-to-date by CVS. This is used
235 for checking if files are modified. If the file modification time is less than
236 or equal to this time, then the file has not been modified.
237  
238 If the file is the result of a merge, then no date is available, and 0 is
239 returned.
240  
241 =cut
242  
243 0 ▶sub get_updated_time {
Subroutine get_updated_time: not called CC=2 SCAR=17.9
Pod documented
244 0 my $self = shift;
245  
246 # if $self->{Merge} is other than "No" ("Merge" or "Conflict") then CVS did
247 # not bring the file up-to-date on the last update, since it had to merge
248 # changes. So, just return 0 to show the file is modified. Otherwise,
249 # return the date.
250  
251 0 ▶ return ($self->{Merge} eq "No") ? $self->{Date} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Merge'} eq 'No' ? : 0 0 0
252 }
253  
254 =head2 B<get_conflict_time()>
255  
256 $date = $entry->get_conflict_time()
257  
258 =over 4
259  
260 =item return type: time in seconds since the epoch
261  
262 =back
263  
264 Returns the time that conflict information was inserted into this file by CVS.
265 This is used for checking if conflicts have been resolved. If the file
266 modification time is less than or equal to this time, then the file has
267 unresolved conflicts in it.
268  
269 If the file did not have conflicts inserted into it, 0 is returned.
270  
271 If this is a new conflict being reported, and the file has not yet been written
272 to disk, there is no time, so undef is returned. This happens in Entry lines
273 being returned from the server.
274  
275 =cut
276  
277 0 ▶sub get_conflict_time {
Subroutine get_conflict_time: not called CC=2 SCAR=17.9
Pod documented
278 0 my $self = shift;
279  
280 # if $self->{Merge} is other than "Conflict" (either "Merge" or "No") then no
281 # conflicts have been inserted into this file. So, just return 0 to show
282 # there are no conflicts. Otherwise, return the date.
283  
284 0 ▶ return ($self->{Merge} eq "Conflict") ? $self->{Date} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Merge'} eq 'Conflict' ? : 0 0 0
285 }
286  
287 =head2 B<is_conflict()>
288  
289 if ( $entry->is_conflict() ) . . .
290  
291 =over 4
292  
293 =item return type: boolean
294  
295 =back
296  
297 Return true if this Entry is for a file with a conflict. This can ba a file on
298 disk with a conflict written into it. Or one being returned from the server.
299  
300 =cut
301  
302 0 ▶sub is_conflict {
Subroutine is_conflict: not called CC=1 SCAR=6.9
Pod documented
303 0 my $self = shift;
304  
305 0 return ($self->{Merge} eq "Conflict");
306 }
307  
308  
309 ###############################################################################
310 # Private routines
311 ###############################################################################
312  
313 0 ▶sub _data_names { return ("Entry"); }
Subroutine _data_names: not called CC=1 SCAR=6.9
314  
315 # Convert the annoying string date to seconds since the epoch
316 # Sun Apr 6 02:24:57 2003
317 0 ▶sub _date_to_secs {
Subroutine _date_to_secs: not called CC=2 SCAR=17.9
318 0 my $date = shift;
319 0 ▶ confess "Unexpected date format: $date"
Branch: 1 branch
BranchTrueFalseTotal
unless $date =~ /^\w{3} (\w{3}) ?(\d{1,2}) (\d\d):(\d\d):(\d\d) (\d{4})/ 0 0 0
320 unless $date =~ /^\w{3} (\w{3}) ?(\d{1,2}) (\d\d):(\d\d):(\d\d) (\d{4})/;
321 0 my ($month, $day, $hour, $minute, $second, $year) = ($1, $2, $3, $4, $5, $6);
322  
323 $month = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3,
324 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7,
325 0 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}->{$month};
326 0 return timegm($second, $minute, $hour, $day, $month, $year);
327 }
328  
329 =head1 SEE ALSO
330  
331 VCS::LibCVS::Datum
332  
333 =cut
334  
335 1 1;
« blib/lib/VCS/LibCVS/Client/Connection/Pserver.pm ↑ Summary blib/lib/VCS/LibCVS/WorkingFile.pm »