« blib/lib/VCS/LibCVS/RepositoryFile.pm
↑ Summary
blib/lib/VCS/LibCVS/Client/Connection/Pserver.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::Admin; | ||||||||||||
| 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 | 1 | ▶ | use FileHandle; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 1 | ▶ | use VCS::LibCVS::Datum; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | =head1 NAME | ||||||||||||
| 18 | |||||||||||||
| 19 | VCS::LibCVS::Admin - The CVS sandbox administrative directory. | ||||||||||||
| 20 | |||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||
| 22 | |||||||||||||
| 23 | $admin_dir = VCS::LibCVS::Admin->new("/home/alex/wrk/libcvs/Perl"); | ||||||||||||
| 24 | $entries = $admin->get_Entries; | ||||||||||||
| 25 | $tag = $admin->get_Tag; | ||||||||||||
| 26 | |||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||
| 28 | |||||||||||||
| 29 | Admin represents the administrative information used for managing the | ||||||||||||
| 30 | checked-out files in the sandbox. Each instance of Admin reprsents this | ||||||||||||
| 31 | information for the contents of a single directory. | ||||||||||||
| 32 | |||||||||||||
| 33 | In order to be compatible with other CVS implementations, the default is to use | ||||||||||||
| 34 | a subdirectory of the indicated directory named "CVS". It should contain at | ||||||||||||
| 35 | least the three files "Entries", "Root" and "Repository". To use a different | ||||||||||||
| 36 | name, change $VCS::LibCVS::Admin_Dir_Name. | ||||||||||||
| 37 | |||||||||||||
| 38 | The administrative information is accessed through objects which are subclasses | ||||||||||||
| 39 | of LibCVS::Datum. | ||||||||||||
| 40 | |||||||||||||
| 41 | =cut | ||||||||||||
| 42 | |||||||||||||
| 43 | ############################################################################### | ||||||||||||
| 44 | # Class constants | ||||||||||||
| 45 | ############################################################################### | ||||||||||||
| 46 | |||||||||||||
| 47 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Admin.pm,v 1.18 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | |||||||||||||
| 49 | ############################################################################### | ||||||||||||
| 50 | # Class variables | ||||||||||||
| 51 | ############################################################################### | ||||||||||||
| 52 | |||||||||||||
| 53 | ############################################################################### | ||||||||||||
| 54 | # Private variables | ||||||||||||
| 55 | ############################################################################### | ||||||||||||
| 56 | |||||||||||||
| 57 | # $self->{AdminDirName} The filesystem name of the directory containing | ||||||||||||
| 58 | # the administrative files eg /home/alex/wrk/mod1/CVS | ||||||||||||
| 59 | # $self->{DirName} The filesystem name of the directory containing | ||||||||||||
| 60 | # the CVS managed files eg /home/alex/wrk/mod1 | ||||||||||||
| 61 | |||||||||||||
| 62 | ############################################################################### | ||||||||||||
| 63 | # Class routines | ||||||||||||
| 64 | ############################################################################### | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 CLASS ROUTINES | ||||||||||||
| 67 | |||||||||||||
| 68 | =head2 B<new()> | ||||||||||||
| 69 | |||||||||||||
| 70 | $admin_dir = Admin->new($directory_name) | ||||||||||||
| 71 | |||||||||||||
| 72 | =over 4 | ||||||||||||
| 73 | |||||||||||||
| 74 | =item return type: VCS::LibCVS::Admin | ||||||||||||
| 75 | |||||||||||||
| 76 | A new Admin. | ||||||||||||
| 77 | |||||||||||||
| 78 | =item argument 1 type: scalar string | ||||||||||||
| 79 | |||||||||||||
| 80 | The name of directory in the file system. This should not end in a slash. | ||||||||||||
| 81 | |||||||||||||
| 82 | =back | ||||||||||||
| 83 | |||||||||||||
| 84 | Creates a new Admin. The administrative information is assumed to be in a | ||||||||||||
| 85 | subdirectory called CVS (or value of $VCS::LibCVS::Admin_Dir_Name) of the | ||||||||||||
| 86 | specified directory. | ||||||||||||
| 87 | |||||||||||||
| 88 | =cut | ||||||||||||
| 89 | |||||||||||||
| 90 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=9.9
Pod
documented
| |||||||||||||
| 91 | 1 | my ($class, $dir) = @_; | |||||||||||
| 92 | |||||||||||||
| 93 | 1 | my $admin_dir = File::Spec->catpath('', $dir, $VCS::LibCVS::Admin_Dir_Name); | |||||||||||
| 94 | 1 | ▶ | confess "No CVS admin directory: $admin_dir" unless -d $admin_dir; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | |||||||||||||
| 96 | 0 | my $that = bless {}, $class; | |||||||||||
| 97 | 0 | $that->{DirName} = $dir; | |||||||||||
| 98 | 0 | $that->{AdminDirName} = $admin_dir; | |||||||||||
| 99 | |||||||||||||
| 100 | 0 | return $that; | |||||||||||
| 101 | } | ||||||||||||
| 102 | |||||||||||||
| 103 | ############################################################################### | ||||||||||||
| 104 | # Instance routines | ||||||||||||
| 105 | ############################################################################### | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 INSTANCE ROUTINES | ||||||||||||
| 108 | |||||||||||||
| 109 | =head2 B<get_dir_name()> | ||||||||||||
| 110 | |||||||||||||
| 111 | $dir_name = $admin->get_dir_name() | ||||||||||||
| 112 | |||||||||||||
| 113 | =over 4 | ||||||||||||
| 114 | |||||||||||||
| 115 | =item return type: scalar string | ||||||||||||
| 116 | |||||||||||||
| 117 | =back | ||||||||||||
| 118 | |||||||||||||
| 119 | Returns the name of the local directory whose administrative data this object | ||||||||||||
| 120 | represents. | ||||||||||||
| 121 | |||||||||||||
| 122 | =cut | ||||||||||||
| 123 | |||||||||||||
| 124 | 0 | ▶ | sub get_dir_name { | ||||||||||
|
Subroutine
get_dir_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||
| 126 | 0 | return $self->{DirName}; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | =head2 B<get_Entries()> | ||||||||||||
| 130 | |||||||||||||
| 131 | $entries = $admin->get_Entries() | ||||||||||||
| 132 | |||||||||||||
| 133 | =over 4 | ||||||||||||
| 134 | |||||||||||||
| 135 | =item return type: ref to hash | ||||||||||||
| 136 | |||||||||||||
| 137 | keys are filenames as strings, values are VCS::LibCVS::Datum::Entry | ||||||||||||
| 138 | |||||||||||||
| 139 | =back | ||||||||||||
| 140 | |||||||||||||
| 141 | Returns the list of CVS managed files in the directory. They are stored in a | ||||||||||||
| 142 | hash with relative filenames as keys and LibCVS::Datum::Entry objects as values. | ||||||||||||
| 143 | |||||||||||||
| 144 | =cut | ||||||||||||
| 145 | |||||||||||||
| 146 | 0 | ▶ | sub get_Entries { | ||||||||||
|
Subroutine
get_Entries: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||
| 148 | |||||||||||||
| 149 | # A line with just a D, means that subdirectories have not been recorded. | ||||||||||||
| 150 | # Remember if it's found, and look for them manually. | ||||||||||||
| 151 | 0 | my $sub_dirs_not_included = 0; | |||||||||||
| 152 | |||||||||||||
| 153 | 0 | my $filename = File::Spec->catpath('', $self->{AdminDirName}, "Entries"); | |||||||||||
| 154 | 0 | my $fh = FileHandle->new($filename); | |||||||||||
| 155 | 0 | ▶ | confess "Couldn't open $filename" unless defined $fh; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 156 | 0 | my $entries = {}; | |||||||||||
| 157 | 0 | foreach my $entry_line ($fh->getlines()) { | |||||||||||
| 158 | 0 | ▶ | if ($entry_line =~ /^D$/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 159 | 0 | $sub_dirs_not_included = 1; | |||||||||||
| 160 | 0 | next; | |||||||||||
| 161 | } | ||||||||||||
| 162 | 0 | my $entry = VCS::LibCVS::Datum::Entry->new($entry_line); | |||||||||||
| 163 | 0 | $entries->{$entry->name} = $entry; | |||||||||||
| 164 | } | ||||||||||||
| 165 | |||||||||||||
| 166 | # Do the manual check for directories if necessary. | ||||||||||||
| 167 | 0 | ▶ | if ($sub_dirs_not_included) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 168 | # Get the name of the parent directory. | ||||||||||||
| 169 | 0 | my @splitdirs = File::Spec->splitdir($self->{AdminDirName}); | |||||||||||
| 170 | 0 | pop @splitdirs; | |||||||||||
| 171 | 0 | my $parent = File::Spec->catdir(@splitdirs); | |||||||||||
| 172 | |||||||||||||
| 173 | # Traverse all of its directory entries. | ||||||||||||
| 174 | 0 | ▶ | my $parent_dir = IO::Dir->new($parent) || confess("Can't opendir $parent"); | ||||||||||
|
Condition0%0/2
'IO::Dir'->new($parent) || confess("Can't opendir $parent")
MC/DC0%0/1
'IO::Dir'->new($parent) || confess("Can't opendir $parent")
'IO::Dir'->new($parent)
Truth table0%0/2
A
A= 'IO::Dir'->new($parent)
| |||||||||||||
| 175 | 0 | foreach my $subdir ($parent_dir->read()) { | |||||||||||
| 176 | 0 | ▶ | next if $subdir =~ /\.\.?/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | 0 | ▶ | next if $subdir eq $VCS::LibCVS::Admin_Dir_Name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 178 | # Skip it if it was already found in the Entries file. | ||||||||||||
| 179 | 0 | ▶ | next if defined $entries->{$subdir}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 180 | # Skip it unless it has a subdirectory called CVS. | ||||||||||||
| 181 | next unless | ||||||||||||
| 182 | 0 | ▶ | -d File::Spec->catdir(($parent, $subdir, $VCS::LibCVS::Admin_Dir_Name)); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 183 | |||||||||||||
| 184 | # Create a new entry for it. | ||||||||||||
| 185 | 0 | $entries->{$subdir} = VCS::LibCVS::Datum::Entry->new("D/$subdir////"); | |||||||||||
| 186 | } | ||||||||||||
| 187 | } | ||||||||||||
| 188 | |||||||||||||
| 189 | 0 | return $entries; | |||||||||||
| 190 | } | ||||||||||||
| 191 | |||||||||||||
| 192 | =head2 B<get_Root()> | ||||||||||||
| 193 | |||||||||||||
| 194 | $root = $admin->get_Root() | ||||||||||||
| 195 | |||||||||||||
| 196 | =over 4 | ||||||||||||
| 197 | |||||||||||||
| 198 | =item return type: LibCVS::Datum::Root | ||||||||||||
| 199 | |||||||||||||
| 200 | =back | ||||||||||||
| 201 | |||||||||||||
| 202 | Returns the CVS Root for the directory. | ||||||||||||
| 203 | |||||||||||||
| 204 | =cut | ||||||||||||
| 205 | |||||||||||||
| 206 | 0 | ▶ | sub get_Root { | ||||||||||
|
Subroutine
get_Root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 207 | 0 | my $self = shift; | |||||||||||
| 208 | |||||||||||||
| 209 | 0 | my $filename = $self->{AdminDirName} . "/Root"; | |||||||||||
| 210 | 0 | my $fh = FileHandle->new($filename); | |||||||||||
| 211 | 0 | return VCS::LibCVS::Datum::Root->new($fh->getline); | |||||||||||
| 212 | } | ||||||||||||
| 213 | |||||||||||||
| 214 | =head2 B<get_Repository()> | ||||||||||||
| 215 | |||||||||||||
| 216 | $rep_dir = $admin->get_Repository() | ||||||||||||
| 217 | |||||||||||||
| 218 | =over 4 | ||||||||||||
| 219 | |||||||||||||
| 220 | =item return type: VCS::LibCVS::Datum::DirectoryName | ||||||||||||
| 221 | |||||||||||||
| 222 | =back | ||||||||||||
| 223 | |||||||||||||
| 224 | Returns the name of the repository directory for this directory, relative to | ||||||||||||
| 225 | the root of the repository. | ||||||||||||
| 226 | |||||||||||||
| 227 | =cut | ||||||||||||
| 228 | |||||||||||||
| 229 | 0 | ▶ | sub get_Repository { | ||||||||||
|
Subroutine
get_Repository: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 230 | 0 | my $self = shift; | |||||||||||
| 231 | |||||||||||||
| 232 | 0 | my $filename = $self->{AdminDirName} . "/Repository"; | |||||||||||
| 233 | 0 | my $fh = FileHandle->new($filename); | |||||||||||
| 234 | 0 | my $repodir = $fh->getline(); | |||||||||||
| 235 | 0 | my $root = $self->get_Root()->as_string(); | |||||||||||
| 236 | 0 | $repodir =~ s#^$root/(.*)#$1#; | |||||||||||
| 237 | 0 | return VCS::LibCVS::Datum::DirectoryName->new($repodir); | |||||||||||
| 238 | } | ||||||||||||
| 239 | |||||||||||||
| 240 | =head2 B<get_Tag()> | ||||||||||||
| 241 | |||||||||||||
| 242 | $tag = $admin->get_Tag() | ||||||||||||
| 243 | |||||||||||||
| 244 | =over 4 | ||||||||||||
| 245 | |||||||||||||
| 246 | =item return type: LibCVS::Datum::TagSpec | ||||||||||||
| 247 | |||||||||||||
| 248 | =back | ||||||||||||
| 249 | |||||||||||||
| 250 | Returns the sticky tag specification for this directory. If there is no sticky | ||||||||||||
| 251 | tag, it returns undef. | ||||||||||||
| 252 | |||||||||||||
| 253 | =cut | ||||||||||||
| 254 | |||||||||||||
| 255 | 0 | ▶ | sub get_Tag { | ||||||||||
|
Subroutine
get_Tag: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 256 | 0 | my $self = shift; | |||||||||||
| 257 | |||||||||||||
| 258 | 0 | my $filename = $self->{AdminDirName} . "/Tag"; | |||||||||||
| 259 | 0 | ▶ | return undef unless -e $filename; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 260 | 0 | my $fh = FileHandle->new($filename); | |||||||||||
| 261 | 0 | return VCS::LibCVS::Datum::TagSpec->new($fh->getline); | |||||||||||
| 262 | } | ||||||||||||
| 263 | |||||||||||||
| 264 | ############################################################################### | ||||||||||||
| 265 | # Private routines | ||||||||||||
| 266 | ############################################################################### | ||||||||||||
| 267 | |||||||||||||
| 268 | |||||||||||||
| 269 | =head1 SEE ALSO | ||||||||||||
| 270 | |||||||||||||
| 271 | VCS::LibCVS::Datum | ||||||||||||
| 272 | |||||||||||||
| 273 | =cut | ||||||||||||
| 274 | |||||||||||||
| 275 | 1 | 1; | |||||||||||