| 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::DirectoryBranch; | ||||||||||||||||||||||
| 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::DirectoryBranch - A CVS managed directory, viewed from a branch. | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | Represents a directory managed by CVS, viewed from a specific branch. | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | When getting the files in the directory, only those on that branch will be | ||||||||||||||||||||||
| 24 | considered. | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | ############################################################################### | ||||||||||||||||||||||
| 29 | # Class constants | ||||||||||||||||||||||
| 30 | ############################################################################### | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/DirectoryBranch.pm,v 1.11 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | ############################################################################### | ||||||||||||||||||||||
| 35 | # Class variables | ||||||||||||||||||||||
| 36 | ############################################################################### | ||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | ############################################################################### | ||||||||||||||||||||||
| 39 | # Private variables | ||||||||||||||||||||||
| 40 | ############################################################################### | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | # $self->{Directory} VCS::LibCVS::RepositoryDirectory | ||||||||||||||||||||||
| 43 | # $self->{TagSpec} VCS::LibCVS::Datum::TagSpec of the Branch | ||||||||||||||||||||||
| 44 | # For the main branch/trunk its value is undef | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | ############################################################################### | ||||||||||||||||||||||
| 47 | # Class routines | ||||||||||||||||||||||
| 48 | ############################################################################### | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | =head1 CLASS ROUTINES | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | =head2 B<new()> | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | $dir_branch = VCS::LibCVS::DirectoryBranch->new($dir, $tag_spec) | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | =over 4 | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | =item return type: VCS::LibCVS::DirectoryBranch | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | =item argument 1 type: VCS::LibCVS::RepositoryDirectory | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | =item argument 2 type: VCS::LibCVS::Datum::TagSpec | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | =back | ||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||
| 69 | 0 | my $class = shift; | |||||||||||||||||||||
| 70 | 0 | my $that = bless {}, $class; | |||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 0 | ($that->{Directory}, $that->{TagSpec}) = @_; | |||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 0 | ▶ | if ($that->{TagSpec}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 75 | 0 | my $tag_type = $that->{TagSpec}->get_type(); | |||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | # If it's a branch tag, everything is fine | ||||||||||||||||||||||
| 78 | 0 | ▶ | if ($tag_type eq VCS::LibCVS::Datum::TagSpec::TYPE_BRANCH) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | # If it's a date tag, then it's on the trunk, so make it undef | ||||||||||||||||||||||
| 81 | elsif ($tag_type eq VCS::LibCVS::Datum::TagSpec::TYPE_DATE) { | ||||||||||||||||||||||
| 82 | 0 | delete($that->{TagSpec}); | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||
| 84 | # If it's a non-branch tag, guess the branch tag from one of the files | ||||||||||||||||||||||
| 85 | elsif ($tag_type eq VCS::LibCVS::Datum::TagSpec::TYPE_NONBRANCH) { | ||||||||||||||||||||||
| 86 | 0 | confess "This code is broken. See Issue 35"; | |||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||
| 88 | # Revision sticky tags for directories are unlikely to correspond to a | ||||||||||||||||||||||
| 89 | # single branch for all files in that directory, so throw an exception. | ||||||||||||||||||||||
| 90 | elsif ($tag_type eq VCS::LibCVS::Datum::TagSpec::TYPE_REVISION) { | ||||||||||||||||||||||
| 91 | 0 | confess "Cannot create a DirectoryBranch with a revision sticky tag."; | |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||
| 94 | 0 | return $that; | |||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | ############################################################################### | ||||||||||||||||||||||
| 98 | # Instance routines | ||||||||||||||||||||||
| 99 | ############################################################################### | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | =head1 INSTANCE ROUTINES | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | =head2 B<get_directory()> | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | $dir = $dir_branch->get_directory() | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | =over 4 | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | =item return type: VCS::LibCVS::RepositoryDirectory | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | =back | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | 0 | ▶ | sub get_directory() { | ||||||||||||||||||||
|
Subroutine
get_directory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 116 | 0 | return shift->{Directory}; | |||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | =head2 B<get_tag()> | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | $tag = $dir_branch->get_tag() | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =over 4 | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | =item return type: VCS::LibCVS::Datum::TagSpec | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | =back | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | 0 | ▶ | sub get_tag() { | ||||||||||||||||||||
|
Subroutine
get_tag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 132 | 0 | return shift->{TagSpec}; | |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | =head2 B<get_file_branches()> | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | $file_bs = $dir_branch->get_file_branches() | ||||||||||||||||||||||
| 138 | |||||||||||||||||||||||
| 139 | =over 4 | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | =item return type: ref to hash of string -> VCS::LibCVS::FileBranch | ||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | Keys are the names of the files without directory specified | ||||||||||||||||||||||
| 144 | Values are VCS::LibCVS::FileBranch objects | ||||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | =back | ||||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | For each file in this directory, on this branch, return a FileBranch object. | ||||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | It doesn't include files whose tip revision on this branch is dead. | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||
| 153 | |||||||||||||||||||||||
| 154 | 0 | ▶ | sub get_file_branches { | ||||||||||||||||||||
|
Subroutine
get_file_branches: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 155 | 0 | my $self = shift; | |||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | # To get the list of files, just do a "cvs up -r" | ||||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | # Since only one directory is specified with a Directory request, there is no | ||||||||||||||||||||||
| 160 | # need to submit a "-l" argument to avoid recursion. | ||||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | # Specify the tag, or no tag for the trunk | ||||||||||||||||||||||
| 163 | 0 | my $tag_spec = $self->{TagSpec}; | |||||||||||||||||||||
| 164 | 0 | ▶ | my $tag_arg = (defined $tag_spec) ? [ "-r" . $tag_spec->get_name() ] : []; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 165 | 0 | my $dir = $self->get_directory(); | |||||||||||||||||||||
| 166 | 0 | my $command = VCS::LibCVS::Command->new({}, "update", $tag_arg, [$dir]); | |||||||||||||||||||||
| 167 | |||||||||||||||||||||||
| 168 | 0 | $command->issue($self->get_directory->get_repository()); | |||||||||||||||||||||
| 169 | |||||||||||||||||||||||
| 170 | # We are only interested in the updated responses | ||||||||||||||||||||||
| 171 | 0 | my @resps = $command->get_responses("VCS::LibCVS::Client::Response::Updated"); | |||||||||||||||||||||
| 172 | 0 | my %results; | |||||||||||||||||||||
| 173 | 0 | foreach my $resp (@resps) { | |||||||||||||||||||||
| 174 | # Construct the name of the specified file. Its basename is specified in | ||||||||||||||||||||||
| 175 | # the first datum of the response (a pathname). Its directory is the | ||||||||||||||||||||||
| 176 | # fullname of this object. | ||||||||||||||||||||||
| 177 | 0 | my ($basename) = ( $resp->data()->[0]->{RemoteFile} =~ m#^.*/([^/]*)# ); | |||||||||||||||||||||
| 178 | 0 | my $name = File::Spec::Unix->catfile($dir->get_name(), $basename); | |||||||||||||||||||||
| 179 | # Construct a filebranch | ||||||||||||||||||||||
| 180 | 0 | my $file = VCS::LibCVS::RepositoryFile->new($dir->get_repository(), $name); | |||||||||||||||||||||
| 181 | 0 | my $file_branch = VCS::LibCVS::FileBranch->new($file, $tag_spec, undef); | |||||||||||||||||||||
| 182 | 0 | $results{$basename} = $file_branch; | |||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||
| 184 | 0 | return \%results; | |||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||
| 186 | |||||||||||||||||||||||
| 187 | ############################################################################### | ||||||||||||||||||||||
| 188 | # Private routines | ||||||||||||||||||||||
| 189 | ############################################################################### | ||||||||||||||||||||||
| 190 | |||||||||||||||||||||||
| 191 | =head1 SEE ALSO | ||||||||||||||||||||||
| 192 | |||||||||||||||||||||||
| 193 | VCS::LibCVS | ||||||||||||||||||||||
| 194 | |||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||
| 196 | |||||||||||||||||||||||
| 197 | 1 | 1; | |||||||||||||||||||||