PVCS/Archive.pm untested

filter: Statementstmt 0.0% 0 / 179 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 47 Subroutinesub 0.0% 0 / 36 Podpod 0.0% 0 / 28 totaltotal 0.0% 0 / 403 CC 18 SCAR 26.6
CC
18
Cov
0%
new
72.0
vdiff
12.0
get
6.0
CRAP 14.3
1 # Archive.pm - access to PVCS Archives for the Perl PVCS module
2 #
3 # Copyright (c) 1998 Bill Middleton
4 #
5  
6 =head1 NAME
7  
8 VCS::PVCS::Archive - Archive class for for VCS::PVCS.
9  
10  
11 =head1 SYNOPSIS
12  
13 use VCS::PVCS::Project;
14  
15 $project = new VCS::PVCS::Project("ProjectName");
16  
17 # return ref to array of all folders in the project with SCRIPTS in the name
18  
19 $folds = $project->openFolders("SCRIPTS");
20 foreach $folder (@$folds){
21 @archives = $folder->Members(); # array of blessed Archive objects
22 foreach $archive(@archives){
23 $archive->checkout; # Checkout single archive to folder's WD
24 }
25 }
26  
27 =head1 DESCRIPTION
28  
29 This class provides methods for use by Archive objects in the
30 PVCS model.
31  
32 Ordinarily, this class won't be included in your programs,
33 as it is part of the ISA for the master class VCS::PVCS::Project,
34 which should ordinarily be used, as shown above.
35  
36  
37 =head1 METHODS
38  
39 =over 5
40  
41 =item B<new>
42  
43 VCS::PVCS::Archive::new(archivedir,
44 workdir,workfile,"checkin comment","workfile comment");
45  
46 Open an existing archive or create a new one.
47  
48 =item B<workfile>
49  
50 $workfile = $Archive->Workfile;
51  
52 Return the default workfile for this archive object. Use opts to
53 change default actions.
54  
55 =item B<get>
56  
57 $Archive->get([get opts]);
58  
59 Checkout the archive to the CWD. Use opts to change default
60 actions.
61  
62 =item B<checkout>
63  
64 Convenience routine calls get()
65  
66 =item B<co>
67  
68 Convenience routine calls get()
69  
70 =item B<put>
71  
72 $Archive->put([put opts]);
73  
74 Checkin the workfile in CWD to archive. Use opts to change default
75 actions.
76  
77 =item B<checkin>
78  
79 Convenience routine calls put()
80  
81 =item B<ci>
82  
83 Convenience routine calls put()
84  
85 =item B<vdiff>
86  
87 $Archive->vdiff([vdiff opts]);
88  
89 Takes a diff on the archive and workfile. Use opts to change default
90 actions.
91  
92 =item B<vlog>
93  
94 $Archive->vlog([vlog opts]);
95  
96 Takes a full vlog on the archive. Use opts to change default
97 actions.
98  
99 =item B<log>
100  
101 Convenience routine calls vlog()
102  
103 =item B<history>
104  
105 Convenience routine calls vlog()
106  
107 =item B<lock>
108  
109 $Archive->lock($label|$version,[vcs opts]);
110  
111 Locks the named revision (or rev spec'd by label). Use opts
112 to change default action.
113  
114 =item B<unlock>
115  
116 $Archive->unlock($label|$version,[vcs opts]);
117  
118 unlocks the named revision (or rev spec'd by label). Use opts
119 to change default action.
120  
121 =item B<addVersionLabel>
122  
123 $Archive->addVersionLabel($label,[vcs opts]);
124  
125 Create a new sticky version label for the archive (optionally with :<rev>.
126  
127 =item B<deleteVersionLabel>
128  
129 $Archive->deleteVersionLabel($label,[vcs opts]);
130  
131 Delete a version label from the archive.
132  
133 =item B<replaceVersionLabel>
134  
135 $Archive->replaceVersionLabel($newlabel,$oldlabel,[vcs opts]);
136  
137 Rename a version label in the archive
138  
139 =item B<addFloatingVersionLabel>
140  
141 $Archive->addFloatingVersionLabel($label,[vcs opts]);
142  
143 Create a floating version label for the archive.
144  
145 =item B<transformVersionLabel>
146  
147 $Archive->transformVersionLabel($label,[vcs opts])';
148  
149 Transform a specified version label to a floating version label.
150  
151 =item B<deletePromoGroup>
152  
153 $Archive->deletePromoGroup($group,[vcs opts]);
154  
155 Delete the promotion group from the archive.
156  
157 =item B<addPromoGroup>
158  
159 $Archive->deletePromoGroup($group:$rev,[vcs opts])';
160  
161 Add the archive, or promote it to, the named promotion group.
162  
163 Create a new archive
164  
165 =item B<vcs>
166  
167 $archive->vcs([opts][files]);
168  
169 Runs the VCS command against the archive, with opts as specified.
170  
171 =item B<getAttributes>
172  
173 $archive->getAttributes(@_);
174  
175 Populates and returns the archive object associated with the archive.
176 This object is blessed into the VCS::PVCS::Attributes class.
177  
178 =item B<attributes>
179  
180 $archive->attributes;
181  
182 Returns the attributes object associated with the archive
183  
184 =back
185  
186 =head1 COPYRIGHT
187  
188 The PVCS module is Copyright (c) 1998 Bill Middleton.
189 All rights reserved.
190  
191 You may distribute under the terms of either the GNU General Public
192 License or the Artistic License, as specified in the Perl README file.
193  
194 =head1 AUTHOR
195  
196 Bill Middleton, wjm@metronet.com
197  
198 =head1 SUPPORT / WARRANTY
199  
200 The VCS::PVCS modules are free software.
201  
202 B<THEY COME WITHOUT WARRANTY OF ANY KIND.>
203  
204 Commercial support agreements for Perl can be arranged via
205 The Perl Clinic. See http://www.perl.co.uk/tpc for more details.
206  
207 =head1 SEE ALSO
208  
209 VCS::PVCS::Project
210  
211 =cut
212  
213 package VCS::PVCS::Archive;
214 use strict;
215 no strict qw(refs);
216 use vars qw($VERSION @EXPORT @EXPORT_OK @ISA);
217 use Carp;
218 use Cwd;
219 use VCS::PVCS;
220 use VCS::PVCS::Commands;
221 require VCS::PVCS::Attributes;
222 @ISA = qw(VCS::PVCS::Commands VCS::PVCS::Attributes);
223 $VERSION = "0.01";
224  
225  
226 ################################################
227 ## Constructor
228 ################################################
229 sub new{
230 @_ == 5 or croak 'usage: VCS::PVCS::Archive::new(archivedir,workdir,workfile,"checkin comment","workfile comment")';
231 my($workfile,$arpath,$workdir,$cicomment,$workfilecomment)=@_;
232 my(@args,$output,$newarchive);
233 my($new) = {};
234 my($tmpdir) = cwd;
235  
236 # Check things for sanity
237 if(! (-d $arpath)){
238 print "ls is ".`ls $arpath`;
239 croak "archivepath $arpath is not a directory\n";
240
241 }
242 if(! (-d $workdir)){
243 croak "workingdir $workdir is not a directory\n";
244 }
245  
246 chdir($workdir) or croak "Cant change dir to $workdir\n";
247  
248 if(! -e "$workfile"){
249 croak "workfile $workdir/$workfile does not exist!\n";
250 }
251  
252 if($^O !~ "^MSWin32"){
253 @args = ("-U", "-M\"$cicomment\"", "-T\"$workfilecomment\"","$arpath\\($workfile\\)");
254 }
255 else{
256 @args = ( "-N","-U","-M\"$cicomment\"", "-T\"$workfilecomment\"","$arpath($workfile)");
257 }
258  
259 VCS::PVCS::Commands::put(@args);
260  
261 if(!$PVCSERR){
262 $output = $PVCSOUTPUT;
263 $output =~ /$workfile\s+->\s+([^\r\n]+)/;
264 $newarchive = $1;
265 if((! -e "$newarchive") && (! $PVCSSHOWMODE)){
266 croak "Something went wrong creating $arpath\($workfile\)\n";
267 }
268 }
269 else{
270 return undef;
271 }
272  
273 if($PVCSMULTIPLATFORM){
274 ($^O ne "MSWin32") and translatePath2Win(\$newarchive);
275 ($^O ne "MSWin32") and translatePath2Win(\$workfile);
276 ($^O ne "MSWin32") and translatePath2Win(\$workdir);
277 }
278  
279 $new->{'arpath'} = $newarchive;
280 $new->{'workfiles'}->{'MASTER'} = ".\\$workfile";
281 bless($new,"VCS::PVCS::Archive");
282 chdir($tmpdir);
283 return $new;
284 }
285
286  
287 ################################################
288 ## Member access methods
289 ################################################
290  
291 sub Archive{
292 my($self) = shift;
293 return $self->{'arpath'};
294 }
295 sub archive{
296 my($self) = shift;
297 return $self->{'arpath'};
298 }
299 sub workfile{
300 my($self) = shift;
301 return $self->{'workfiles'}->{'MASTER'};
302 }
303 sub Workfile{
304 my($self) = shift;
305 return $self->{'workfiles'}->{'MASTER'};
306 }
307  
308  
309  
310 ##############################################################################
311 # Archive Checkout methods
312 ##############################################################################
313  
314 sub get{
315 @_ >= 1 or croak 'usage: $Archive->get([get opts])';
316 my($type) = shift;
317 my($class) = ref($type);
318  
319 if($class eq "VCS::PVCS::Archive"){
320 (caller =~ /VCS::PVCS::(Folder|Archive)/) or ($PVCSOUTPUT = "");
321 my($archive) = $type->archive();
322 ($^O ne "MSWin32") and translatePath2Unix(\$archive);
323 return VCS::PVCS::Commands::get(@_,$archive);
324 }
325 else{
326 croak "Must invoke Archive::get passing archive object";
327 }
328  
329 }
330  
331 sub checkout{
332 get(@_);
333 }
334  
335 sub co{
336 get(@_);
337 }
338  
339 ##############################################################################
340 # Checkin methods
341 ##############################################################################
342  
343 sub put{
344 @_ >= 1 or croak 'usage: $Archive->put([get opts])';
345 my($type) = shift;
346 my($class) = ref($type);
347  
348 if($class eq "VCS::PVCS::Archive"){
349 (caller =~ /VCS::PVCS::(Folder|Archive)/) or ($PVCSOUTPUT = "");
350 my($archive) = $type->archive();
351 ($^O ne "MSWin32") and translatePath2Unix(\$archive);
352 return VCS::PVCS::Commands::put(@_,$archive);
353 }
354 else{
355 croak "Must invoke Archive::put passing archive object";
356 }
357  
358 }
359  
360 sub checkin{
361 put(@_);
362 }
363  
364 sub ci{
365 put(@_);
366 }
367  
368 ##############################################################################
369 # diff method
370 ##############################################################################
371 sub vdiff{
372 @_ >= 1 or croak 'usage: $Archive->vdiff([vlog opts])';
373 my($type) = shift;
374 my($class) = ref($type);
375  
376 # The default here is to diff the workfile against the tip
377 # if we have additional arguments, then assume only the archive
378  
379 if($class eq "VCS::PVCS::Archive"){
380 (caller =~ /VCS::PVCS::(Folder|Archive)/) or ($PVCSOUTPUT = "");
381 my($archive) = $type->archive();
382 my($workfile) = $type->workfile();
383 ($^O ne "MSWin32") and translatePath2Unix(\$archive);
384 ($^O ne "MSWin32") and translatePath2Unix(\$workfile);
385 if(@_ == 0){
386 return VCS::PVCS::Commands::vdiff(@_,$workfile,$archive);
387 }
388 else{
389 return VCS::PVCS::Commands::vdiff(@_,$archive);
390 }
391 }
392 else{
393 croak "Must invoke Archive::vdiff passing archive object";
394 }
395 }
396 ##############################################################################
397 # history methods
398 ##############################################################################
399 sub vlog{
400 @_ >= 1 or croak 'usage: $Archive->vlog([vlog opts])';
401 my($type) = shift;
402 my($class) = ref($type);
403  
404 if($class eq "VCS::PVCS::Archive"){
405 (caller =~ /VCS::PVCS::(Folder|Archive)/) or ($PVCSOUTPUT = "");
406 my($archive) = $type->archive();
407 ($^O ne "MSWin32") and translatePath2Unix(\$archive);
408 return VCS::PVCS::Commands::vlog(@_,$archive);
409 }
410 else{
411 croak "Must invoke Archive::vlog passing archive object";
412 }
413 }
414  
415 sub log{
416 vlog(@_);
417 }
418  
419 sub history{
420 vlog(@_);
421 }
422  
423 ######################################################################
424 # locking methods
425 ######################################################################
426  
427 sub lock{
428 @_ >= 2 or croak 'usage: $Archive->lock($label|$version,[vcs opts])';
429 my($type) = shift;
430 my($tmptype) = $VCS::PVCS::Commands::vcsopts->{'L'};
431 my($version) = shift;
432  
433 $VCS::PVCS::Commands::vcsopts->{'L'} = $version;
434 vcs($type,@_);
435 $VCS::PVCS::Commands::vcsopts->{'L'} = $tmptype;
436  
437 }
438  
439 sub unlock{
440 @_ >= 2 or croak 'usage: $Archive->unlock($label|$version,[vcs opts])';
441 my($type) = shift;
442 my($tmptype) = $VCS::PVCS::Commands::vcsopts->{'U'};
443 my($version) = shift;
444  
445 $VCS::PVCS::Commands::vcsopts->{'U'} = $version;
446 vcs($type,@_);
447 $VCS::PVCS::Commands::vcsopts->{'U'} = $tmptype;
448  
449 }
450  
451 ######################################################################
452 # Version label methods
453 ######################################################################
454 sub addVersionLabel{
455 @_ >= 2 or croak 'usage: $Archive->addVersionLabel($label,[vcs opts])';
456 my($type) = shift;
457 my($label) = shift;
458  
459 vcs($type,@_,"-V$label");
460 }
461  
462 sub deleteVersionLabel{
463 @_ >= 2 or croak 'usage: $Archive->deleteVersionLabel($label,[vcs opts])';
464 my($type) = shift;
465 my($label) = shift;
466  
467 ($label .= ":delete") unless ($label =~ /:delete$/);
468 vcs($type,@_,"-V$label");
469 }
470  
471 sub replaceVersionLabel{
472 @_ >= 3 or croak 'usage: $Archive->replaceVersionLabel($newlabel,$oldlabel,[vcs opts])';
473 my($type) = shift;
474 my($newlabel) = shift;
475 my($oldlabel) = shift;
476  
477 vcs($type,@_,"-V$newlabel\:\:$oldlabel");
478 }
479  
480 sub addFloatingVersionLabel{
481 @_ >= 2 or croak 'usage: $Archive->addFloatingVersionLabel($label,[vcs opts])';
482 my($type) = shift;
483 my($label) = shift;
484  
485 ($label .= ":\*") unless ($label =~ /:\*$/);
486 vcs($type,@_,"-V$label");
487 }
488  
489 sub transformVersionLabel{
490 @_ >= 2 or croak 'usage: $Archive->transformVersionLabel($label,[vcs opts])';
491 my($type) = shift;
492 my($label) = shift;
493  
494 ($label .= ":\\*") unless ($label =~ /:\*$/);
495 vcs($type,@_,"-V$label","-Y");
496 }
497  
498 ######################################################################
499 # Promotion group methods
500 ######################################################################
501  
502 sub deletePromoGroup{
503 @_ >= 2 or croak 'usage: $Archive->deletePromoGroup($group,[vcs opts])';
504 my($type) = shift;
505 my($label) = shift;
506  
507 ($label .= ":delete") unless ($label =~ /:delete$/);
508 vcs($type,@_,"-G$label");
509  
510 }
511  
512 sub addPromoGroup{
513 @_ >= 2 or croak 'usage: $Archive->deletePromoGroup($group:$rev,[vcs opts])';
514 my($type) = shift;
515 my($label) = shift;
516  
517 vcs($type,@_,"-G$label");
518 }
519  
520 sub createArchive{
521 @_ >= 2 or croak 'usage: $Folder->createArchive($archive,[vcs opts])';
522 my($type) = shift;
523 my($class) = ref($type);
524  
525 vcs($type,@_,"-I");
526 }
527  
528  
529 ##########################################################################
530 # The all-seeing, all-knowing VCS utility command
531 ##########################################################################
532 sub vcs{
533 @_ >= 1 or croak 'usage: vcs([opts][files])';
534 my($type) = shift;
535 my($class) = ref($type);
536 my($member);
537 if($class eq "VCS::PVCS::Archive"){
538 (caller =~ /VCS::PVCS::(Folder|Archive)/) or ($PVCSOUTPUT = "");
539 my($archive) = $type->archive();
540 ($^O ne "MSWin32") and translatePath2Unix(\$archive);
541 return VCS::PVCS::Commands::vcs(@_,$archive);
542 }
543 else{
544 croak "Must invoke Archive::vcs passing archive object";
545 }
546  
547 }
548  
549 sub getAttributes{
550 return VCS::PVCS::Attributes::getAttributes(@_);
551 }
552  
553 sub attributes{
554 my($self) = shift;
555 return $self->{'Attributes'};
556 }
557  
558 1;
559 __END__