blib/lib/VCS/LibCVS.pm

filter: Statementstmt 88.5% 93 / 105 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.6% 29 / 30 Podpod 0.0% 0 / 1 totaltotal 85.9% 122 / 142 CC 4 SCAR 11.9
CC
4
Cov
84%
parse_date
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« blib/lib/VCS/LibCVS/WorkingFileOrDirectory.pm ↑ Summary blib/lib/VCS/LibCVS/Client/Connection/Local.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;
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 Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Internals
16  
17 1 ▶use VCS::LibCVS::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use VCS::LibCVS::Admin;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use VCS::LibCVS::IgnoreChecker;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use VCS::LibCVS::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 =head1 NAME
23  
24 VCS::LibCVS - Access CVS working directories and repositories.
25  
26 =head1 SYNOPSIS
27  
28 Please see the example script, examples/lcvs-example.
29  
30 $working_dir = VCS::LibCVS::WorkingDirectory->new(File::Spec->curdir);
31  
32 =head1 DESCRIPTION
33  
34 LibCVS provides native Perl access to CVS.
35  
36 These docs assume some familiarity with concepts of CVS. For example, the term
37 "Working Directory" (or sandbox) refers to a collection of directories and
38 files which have been checked out of CVS.
39  
40 The API is provided through a collection of classes. They come in 3 groups,
41 Working Directory Classes, Repository Classes, and Other Classes. A brief
42 description of each class is provided here, for more details see its perldoc.
43  
44 For a language independent description of the API, please see the docs at
45 libcvs.cvshome.org.
46  
47 =head2 Working Directory classes
48  
49 These classes give you access to the stuff in a working directory, as governed
50 by the standard CVS working directory admin information (CVS/*). They also
51 provide several ways to get at information the repository, or compare against
52 what's in the repository.
53  
54 You will probably find the need to construct objects of these types explicitly.
55  
56 =over 4
57  
58 =cut
59  
60 1 ▶use VCS::LibCVS::WorkingFileOrDirectory;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use VCS::LibCVS::WorkingFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 ▶use VCS::LibCVS::WorkingDirectory;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use VCS::LibCVS::WorkingUnmanagedFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 =item VCS::LibCVS::WorkingFileOrDirectory
66  
67 A parent class for all the types of files and directories that you find in a
68 working directory.
69  
70 =item VCS::LibCVS::WorkingFile
71  
72 A file which is being managed by CVS. It has either been checked out of the
73 repository, or given to CVS with "cvs add".
74  
75 =item VCS::LibCVS::WorkingDirectory
76  
77 A directory which is being managed by CVS.
78  
79 =item VCS::LibCVS::WorkingUnmanagedFile
80  
81 A file which upsets CVS. It's in a CVS working directory, but it's not in the
82 repository, it has been "cvs add"ed, and it's not in any of the ignore lists.
83  
84 =back
85  
86 =head2 Repository classes
87  
88 These classes give you access to the stuff in the repository. They use the
89 remote protocol to get at the repository, so they don't require any local CVS
90 directory. You will need a CVSROOT to find the repo though.
91  
92 The only classes here that you should need to construct explicitly are those
93 named VCS::LibCVS::Repository*.
94  
95 =over 4
96  
97 =cut
98  
99 1 ▶use VCS::LibCVS::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 =item VCS::LibCVS::Repository
102  
103 The CVS repository.
104  
105 =cut
106  
107 1 ▶use VCS::LibCVS::RepositoryFileOrDirectory;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 1 ▶use VCS::LibCVS::RepositoryFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 1 ▶use VCS::LibCVS::RepositoryDirectory;
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 =item VCS::LibCVS::RepositoryFileOrDirectory
112  
113 Parent class for repository files and directories.
114  
115 =item VCS::LibCVS::RepositoryFile
116  
117 A file in the repository. It's really a collection of revisions, and a bunch
118 of branch and tag information too.
119  
120 =item VCS::LibCVS::RepositoryDirectory
121  
122 A directory in the repository. Really just a container for files, but it is
123 treated as having branches.
124  
125 =cut
126  
127 1 ▶use VCS::LibCVS::DirectoryBranch;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 =item VCS::LibCVS::DirectoryBranch
130  
131 A branch of a directory. This is really just a stepping stone to getting
132 specific branches of many files at once.
133  
134 =cut
135  
136 1 ▶use VCS::LibCVS::FileBranch;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 1 ▶use VCS::LibCVS::FileRevision;
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 =item VCS::LibCVS::FileBranch
140  
141 A specific branch of a file. Or a collection of revisions from another
142 perspective.
143  
144 =item VCS::LibCVS::FileRevision
145  
146 A specific revision of a file.
147  
148 =cut
149  
150 1 ▶use VCS::LibCVS::Branch;
Subroutine BEGIN: called CC=1 SCAR=0.0
151  
152 =item VCS::LibCVS::Branch
153  
154 A branch across the repository. This is not much more than a wrapper around a
155 branch name.
156  
157 =cut
158  
159 1 ▶use VCS::LibCVS::Slice;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 =item VCS::LibCVS::Slice
162  
163 A slice through the repository. A set of file revisions, with at most one
164 revision per file.
165  
166 =cut
167  
168 1 ▶use VCS::LibCVS::Datum;
Subroutine BEGIN: called CC=1 SCAR=0.0
169  
170 =head2 Other classes
171  
172 These classes are used by both the groups of classes above.
173  
174 =over
175  
176 =item VCS::LibCVS::Datum and children
177  
178 These classes reprsent various common bits of information in CVS, for example,
179 revision numbers. You shouldn't need to construct these directly, they are
180 returned by various routines in the other objects.
181  
182 =back
183  
184 =head1 WARNINGS
185  
186 =head2 Absolute And Relative Filenames
187  
188 Objects are created using filenames. These may be relative or absolute, and
189 are stored as such, so be careful if you change the current directory.
190  
191 =head2 Root vs. Repository
192  
193 A repository is a place where managed files are stored. A root is a string
194 which specifies a repository.
195  
196 =cut
197  
198 ###############################################################################
199 # Constants
200 ###############################################################################
201  
202 1 ▶use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS.pm,v 1.28 2005/10/10 12:58:42 dissent Exp $ ';
Subroutine BEGIN: called CC=1 SCAR=0.0
203 1 ▶use constant VERSION_TAG => '$Name: Release-1-00-02 $';
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 1 ▶use vars ('$VERSION');
Subroutine BEGIN: called CC=1 SCAR=0.0
206 1 $VERSION = 1.0002_0;
207  
208 ###############################################################################
209 # Variables
210 ###############################################################################
211  
212 =head1 CONFIGURATION VARIABLES
213  
214 =head2 @Authentication_Functions
215  
216 A list of functions that LibCVS will call when it's trying to authenticate to
217 the server. The functions will be called in order, until one responds with
218 proper credentials. If an authentication scheme has multiple steps, then the
219 same function will be called repeatedly for each step.
220  
221 They have this signature:
222  
223 \%credentials get_credentials($scheme, \@needed, \%info)
224  
225 =over 4
226  
227 =item $scheme is a string, eg "pserver", "kerberos", . . .
228  
229 Its value is determined from the CVSROOT.
230  
231 =item @needed are strings naming the needed information
232  
233 A list of parameters this scheme needs to authenticate successfully, eg
234 "scrambled_password" for pserver. Each authentication scheme defines different
235 needed parameters. They are documented with the authentication scheme. You
236 may find such documentation in the documentation for your connection class, eg
237 "VCS::LibCVS::Client::Connection::Pserver" for the pserver scheme.
238  
239 =item %info is information required to authenticate
240  
241 What is included in here is also documented as part of the authentication
242 scheme. For example, a challenge response scheme will provide the challenge in
243 here, with the key "Challenge".
244  
245 A VCS::LibCVS::Datum::Root object will always be available through the key
246 "CVSRoot".
247  
248 =item %credentials values for needed parameters, or undef
249  
250 If the function can't authenticate for any reason, it can return undef to
251 signal this. Otherwise, for each parameter named in @needed, there must be a
252 key in here with the same name, whose value is the required information.
253  
254 =back
255  
256 By default one function is inserted to this list by the Pserver connection
257 module. This function handles password prompting, and the manipulation of the
258 .cvspass file. This default function can be removed by emptying the list. See
259 VCS::LibCVS::Client::Connection::Pserver::auth_cvspass for details on
260 configuring this function..
261  
262 =cut
263  
264 1 ▶use vars ('@Authentication_Functions');
Subroutine BEGIN: called CC=1 SCAR=0.0
265  
266 =head2 $Admin_Dir_Name scalar string, default "CVS"
267  
268 The name of the sandbox admin directory.
269  
270 =cut
271  
272 1 ▶use vars ('$Admin_Dir_Name');
Subroutine BEGIN: called CC=1 SCAR=0.0
273 1 $Admin_Dir_Name = "CVS";
274  
275 =head2 $Cache_FileRevision_Contents_by_Repository boolean, default "1"
276  
277 True means that results of fetching the contents of a file revision should be
278 cached for each Repository object. This cache is necessary because of the way
279 CVS works; it won't return the contents of the same revision twice in a row
280 over a single client connection. You shouldn't change this unless you really
281 know what you are doing. It is used in the routine
282 VCS::LibCVS::FileRevision->get_contents().
283  
284 =cut
285  
286 1 ▶use vars ('$Cache_FileRevision_Contents_by_Repository');
Subroutine BEGIN: called CC=1 SCAR=0.0
287 1 $Cache_FileRevision_Contents_by_Repository = 1;
288  
289 =head2 $Cache_Repository boolean, default "1"
290  
291 True means that VCS::LibCVS::Repository objects should be cached and reused.
292 If you construct a Repository object, and one already exists with the same
293 root, then the existing one will be reused. Roots are compared as strings, so
294 different usernames, alias hostnames, and symlinks in repository directories
295 will defeat the cache. This is of course risky for multi-thread environments.
296  
297 This also results in connection caching, since each repository object keeps an
298 open connection to the server.
299  
300 =cut
301  
302 1 ▶use vars ('$Cache_Repository');
Subroutine BEGIN: called CC=1 SCAR=0.0
303 1 $Cache_Repository = 1;
304  
305 =head2 $Cache_RepositoryFileOrDirectory boolean, default "1"
306  
307 True means that VCS::LibCVS::RepositoryFileOrDirectory objects should be cached
308 and reused. If you construct a RepositoryFileOrDirectory object, and one
309 already exists with the same filename and repository, then the existing one
310 will be reused. This is of course risky for multi-thread environments.
311  
312 =cut
313  
314 1 ▶use vars ('$Cache_RepositoryFileOrDirectory');
Subroutine BEGIN: called CC=1 SCAR=0.0
315 1 $Cache_RepositoryFileOrDirectory = 1;
316  
317 ###############################################################################
318 # Private Utility Routines
319 ###############################################################################
320  
321 # Parse a CVS style date into a perl time offset since epoch.
322 0 ▶sub parse_date {
Subroutine parse_date: not called CC=4 SCAR=30.0
Pod undocumented
323 0 my $date = shift;
324  
325 # The date format changed in the 1_12 series of cvs
326  
327 # Before 1.12.? it looked like this: 2004/03/22 00:04:43
328 0 my $match_pre_1_12 = ("^([0-9][0-9][0-9][0-9])/([0-1][0-9])/([0-9][0-9]) "
329 . "([0-2][0-9]):([0-5][0-9]):([0-5][0-9])\$");
330  
331 # After 1.12.?-1 it looks like this: 2004-03-21 19:04:43 -0500
332 0 my $match_post_1_12 = ("^([0-9][0-9][0-9][0-9])-([0-1][0-9])-([0-9][0-9]) "
333 . "([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) "
334 . "([+-][0-9][0-9][0-9][0-9])\$");
335  
336 0 ▶ if ($date =~ m#$match_pre_1_12#) {
Branch: 2 branches
BranchTrueFalseTotal
if ($date =~ /$match_pre_1_12/) { } 0 0 0
elsif ($date =~ /$match_post_1_12/) { } 0 0 0
337 0 my ($yr, $mo, $dy, $hr, $mi, $se) = ($date =~ m#$match_pre_1_12#);
338 0 return timegm($se, $mi, $hr, $dy, $mo - 1, $yr);
339  
340 } elsif ($date =~ m#$match_post_1_12#) {
341 0 my ($yr, $mo, $dy, $hr, $mi, $se, $tz) = ($date =~ m#$match_post_1_12#);
342 0 my $time = timegm($se, $mi, $hr, $dy, $mo - 1, $yr);
343  
344 0 my ($tz_sn, $tz_hr, $tz_mi) = ($tz =~ m#([+-])([0-9][0-9])([0-9][0-9])#);
345 0 ▶ my $tz_off = ($tz_hr * 60 + $tz_mi) * 60 * (($tz_sn eq "-") ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$tz_sn eq '-' ? : 0 0 0
346  
347 0 return $time + $tz_off;
348  
349 } else {
350 0 confess "Failed to match date: $date\n";
351 }
352  
353 }
354  
355 =head1 SEE ALSO
356  
357 =cut
358  
359 1 1;
« blib/lib/VCS/LibCVS/WorkingFileOrDirectory.pm ↑ Summary blib/lib/VCS/LibCVS/Client/Connection/Local.pm »