Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -73,3 +73,8 @@ |
74 | 74 | |
75 | 75 | $wgSpecialPages['Code'] = 'SpecialCode'; |
76 | 76 | $wgSpecialPages['RepoAdmin'] = 'SpecialRepoAdmin'; |
| 77 | + |
| 78 | +// If you can't directly access the remote SVN repo, you can set this |
| 79 | +// to an offsite proxy running this fun little proxy tool: |
| 80 | +// http://svn.wikimedia.org/viewvc/mediawiki/trunk/tools/codereview-proxy/ |
| 81 | +$wgSubversionProxy = false; |
Index: trunk/extensions/CodeReview/Subversion.php |
— | — | @@ -5,7 +5,10 @@ |
6 | 6 | protected $mRepo; |
7 | 7 | |
8 | 8 | public static function newFromRepo( $repo ) { |
9 | | - if( function_exists( 'svn_log' ) ) { |
| 9 | + global $wgSubversionProxy; |
| 10 | + if( $wgSubversionProxy ) { |
| 11 | + return new SubversionProxy( $repo, $wgSubversionProxy ); |
| 12 | + } elseif( function_exists( 'svn_log' ) ) { |
10 | 13 | return new SubversionPecl( $repo ); |
11 | 14 | } else { |
12 | 15 | return new SubversionShell( $repo ); |
— | — | @@ -47,7 +50,6 @@ |
48 | 51 | |
49 | 52 | /** |
50 | 53 | * Using the SVN PECL extension... |
51 | | - * Untested! |
52 | 54 | */ |
53 | 55 | class SubversionPecl extends SubversionAdaptor { |
54 | 56 | function getFile( $path, $rev=null ) { |
— | — | @@ -59,15 +61,19 @@ |
60 | 62 | $this->mRepo . $path, $rev1, |
61 | 63 | $this->mRepo . $path, $rev2 ); |
62 | 64 | |
63 | | - // We have to read out the file descriptors. :P |
64 | | - $out = ''; |
65 | | - while( !feof( $fout ) ) { |
66 | | - $out .= $fout; |
| 65 | + if( $fout ) { |
| 66 | + // We have to read out the file descriptors. :P |
| 67 | + $out = ''; |
| 68 | + while( !feof( $fout ) ) { |
| 69 | + $out .= fgets( $fout ); |
| 70 | + } |
| 71 | + fclose( $fout ); |
| 72 | + fclose( $ferr ); |
| 73 | + |
| 74 | + return $out; |
| 75 | + } else { |
| 76 | + return new MWException("Diffing error"); |
67 | 77 | } |
68 | | - fclose( $fout ); |
69 | | - fclose( $ferr ); |
70 | | - |
71 | | - return $out; |
72 | 78 | } |
73 | 79 | |
74 | 80 | function getLog( $path, $startRev=null, $endRev=null ) { |
— | — | @@ -195,3 +201,49 @@ |
196 | 202 | return $out; |
197 | 203 | } |
198 | 204 | } |
| 205 | + |
| 206 | +/** |
| 207 | + * Using a remote JSON proxy |
| 208 | + */ |
| 209 | +class SubversionProxy extends SubversionAdaptor { |
| 210 | + function __construct( $repo, $proxy ) { |
| 211 | + parent::__construct( $repo ); |
| 212 | + $this->mProxy = $proxy; |
| 213 | + } |
| 214 | + |
| 215 | + function getFile( $path, $rev=null ) { |
| 216 | + throw new MWException( "NYI" ); |
| 217 | + } |
| 218 | + |
| 219 | + function getDiff( $path, $rev1, $rev2 ) { |
| 220 | + return $this->_proxy( array( |
| 221 | + 'action' => 'diff', |
| 222 | + 'path' => $path, |
| 223 | + 'rev1' => $rev1, |
| 224 | + 'rev2' => $rev2 ) ); |
| 225 | + } |
| 226 | + |
| 227 | + function getLog( $path, $startRev=null, $endRev=null ) { |
| 228 | + return $this->_proxy( array( |
| 229 | + 'action' => 'log', |
| 230 | + 'path' => $path, |
| 231 | + 'start' => $startRev, |
| 232 | + 'end' => $endRev ) ); |
| 233 | + } |
| 234 | + |
| 235 | + protected function _proxy( $params ) { |
| 236 | + foreach( $params as $key => $val ) { |
| 237 | + if( is_null( $val ) ) { |
| 238 | + // Don't pass nulls to remote |
| 239 | + unset( $params[$key] ); |
| 240 | + } |
| 241 | + } |
| 242 | + $target = $this->mProxy . '?' . wfArrayToCgi( $params ); |
| 243 | + $json = Http::get( $target ); |
| 244 | + if( $json === false ) { |
| 245 | + throw new MWException( "SVN proxy error" ); |
| 246 | + } |
| 247 | + $data = json_decode( $json, true ); |
| 248 | + return $data; |
| 249 | + } |
| 250 | +} |
Index: trunk/extensions/CodeReview/svnImport.php |
— | — | @@ -38,9 +38,14 @@ |
39 | 39 | break; // done! |
40 | 40 | } |
41 | 41 | $chunkSize = max( 1, floor($chunkSize/4) ); |
| 42 | + continue; |
42 | 43 | } else { |
43 | 44 | $start += $chunkSize; |
44 | 45 | } |
| 46 | + if( !is_array( $log ) ) { |
| 47 | + var_dump( $log ); |
| 48 | + die( 'wtf' ); |
| 49 | + } |
45 | 50 | foreach( $log as $data ) { |
46 | 51 | $revCount++; |
47 | 52 | $delta = microtime( true ) - $startTime; |