Repos.pm untested

filter: Statementstmt 0.0% 0 / 126 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 38 Podpod 0.0% 0 / 32 totaltotal 0.0% 0 / 233 CC 14 SCAR 19.6
CC
14
Cov
0%
new
30.0
create
20.0
destroy
6.0
CRAP 7.1
1 use strict;
2 use warnings;
3 package SVN::Friendly::Repos;
4 my $CLASS = __PACKAGE__;
5  
6 #------------------------------------------------------------------
7 our @ISA=qw(SVN::Repos);
8  
9 #------------------------------------------------------------------
10 use SVN::Repos;
11 use SVN::Fs; #needed for fs type constants
12  
13 use SVN::Friendly::Config;
14 my $CONFIG_CLASS='SVN::Friendly::Config';
15  
16 #------------------------------------------------------------------
17  
18 sub START_COMMIT { \&SVN::Repos::start_commit_hook }
19 sub PRE_COMMIT { \&SVN::Repos::pre_commit_hook }
20 sub PRE_REVPROP { \&SVN::Repos::pre_revprop_change_hook }
21 sub POST_REVPROP { \&SVN::Repos::post_revprop_change_hook }
22 sub PRE_OBLITERATE { \&SVN::Repos::pre_obliterate_hook }
23 sub POST_OBLITERATE { \&SVN::Repos::post_obliterate_hook }
24 sub PRE_LOCK { \&SVN::Repos::pre_lock_hook }
25 sub POST_LOCK { \&SVN::Repos::post_lock_hook }
26 sub PRE_UNLOCK { \&SVN::Repos::pre_unlock_hook }
27 sub POST_UNLOCK { \&SVN::Repos::post_unlock_hook }
28  
29  
30 #------------------------------------------------------------------
31  
32 my %SINGLETONS;
33  
34 #------------------------------------------------------------------
35  
36 use Carp;
37  
38 #==================================================================
39 # CLASS METHODS
40 #==================================================================
41  
42 #------------------------------------------------------------------
43  
44 sub create {
45 # $sNative - svn_repos_create (called by SVN::Repos) will complain
46 # about non canonical paths if directory paths are
47 # '/' terminated!!!!
48 # If will also barf unless $sNative either is empty or
49 # non-existant.
50 # $xConfigFs a hash storing parameters that describe the
51 # repository's file system. See svn_fs_create. Some
52 # of the parameters:
53 # SVN_FS_CONFIG_FS_TYPE => file system type
54 # possible values: $SVN::Fs::TYPE_FSFS
55 # $SVN::Fs::TYPE_BDB
56 # $xConfig - opaque structure containing svn_config_t objects;
57 # these objects are created by reading a file or
58 # created in memory with various svn_config_XXX functions
59 # -or-
60 # the name of a directory storing configuration data
61  
62 # ignore $sClass - we need it only so we can call this as a class
63 # method
64 my ($sClass, $sNative, $xConfig, $xConfigFs, $oUuid) = @_;
65 $xConfig = $CONFIG_CLASS->new($xConfig);
66  
67 if (!ref($xConfigFs)) {
68 #config is type of file system rather than a hash reference
69 $xConfigFs = $SVN::Fs::TYPE_FSFS unless defined($xConfigFs);
70 $xConfigFs = { $SVN::Fs::CONFIG_FS_TYPE => $xConfigFs };
71 }
72  
73 #print STDERR "root=<$sNative>"
74 # . "\nconfig="
75 # . (defined $xConfig ? " <@{[%$xConfig]}> " : '<undef>')
76 # . "\nfsconfig="
77 # . (defined $xConfigFs ? " <@{[%$xConfigFs]}>" : '<undef>')
78 # . "\n";
79  
80 #does $sRepoPath need to be a UTF-8 encoded URL or just a OS
81 #acceptable file system path?
82 my $oRepos = SVN::Repos::create($sNative, undef, undef
83 , $xConfig->getCategoryHash()
84 , $xConfigFs);
85 $oRepos = $sClass->_new($sNative, $oRepos);
86  
87 if (defined($oUuid)) {
88 $oRepos->setUUID($oUuid);
89 }
90 return $oRepos;
91 }
92  
93 #------------------------------------------------------------------
94  
95 sub destroy {
96 my ($xRepos) = @_;
97 my $sNative = ref($xRepos) ? $xRepos->getRoot() : $xRepos;
98 SVN::Repos::delete($sNative);
99  
100 # no longer valid, so delete it from list
101 delete $SINGLETONS{$sNative};
102 }
103  
104 #------------------------------------------------------------------
105  
106 sub new {
107 my ($sClass, $sNative) = @_;
108 my $sRef = ref($sNative);
109 my $oRepos;
110  
111 if ($sRef eq '_p_svn_repos_t') {
112 $oRepos = $sNative;
113 $sNative = SVN::Repos::path($oRepos);
114 } elsif ($sRef && $sRef->isa(__PACKAGE__)) {
115 return $sNative; #already have an object
116 }
117  
118 my $k="$sClass($sNative)";
119 if (!exists($SINGLETONS{$k})) {
120 $oRepos = SVN::Repos::open($sNative) unless defined($oRepos);
121 return $sClass->_new($sNative, $oRepos);
122 } else {
123 return $SINGLETONS{$k};
124 }
125 }
126  
127 #------------------------------------------------------------------
128  
129 sub _new {
130 my ($sClass, $sNative, $oRepos) = @_;
131  
132 # $oRepos is blessed as _p_svn_repos_t
133 # to make the methods of this class accessible, we need to have
134 # an object that is a member of this class. However, we can't
135 # directly re-bless or else we will get type errors. So instead
136 # we wrap it up in a little array.
137  
138 my $k="$sClass($sNative)";
139 my $self = $SINGLETONS{$k} = bless(\$oRepos, $CLASS);
140 Scalar::Util::weaken($SINGLETONS{$k});
141 return $self;
142 }
143  
144 #==================================================================
145 # OBJECT METHODS - inherited and overridden
146 #==================================================================
147  
148 #------------------------------------------------------------------
149  
150 sub enableRevProps {
151 my ($self, $sScript) = @_;
152 my $sPath = $self->getHookFile(PRE_REVPROP);
153 $sScript="#!/usr/bin/perl\nexit(0);\n" unless defined($sScript);
154 open(my $fh, '>', $sPath)
155 or die "Can't open pre-revprop hook file: $!";
156 print $fh $sScript;
157 close $fh;
158 chmod 0755, $sPath;
159 }
160  
161 #------------------------------------------------------------------
162  
163 sub getSvnRepos { return ${$_[0]}; }
164  
165 #------------------------------------------------------------------
166  
167 sub getRoot {
168 my $self = shift;
169 my $oPool = $self->_shiftPool(\@_);
170 return SVN::Repos::path($$self, $oPool);
171 }
172  
173 #------------------------------------------------------------------
174  
175 sub getConfDir {
176 my $self = shift;
177 my $oPool = $self->_shiftPool(\@_);
178 return SVN::Repos::conf_dir($$self, $oPool);
179 }
180  
181 #------------------------------------------------------------------
182  
183 sub getDbDir {
184 my $self = shift;
185 my $oPool = $self->_shiftPool(\@_);
186 return SVN::Repos::db_env($$self, $oPool);
187 }
188  
189 #------------------------------------------------------------------
190  
191 sub getDbLogLockFile {
192 my $self = shift;
193 my $oPool = $self->_shiftPool(\@_);
194 return SVN::Repos::db_logs_lockfile($$self,$oPool);
195 }
196  
197 #------------------------------------------------------------------
198  
199 sub getFormat {
200 my $self = shift;
201 my $sNative = File::Spec->rel2abs('format', $self->getRoot());
202 open(my $fh, '<', $sNative) or die "Could not open $sNative: $!";
203 my $sLine = <$fh>;
204 if (defined($sLine)) {
205 chomp $sLine;
206 return $sLine;
207 } else {
208 return undef;
209 }}
210  
211 #------------------------------------------------------------------
212  
213 sub getHookDir {
214 my $self = shift;
215 my $oPool = $self->_shiftPool(\@_);
216 return SVN::Repos::hook_dir($$self, $oPool);
217 }
218  
219 #------------------------------------------------------------------
220  
221 sub getHookFile {
222 my $self = shift;
223 my $crGetHook = shift;
224 my $oPool = $self->_shiftPool(\@_);
225 return $crGetHook->($$self, $oPool);
226 }
227  
228 #------------------------------------------------------------------
229  
230 sub getLockDir {
231 my $self = shift;
232 my $oPool = $self->_shiftPool(\@_);
233 return SVN::Repos::lock_dir($$self, $oPool);
234 }
235  
236 #------------------------------------------------------------------
237  
238 sub getSvnserveConfFile {
239 my $self = shift;
240 my $oPool = $self->_shiftPool(\@_);
241 return SVN::Repos::svnserve_conf($$self, $oPool);
242 }
243  
244 #------------------------------------------------------------------
245  
246 sub getHead { $_[0]->getYoungestRevision() };
247  
248 #------------------------------------------------------------------
249  
250 sub getFileSystemType {
251 my $self = shift;
252 return SVN::Fs::type($self->getDbDir());
253 }
254  
255 #------------------------------------------------------------------
256  
257 sub getUUID {
258 my ($self, $oPool) = @_;
259 return $$self->fs()->get_uuid($oPool);
260 }
261  
262 #------------------------------------------------------------------
263  
264 sub getSwigVersion {
265 # Don't use SVN::Repos::version():
266 # It returns an svn_version_t struct which claims to be a hash
267 # but in fact will complain about FETCH, FIRST_KEY, etc being
268 # undefined. In any case, svn_version.h has constants that
269 # can be used in its place.
270 #my $hVersion = SVN::Repos::version();
271  
272 return sprintf("%d.%03d.%03d%s"
273 , $SVN::Core::VER_MAJOR
274 , $SVN::Core::VER_MINOR
275 , $SVN::Core::VER_PATCH
276 , (defined($SVN::Core::VER_NUMTAG)
277 ? $SVN::Core::VER_NUMTAG:'')
278 );
279 }
280  
281 #------------------------------------------------------------------
282  
283 sub getYoungestRevision {
284 my ($self, $iAprTime) = @_;
285 my $oFs = $$self->fs();
286 if (defined($iAprTime)) {
287 return $oFs->dated_revision($iAprTime);
288 } else {
289 return $oFs->youngest_rev();
290 }
291 }
292  
293 #------------------------------------------------------------------
294  
295 sub setUUID {
296 my ($self, $sUuid, $oPool) = @_;
297 return $$self->fs()->set_uuid($sUuid, $oPool);
298 }
299  
300  
301 ##------------------------------------------------------------------
302  
303 #sub hotcopy {
304 # my $self = shift;
305 # my $sFrom = shift;
306 # my $sTo = shift;
307 # my $bCleanLogs = shift;
308 # my $oPool = $self->_shiftPool(\@_);
309 # return SVN::Repos::hotcopy($self, $sFrom, $sTo, $bCleanLogs, $oPool);
310 #}
311  
312 ##------------------------------------------------------------------
313  
314 #sub recover {
315 # my $self = shift;
316 # my $crStart = shift;
317 # my $oPool = $self->_shiftPool(\@_);
318  
319 # my $sNative = $self->getRoot();
320 # SVN::Repos::recover2($self->getRoot(), $crStart, $oPool);
321 #}
322  
323 #------------------------------------------------------------------
324 # report
325 # svn_repos_begin_report - internal?
326 # svn_repos_set_path - internal?
327 # svn_repos_link_path - internal?
328 # svn_repos_delete_path - internal?
329 # svn_repos_finish_report - internal?
330 # svn_repos_abort_report - internal?
331 # delta editor
332 # svn_repos_node_editor
333 # svn_repos_node_from_baton
334 # svn_repos_get_commit_editor
335 # svn_repos_dir_delta
336 # svn_repos_replay
337 #
338 # filesystem
339 # svn_repos_deleted_rev
340 # svn_repos_history
341 # svn_repos_trace_node_locations
342 # filesystem root
343 # svn_repos_get_commited_info
344 # svn_repos_stat
345 # svn_repos_fs_change_node_prop
346 # filesystem transaction
347 # svn_repos_fs_change_txn_prop
348 # svn_repos_fs_change_txn_props
349 #
350 # authz
351 # svn_repos_authz_read
352 # svn_repos_authz_check_access
353 #
354 # notify action (used by pack)
355 # svn_repos_notify_create - internal?
356 #
357 # repository node
358 # repository dump stream parser
359 # svn_repos_get_fs_build_parser
360 # svn_repos_parse_dumpstream
361 #
362 # repos
363 # svn_repos_fs - do we want a separate object?
364 # svn_repos_trace_node_location_segments
365 # svn_repos_get_logs
366 # svn_repos_fs_get_mergeinfo
367 # svn_repos_get_file_revs
368 # svn_repos_fs_begin_txn_for_commit
369 # svn_repos_fs_begin_txn_for_update
370 # svn_repos_fs_lock
371 # svn_repos_fs_unlock
372 # svn_repos_fs_get_locks
373 # svn_repos_fs_change_rev_prop
374 # svn_repos_fs_revision_prop
375 # svn_repos_fs_revision_proplist
376 # svn_repos_verify_fs
377 # svn_repos_dump
378 # svn_repos_load
379 # svn_repos_has_capability
380 # svn_repos_remember_client_capabilities
381 # svn_repos_authz_check_revision_access
382 # svn_repos_fs_pack
383 # svn_repos_upgrade
384 # svn_repos_fs_commit_txn
385  
386  
387  
388  
389 #==================================================================
390 # PRIVATE OBJECT METHODS
391 #==================================================================
392  
393 sub _shiftPool {
394 my $self = shift @_;
395 die "Not a $CLASS" unless $self->isa($CLASS);
396  
397 my $oPool = shift @{shift @_};
398  
399 # Note: it seems that in one release, the default pool was
400 # accessible via $SVN::Core->gpool but in a later version, it is
401 # returned via a sub, SVN::Core::gpool(). Rather than try to guess
402 # which syntax (our vs. sub) we simply don't use the default
403 # global pool, gpool.
404 #
405 # In any case, callers are supposed to be able to temporarily
406 # reset the default pool (the pool chosen when $oPool is null). If
407 # we always set $oPool to the global pool we interfere with that.
408 #
409 # We can also run into problems because some C API routines that
410 # take file handles leave the current pool with an active reference
411 # to that handle. It is best not to use the global pool in lieu
412 # of the default since memory taken from gpool() is not released
413 # until subvrsion terminates.
414 # return defined($oPool) ? $oPool : $SVN::Core::gpool();
415  
416 return $oPool;
417 }
418  
419 #==================================================================
420 # MODULE INITIALIZATION
421 #==================================================================
422  
423 1;