Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
SubversionPecl
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 6
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 canConnect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDiff
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
 getDirList
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getLog
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CodeReview\Backend;
4
5use Exception;
6use Wikimedia\AtEase\AtEase;
7
8/**
9 * Using the SVN PECL extension...
10 */
11class SubversionPecl extends SubversionAdaptor {
12
13    public function __construct( $repoPath ) {
14        parent::__construct( $repoPath );
15        global $wgSubversionUser, $wgSubversionPassword;
16        if ( $wgSubversionUser ) {
17            svn_auth_set_parameter( SVN_AUTH_PARAM_DEFAULT_USERNAME, $wgSubversionUser );
18            svn_auth_set_parameter( SVN_AUTH_PARAM_DEFAULT_PASSWORD, $wgSubversionPassword );
19        }
20    }
21
22    /**
23     * Just return true for now. svn_info() is too slow to be useful...
24     *
25     * Using undocumented svn_info function. Looking at the source, this has
26     * existed since version 0.3 of the Pecl extension (per release notes).
27     * Nobody ever bothered filling in the documentation on php.net though.
28     * The function returns a big array of a bunch of info about the repository
29     * It throws a warning if the repository does not exist.
30     * @return true
31     */
32    public function canConnect() {
33        // Wikimedia\suppressWarnings();
34        // $result = svn_info( $this->mRepoPath );
35        // Wikimedia\restoreWarnings();
36        return true;
37    }
38
39    public function getFile( $path, $rev = null ) {
40        return svn_cat( $this->mRepoPath . $path, $rev );
41    }
42
43    public function getDiff( $path, $rev1, $rev2 ) {
44        list( $fout, $ferr ) = svn_diff(
45            $this->mRepoPath . $path, $rev1,
46            $this->mRepoPath . $path, $rev2 );
47
48        if ( $fout ) {
49            // We have to read out the file descriptors. :P
50            $out = '';
51            while ( !feof( $fout ) ) {
52                $out .= fgets( $fout );
53            }
54            fclose( $fout );
55            fclose( $ferr );
56
57            return $out;
58        } else {
59            return new Exception( "Diffing error" );
60        }
61    }
62
63    public function getDirList( $path, $rev = null ) {
64        return svn_ls( $this->mRepoPath . $path,
65            $this->_rev( $rev, SVN_REVISION_HEAD ) );
66    }
67
68    public function getLog( $path, $startRev = null, $endRev = null ) {
69        AtEase::suppressWarnings();
70        $log = svn_log( $this->mRepoPath . $path,
71            $this->_rev( $startRev, SVN_REVISION_INITIAL ),
72            $this->_rev( $endRev, SVN_REVISION_HEAD ) );
73        AtEase::restoreWarnings();
74        return $log;
75    }
76}