| 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::WorkingDirectory; | ||||||||||
| 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 IO::Dir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | =head1 NAME | ||||||||||
| 16 | |||||||||||
| 17 | VCS::LibCVS::WorkingDirectory - A directory checked out from CVS. | ||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | This object represents a directory of files checked out from CVS. | ||||||||||
| 24 | |||||||||||
| 25 | =head1 SUPERCLASS | ||||||||||
| 26 | |||||||||||
| 27 | VCS::LibCVS::WorkingFileOrDirectory | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | ############################################################################### | ||||||||||
| 32 | # Class constants | ||||||||||
| 33 | ############################################################################### | ||||||||||
| 34 | |||||||||||
| 35 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/WorkingDirectory.pm,v 1.10 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 1 | ▶ | use vars ('@ISA'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 1 | @ISA = ("VCS::LibCVS::WorkingFileOrDirectory"); | |||||||||
| 39 | |||||||||||
| 40 | ############################################################################### | ||||||||||
| 41 | # Class variables | ||||||||||
| 42 | ############################################################################### | ||||||||||
| 43 | |||||||||||
| 44 | ############################################################################### | ||||||||||
| 45 | # Private variables | ||||||||||
| 46 | ############################################################################### | ||||||||||
| 47 | |||||||||||
| 48 | ############################################################################### | ||||||||||
| 49 | # Class routines | ||||||||||
| 50 | ############################################################################### | ||||||||||
| 51 | |||||||||||
| 52 | =head1 CLASS ROUTINES | ||||||||||
| 53 | |||||||||||
| 54 | =head2 B<new()> | ||||||||||
| 55 | |||||||||||
| 56 | $working_dir = VCS::LibCVS::WorkingDirectory->new($dirname) | ||||||||||
| 57 | |||||||||||
| 58 | =over 4 | ||||||||||
| 59 | |||||||||||
| 60 | =item return type: VCS::LibCVS::WorkingDirectory | ||||||||||
| 61 | |||||||||||
| 62 | =item argument 1 type: scalar string | ||||||||||
| 63 | |||||||||||
| 64 | The name of the directory which is under CVS control. | ||||||||||
| 65 | |||||||||||
| 66 | =back | ||||||||||
| 67 | |||||||||||
| 68 | Creates a new WorkingDirectory. The filename may be relative or absolute, and | ||||||||||
| 69 | is stored as such. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||
| 74 | 1 | my $class = shift; | |||||||||
| 75 | 1 | my $that = $class->SUPER::new(@_); | |||||||||
| 76 | |||||||||||
| 77 | 1 | $that->{Admin} = VCS::LibCVS::Admin->new($that->get_name); | |||||||||
| 78 | |||||||||||
| 79 | 0 | return $that; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | ############################################################################### | ||||||||||
| 83 | # Instance routines | ||||||||||
| 84 | ############################################################################### | ||||||||||
| 85 | |||||||||||
| 86 | =head1 INSTANCE ROUTINES | ||||||||||
| 87 | |||||||||||
| 88 | =head2 B<get_remote_object()> | ||||||||||
| 89 | |||||||||||
| 90 | $r_dir = $l_dir->get_remote_object() | ||||||||||
| 91 | |||||||||||
| 92 | =over 4 | ||||||||||
| 93 | |||||||||||
| 94 | =item return type: VCS::LibCVS::RepositoryDirectory | ||||||||||
| 95 | |||||||||||
| 96 | Returns the CVS repository directory associated with this working directory. | ||||||||||
| 97 | |||||||||||
| 98 | =back | ||||||||||
| 99 | |||||||||||
| 100 | It reads the CVS working dir administrative directory to get this info. | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub get_remote_object { | ||||||||
|
Subroutine
get_remote_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 105 | 0 | my $self = shift; | |||||||||
| 106 | |||||||||||
| 107 | 0 | my $repo = VCS::LibCVS::Repository->new($self->{Admin}->get_Root()); | |||||||||
| 108 | 0 | my $r_name = $self->{Admin}->get_Repository()->{DirectoryName}; | |||||||||
| 109 | 0 | return VCS::LibCVS::RepositoryDirectory->new($repo, $r_name); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | =head2 B<get_files()> | ||||||||||
| 113 | |||||||||||
| 114 | $l_files = $l_dir->get_files() | ||||||||||
| 115 | |||||||||||
| 116 | =over 4 | ||||||||||
| 117 | |||||||||||
| 118 | =item return type: ref to hash | ||||||||||
| 119 | |||||||||||
| 120 | keys are filenames relative to this directory, as strings, values are | ||||||||||
| 121 | objects of type VCS::LibCVS::WorkingFile. | ||||||||||
| 122 | |||||||||||
| 123 | =back | ||||||||||
| 124 | |||||||||||
| 125 | Returns the CVS managed files in this directory, as specified locally in the | ||||||||||
| 126 | CVS sandbox administrative directory. | ||||||||||
| 127 | |||||||||||
| 128 | =cut | ||||||||||
| 129 | |||||||||||
| 130 | 0 | ▶ | sub get_files { | ||||||||
|
Subroutine
get_files: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 131 | 0 | my $self = shift; | |||||||||
| 132 | 0 | my $entries = $self->{Admin}->get_Entries(); | |||||||||
| 133 | 0 | my %files; | |||||||||
| 134 | 0 | foreach my $name (keys %$entries) { | |||||||||
| 135 | # Ignore any non-files in the list | ||||||||||
| 136 | 0 | ▶ | if ( $entries->{$name}->is_file() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 0 | my $full_name = File::Spec->catfile($self->get_name, $name); | |||||||||
| 138 | 0 | $files{$name} = VCS::LibCVS::WorkingFile->new($full_name); | |||||||||
| 139 | } | ||||||||||
| 140 | } | ||||||||||
| 141 | 0 | return \%files; | |||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | =head2 B<get_directory_branch()> | ||||||||||
| 145 | |||||||||||
| 146 | $local_dir->get_directory_branch() | ||||||||||
| 147 | |||||||||||
| 148 | =over 4 | ||||||||||
| 149 | |||||||||||
| 150 | =item return type: VCS::LibCVS::DirectoryBranch | ||||||||||
| 151 | |||||||||||
| 152 | =back | ||||||||||
| 153 | |||||||||||
| 154 | Returns the DirectoryBranch that this local directory is on, as determined by | ||||||||||
| 155 | any sticky tag. | ||||||||||
| 156 | |||||||||||
| 157 | =cut | ||||||||||
| 158 | |||||||||||
| 159 | 0 | ▶ | sub get_directory_branch { | ||||||||
|
Subroutine
get_directory_branch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 160 | 0 | my $self = shift; | |||||||||
| 161 | |||||||||||
| 162 | return VCS::LibCVS::DirectoryBranch->new($self->get_remote_object(), | ||||||||||
| 163 | 0 | $self->{Admin}->get_Tag()); | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | =head2 B<get_unmanaged_files()> | ||||||||||
| 167 | |||||||||||
| 168 | $u_files = $l_dir->get_unmanaged_files() | ||||||||||
| 169 | |||||||||||
| 170 | =over 4 | ||||||||||
| 171 | |||||||||||
| 172 | =item return type: ref to hash | ||||||||||
| 173 | |||||||||||
| 174 | keys are the names of files, relative to this directory. values are objects of | ||||||||||
| 175 | type VCS::LibCVS::WorkingUnmanagedFile. | ||||||||||
| 176 | |||||||||||
| 177 | =back | ||||||||||
| 178 | |||||||||||
| 179 | Return the list of files which are neither scheduled for addition, checked-out | ||||||||||
| 180 | from the repository, nor ignored. | ||||||||||
| 181 | |||||||||||
| 182 | Note that there may be a file in the repository with the same name as one | ||||||||||
| 183 | returned by this routine. This is a conflict situation. | ||||||||||
| 184 | |||||||||||
| 185 | =cut | ||||||||||
| 186 | |||||||||||
| 187 | 0 | ▶ | sub get_unmanaged_files { | ||||||||
|
Subroutine
get_unmanaged_files: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 188 | 0 | my $self = shift; | |||||||||
| 189 | |||||||||||
| 190 | # Managed files | ||||||||||
| 191 | 0 | my $m_files = $self->get_files(); | |||||||||
| 192 | |||||||||||
| 193 | # To check if files are to be ignored | ||||||||||
| 194 | 0 | my $ignorer = $self->get_repository()->get_ignoreChecker(); | |||||||||
| 195 | |||||||||||
| 196 | # All files in the directory | ||||||||||
| 197 | 0 | my $dir = IO::Dir->new($self->get_name()); | |||||||||
| 198 | 0 | my @entries = $dir->read(); | |||||||||
| 199 | 0 | $dir->close(); | |||||||||
| 200 | |||||||||||
| 201 | # Holds the hash of unmanaged files | ||||||||||
| 202 | 0 | my %u_files; | |||||||||
| 203 | 0 | foreach my $name (@entries) { | |||||||||
| 204 | 0 | my $full_name = File::Spec->catfile($self->get_name(), $name); | |||||||||
| 205 | # Throws exceptions if the file is not right | ||||||||||
| 206 | 0 | my $u_file; | |||||||||
| 207 | 0 | eval { | |||||||||
| 208 | 0 | $u_file = VCS::LibCVS::WorkingUnmanagedFile->new($full_name); | |||||||||
| 209 | 0 | $u_files{$name} = $u_file; | |||||||||
| 210 | }; | ||||||||||
| 211 | } | ||||||||||
| 212 | |||||||||||
| 213 | 0 | return \%u_files; | |||||||||
| 214 | } | ||||||||||
| 215 | |||||||||||
| 216 | =head2 B<get_directories()> | ||||||||||
| 217 | |||||||||||
| 218 | $s_dirs = $l_dir->get_directories() | ||||||||||
| 219 | |||||||||||
| 220 | =over 4 | ||||||||||
| 221 | |||||||||||
| 222 | =item return type: ref to hash | ||||||||||
| 223 | |||||||||||
| 224 | keys are the names of directories, relative to this directory. values are | ||||||||||
| 225 | objects of type VCS::LibCVS::WorkingDirectory. | ||||||||||
| 226 | |||||||||||
| 227 | =back | ||||||||||
| 228 | |||||||||||
| 229 | Returns the CVS managed directories in this directory, as specified locally in | ||||||||||
| 230 | the CVS sandbox administrative directory. | ||||||||||
| 231 | |||||||||||
| 232 | =cut | ||||||||||
| 233 | |||||||||||
| 234 | 0 | ▶ | sub get_directories { | ||||||||
|
Subroutine
get_directories: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 235 | 0 | my $self = shift; | |||||||||
| 236 | 0 | my $entries = $self->{Admin}->get_Entries(); | |||||||||
| 237 | 0 | my %dirs; | |||||||||
| 238 | 0 | foreach my $name (keys %$entries) { | |||||||||
| 239 | # Ignore any non-directories in the list | ||||||||||
| 240 | 0 | ▶ | if ( $entries->{$name}->is_directory() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 241 | 0 | my $full_name = File::Spec->catfile($self->get_name, $name); | |||||||||
| 242 | 0 | $dirs{$name} = VCS::LibCVS::WorkingDirectory->new($full_name); | |||||||||
| 243 | } | ||||||||||
| 244 | } | ||||||||||
| 245 | 0 | return \%dirs; | |||||||||
| 246 | } | ||||||||||
| 247 | |||||||||||
| 248 | ############################################################################### | ||||||||||
| 249 | # Private routines | ||||||||||
| 250 | ############################################################################### | ||||||||||
| 251 | |||||||||||
| 252 | # Directory names for reporting to the server. | ||||||||||
| 253 | # Routine called in Command.pm, see there for more details. | ||||||||||
| 254 | 0 | ▶ | sub _get_repo_dirs { | ||||||||
|
Subroutine
_get_repo_dirs: not called CC=1 SCAR=6.9
| |||||||||||
| 255 | 0 | my $self = shift; | |||||||||
| 256 | 0 | my $l_dir = $self->get_name(); | |||||||||
| 257 | 0 | my $root_repo_dir = $self->{Admin}->get_Root()->{RootDir}; | |||||||||
| 258 | 0 | my $within_repo_dir = $self->{Admin}->get_Repository()->as_string(); | |||||||||
| 259 | 0 | my $r_dir = File::Spec::Unix->catdir($root_repo_dir, $within_repo_dir); | |||||||||
| 260 | 0 | return [ $l_dir, $r_dir ]; | |||||||||
| 261 | } | ||||||||||
| 262 | |||||||||||
| 263 | =head1 SEE ALSO | ||||||||||
| 264 | |||||||||||
| 265 | VCS::LibCVS | ||||||||||
| 266 | |||||||||||
| 267 | =cut | ||||||||||
| 268 | |||||||||||
| 269 | 1 | 1; | |||||||||