blib/lib/VCS/LibCVS/FileRevision.pm

filter: Statementstmt 13.1% 10 / 76 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 15.7% 3 / 19 Podpod 100% 14 / 14 totaltotal 20.6% 27 / 131 CC 12 SCAR 21.9
CC
12
Cov
10%
get_contents
30.0
get_successor
12.0
new
6.0
CRAP 8.9
« blib/lib/VCS/LibCVS/Datum/FileMode.pm ↑ Summary blib/lib/VCS/LibCVS/Client/Connection.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::FileRevision;
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  
13 =head1 NAME
14  
15 VCS::LibCVS::FileRevision - A specific revision of a file managed by CVS.
16  
17 =head1 SYNOPSIS
18  
19 =head1 DESCRIPTION
20  
21 Represents a single revision of a file managed by CVS.
22  
23 =cut
24  
25 ###############################################################################
26 # Class constants
27 ###############################################################################
28  
29 1 ▶use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/FileRevision.pm,v 1.25 2005/10/10 12:52:11 dissent Exp $ ';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 ###############################################################################
32 # Class variables
33 ###############################################################################
34  
35 ###############################################################################
36 # Private variables
37 ###############################################################################
38  
39 # $self->{BranchNumber} VCS::LibCVS::Datum::RevisionNumber
40 # The Branch revision number is stored in order to determine the
41 # predecessor correctly. This is necessary since a revision is
42 # exists on all branches which sprout from it, as well as the
43 # one to which it was first committed. eg. revision 1.2 is on
44 # branch 1, as well as branch 1.2.2.
45 # $self->{File} VCS::LibCVS::RepositoryFile of this revision
46 # $self->{LogMessage} VCS::LibCVS::Datum::LogMessage (fetched on demand)
47 # $self->{RevisionNumber} VCS::LibCVS::Datum::RevisionNumber
48  
49 ###############################################################################
50 # Class routines
51 ###############################################################################
52  
53 =head1 CLASS ROUTINES
54  
55 =head2 B<new()>
56  
57 $file_rev = VCS::LibCVS::FileRevision->new($file, $revision, $branch_rev)
58  
59 =over 4
60  
61 =item return type: VCS::LibCVS::FileRevision
62  
63 =item argument 1 type: VCS::LibCVS::RepositoryFile
64  
65 =item argument 2 type: VCS::LibCVS::Datum::RevisionNumber
66  
67 =item argument 3 type: optional VCS::LibCVS::Datum::RevisionNumber
68  
69 =back
70  
71 The revision number of the branch of this revision can be optionally specified.
72 If it's not, its revision number without the last field is used as the branch
73 number. It is needed to correctly determine this revision's successor.
74  
75 =cut
76  
77 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
78 0 my $class = shift;
79 0 my ($file, $revision, $branch) = @_;
80 0 my $that = bless {}, $class;
81  
82 0 $that->{File} = $file;
83 0 $that->{RevisionNumber} = $revision;
84 0 ▶ if (! defined $branch) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $branch) 0 0 0
85 0 $branch = $revision->branch_of();
86 }
87 0 $that->{BranchNumber} = $branch;
88  
89 0 return $that;
90 }
91  
92 ###############################################################################
93 # Instance routines
94 ###############################################################################
95  
96 =head1 INSTANCE ROUTINES
97  
98 =head2 B<get_revision_number()>
99  
100 $file = $file_rev->get_revision_number()
101  
102 =over 4
103  
104 =item return type: VCS::LibCVS::Datum::RevisionNumber
105  
106 =back
107  
108 =cut
109  
110 0 ▶sub get_revision_number {
Subroutine get_revision_number: not called CC=1 SCAR=6.9
Pod documented
111 0 return shift->{RevisionNumber};
112 }
113  
114 =head2 B<get_file()>
115  
116 $file = $file_rev->get_file()
117  
118 =over 4
119  
120 =item return type: VCS::LibCVS::RepositoryFile
121  
122 =back
123  
124 =cut
125  
126 0 ▶sub get_file {
Subroutine get_file: not called CC=1 SCAR=6.9
Pod documented
127 0 return shift->{File};
128 }
129  
130 =head2 B<get_file_branch()>
131  
132 $file_branch = $file_rev->get_branch()
133  
134 =over 4
135  
136 =item return type: VCS::LibCVS::FileBranch
137  
138 =back
139  
140 =cut
141  
142 0 ▶sub get_file_branch {
Subroutine get_file_branch: not called CC=1 SCAR=6.9
Pod documented
143 0 my $self = shift;
144 0 return $self->{File}->get_branch($self->{RevisionNumber}->branch_of());
145 }
146  
147 =head2 B<get_log_message()>
148  
149 $message = $file_rev->get_log_message()
150  
151 =over 4
152  
153 =item return type: scalar string
154  
155 =back
156  
157 Returns the text of the log message for the commit that resulted in this
158 revision.
159  
160 =cut
161  
162 0 ▶sub get_log_message {
Subroutine get_log_message: not called CC=1 SCAR=6.9
Pod documented
163 0 return shift->_get_log_message()->get_text();
164 }
165  
166 =head2 B<get_committer()>
167  
168 $committer = $file_rev->get_committer()
169  
170 =over 4
171  
172 =item return type: scalar string
173  
174 =back
175  
176 Returns the logname of whoever committed this particular revision.
177  
178 =cut
179  
180 0 ▶sub get_committer {
Subroutine get_committer: not called CC=1 SCAR=6.9
Pod documented
181 0 return shift->_get_log_message()->{Author};
182 }
183  
184 =head2 B<get_time()>
185  
186 $time = $file_rev->get_time()
187  
188 =over 4
189  
190 =item return type: scalar number
191  
192 =back
193  
194 Returns the time that this particular revision was committed, as seconds since
195 midnight January 1 1970.
196  
197 =cut
198  
199 0 ▶sub get_time {
Subroutine get_time: not called CC=1 SCAR=6.9
Pod documented
200 0 my $self = shift;
201  
202 0 return VCS::LibCVS::parse_date($self->_get_log_message()->{Date});
203 }
204  
205 =head2 B<get_time_string()>
206  
207 $time_str = $file_rev->get_time_string()
208  
209 =over 4
210  
211 =item return type: scalar string
212  
213 =back
214  
215 Returns the time that this particular revision was committed, as the formatted
216 string returned by CVS.
217  
218 =cut
219  
220 0 ▶sub get_time_string {
Subroutine get_time_string: not called CC=1 SCAR=6.9
Pod documented
221 0 return shift->_get_log_message()->{Date};
222 }
223  
224 =head2 B<is_dead()>
225  
226 if ($file_rev->is_dead()) { . . .
227  
228 =over 4
229  
230 =item return type: scalar boolean
231  
232 =back
233  
234 Returns true if and only if this revision is marked dead.
235  
236 =cut
237  
238 0 ▶sub is_dead {
Subroutine is_dead: not called CC=1 SCAR=6.9
Pod documented
239 0 return shift->_get_log_message()->{State} eq "dead";
240 }
241  
242 =head2 B<get_contents()>
243  
244 $data = $file_rev->get_contents()
245  
246 =over 4
247  
248 =item return type: VCS::LibCVS::Datum::FileContents
249  
250 =back
251  
252 Returns the contents of the particular revision.
253  
254 =cut
255  
256 # This function could use stdout mode ("-p") to avoid getting all the entries
257 # and stuff, but it would then receive the file as a series of "M" messages.
258 # This format of output worries me.
259  
260 0 ▶sub get_contents {
Subroutine get_contents: not called CC=5 SCAR=34.0
Pod documented
261 0 my $self = shift;
262  
263 # Check if the file contents have been cached
264 0 my ($cache, $c_key);
265 0 ▶ if ($VCS::LibCVS::Cache_FileRevision_Contents_by_Repository) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VCS::LibCVS::Cache_FileRevision_Contents_by_Repository) 0 0 0
266 0 $cache = $self->get_file->get_repository->{FileRevisionContentsCache};
267 0 $c_key = $self->get_file->get_name.":".$self->{RevisionNumber}->as_string;
268 0 ▶ return ($cache->{$c_key}) if ($cache->{$c_key});
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$c_key} 0 0 0
269 }
270  
271 # Specify which revision to get the contents of
272 0 my $arg = [ "-r" . $self->{RevisionNumber}->as_string() ];
273  
274 # Generate and issue the command
275 0 my $command = VCS::LibCVS::Command->new({},"update",$arg, [$self->get_file]);
276 0 $command->issue($self->get_file()->get_repository());
277  
278 # The file is returned in an Updated response, as a FileContents Datum
279 0 my @resps = $command->get_responses("VCS::LibCVS::Client::Response::Updated");
280 0 ▶ confess "Not 1 Updated for " . $self->get_file->get_name unless (@resps == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @resps == 1 0 0 0
281  
282 # Cache and return the results
283 0 ▶ if ($VCS::LibCVS::Cache_FileRevision_Contents_by_Repository) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VCS::LibCVS::Cache_FileRevision_Contents_by_Repository) 0 0 0
284 0 ($cache->{$c_key}) = $resps[0]->data()->[3];
285 }
286 0 return $resps[0]->data()->[3];
287 }
288  
289 =head2 B<get_predecessor()>
290  
291 $pre_file_rev = $file_rev->get_predecessor()
292  
293 =over 4
294  
295 =item return type: VCS::LibCVS::FileRevision
296  
297 =back
298  
299 Returns the file revision that was right before this one, it's youngest
300 ancestor. Return undef if it has no predecessor.
301  
302 =cut
303  
304 0 ▶sub get_predecessor {
Subroutine get_predecessor: not called CC=2 SCAR=17.9
Pod documented
305 0 my $self = shift;
306 0 my $pre_rev = $self->{RevisionNumber}->get_predecessor();
307 0 ▶ if ( defined $pre_rev) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pre_rev) { } 0 0 0
308 0 return VCS::LibCVS::FileRevision->new($self->{File}, $pre_rev);
309 } else {
310 0 return;
311 }
312 }
313  
314 =head2 B<get_successor()>
315  
316 $next_file_rev = $file_rev->get_successor()
317  
318 =over 4
319  
320 =item return type: VCS::LibCVS::FileRevision
321  
322 =back
323  
324 Returns the file revision on the same branch that comes right after this one,
325 it's oldest descendant. Return undef if it has no successor.
326  
327 XXXBUG: If a revision has been deleted, this will break.
328  
329 =cut
330  
331 0 ▶sub get_successor {
Subroutine get_successor: not called CC=3 SCAR=24.8
Pod documented
332 0 my $self = shift;
333  
334 # First determine the successor revision number. If this revision is on a
335 # branch which sprouts from it, then its successor's revision number has two
336 # extra fields, and can't be determined directly from
337 # Datum::RevisionNumber->get_successor(), so handle that case differently.
338  
339 0 my $suc_rev_num;
340 0 ▶ if ($self->{BranchNumber}->equals($self->{RevisionNumber}->branch_of())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'BranchNumber'}->equals($self->{'RevisionNumber'}->branch_of)) { } 0 0 0
341 0 $suc_rev_num = $self->{RevisionNumber}->get_successor();
342 } else {
343 0 $suc_rev_num = $self->{BranchNumber}->first_revision_of();
344 }
345  
346 0 ▶ if (defined $self->{File}->_get_log_messages()->{$suc_rev_num->as_string()}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'File'}->_get_log_messages->{$suc_rev_num->as_string}) { } 0 0 0
347 0 return VCS::LibCVS::FileRevision->new($self->{File}, $suc_rev_num);
348 } else {
349 0 return;
350 }
351 }
352  
353 =head2 B<compare()>
354  
355 $cmp = $file_rev1->compare($file_rev2)
356  
357 =over 4
358  
359 =item return type: integer, one of VCS::LibCVS::Datum::RevisionNumber::COMPARE_*
360  
361 =item argument 1 type: VCS::LibCVS::FileRevision
362  
363 =back
364  
365 Compares this file revision with the argument.
366  
367 The meanings of the return values are:
368  
369 =over 4
370  
371 =item COMPARE_EQUAL
372  
373 They are the same revision.
374  
375 =item COMPARE_ANCESTOR
376  
377 The argument is an ancestor of this.
378  
379 =item COMPARE_DESCENDANT
380  
381 The argument is a descendant of this.
382  
383 =item COMPARE_INCOMPARABLE
384  
385 The argument is neither an ancestor, nor a descendant of this, and they aren't
386 equal.
387  
388 =back
389  
390 If they are FileRevisions of different files an exception is thrown.
391  
392 See VCS::LibCVS::Datum::RevisionNumber for more information about the
393 comparison of revisions.
394  
395 =cut
396  
397 0 ▶sub compare {
Subroutine compare: not called CC=2 SCAR=17.9
Pod documented
398 0 my $self = shift;
399 0 my $other = shift;
400  
401 0 ▶ if (! $self->{File}->equals($other->{File})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"File"}->equals($other->{"File"})) 0 0 0
402 0 confess "Can only compare revisions of the same file";
403 }
404 0 return $self->{RevisionNumber}->compare($other->{RevisionNumber});
405 }
406  
407 =head2 B<equals()>
408  
409 if ($frev1->equals($frev2)) {
410  
411 =over 4
412  
413 =item return type: boolean
414  
415 =item argument 1 type: VCS::LibCVS::FileRevision
416  
417 =back
418  
419 Returns true if this and the other FileRevision are the same.
420  
421 The same revision can be on multiple branches, so the branch it's on is not
422 compared.
423  
424 =cut
425  
426 0 ▶sub equals {
Subroutine equals: not called CC=2 SCAR=17.9
Pod documented
427 0 my $self = shift;
428 0 my $other = shift;
429  
430 0 ▶ if (! $self->{File}->equals($other->{File})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"File"}->equals($other->{"File"})) 0 0 0
431 0 confess "Can only compare revisions of the same file";
432 }
433 0 return $self->{RevisionNumber}->equals($other->{RevisionNumber});
434 }
435  
436 ###############################################################################
437 # Private routines
438 ###############################################################################
439  
440 # get the Datum::LogMessage object for this particular file revision the
441 # difference between this and get_log_message is the return type. I don't
442 # think it's appropriate for the external API to return a Datum::LogMessage
443 # object.
444  
445 0 ▶sub _get_log_message {
Subroutine _get_log_message: not called CC=2 SCAR=17.9
446 0 my $self = shift;
447 0 ▶ if (!defined $self->{LogMessage}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"LogMessage"}) 0 0 0
448 0 my $rev_num_str = $self->{RevisionNumber}->as_string();
449 0 $self->{LogMessage} = $self->{File}->_get_log_messages()->{$rev_num_str};
450 }
451 0 return $self->{LogMessage};
452 }
453  
454 # Returns an Entry, like from the Entries file for this FileRevision.
455  
456 0 ▶sub _get_entry {
Subroutine _get_entry: not called CC=1 SCAR=6.9
457 0 my $self = shift;
458 0 my $name = $self->{File}->get_name({'no_dir' => 1});
459 0 my $revnum = $self->{RevisionNumber}->as_string();
460 0 my $date = "Wed Jan 31 02:14:08 1973";
461 0 return VCS::LibCVS::Datum::Entry->new("/$name/$revnum/$date//");
462 }
463  
464 =head1 SEE ALSO
465  
466 VCS::LibCVS
467  
468 =cut
469  
470 1 1;
« blib/lib/VCS/LibCVS/Datum/FileMode.pm ↑ Summary blib/lib/VCS/LibCVS/Client/Connection.pm »