r41442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41441‎ | r41442 | r41443 >
Date:19:33, 30 September 2008
Author:brion
Status:old
Tags:
Comment:
* fix diff bug in SubversionPecl adaptor
* add basic proxy adaptor for quickie hack via codereview-proxy
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/Subversion.php (modified) (history)
  • /trunk/extensions/CodeReview/svnImport.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -73,3 +73,8 @@
7474
7575 $wgSpecialPages['Code'] = 'SpecialCode';
7676 $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 @@
66 protected $mRepo;
77
88 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' ) ) {
1013 return new SubversionPecl( $repo );
1114 } else {
1215 return new SubversionShell( $repo );
@@ -47,7 +50,6 @@
4851
4952 /**
5053 * Using the SVN PECL extension...
51 - * Untested!
5254 */
5355 class SubversionPecl extends SubversionAdaptor {
5456 function getFile( $path, $rev=null ) {
@@ -59,15 +61,19 @@
6062 $this->mRepo . $path, $rev1,
6163 $this->mRepo . $path, $rev2 );
6264
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");
6777 }
68 - fclose( $fout );
69 - fclose( $ferr );
70 -
71 - return $out;
7278 }
7379
7480 function getLog( $path, $startRev=null, $endRev=null ) {
@@ -195,3 +201,49 @@
196202 return $out;
197203 }
198204 }
 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 @@
3939 break; // done!
4040 }
4141 $chunkSize = max( 1, floor($chunkSize/4) );
 42+ continue;
4243 } else {
4344 $start += $chunkSize;
4445 }
 46+ if( !is_array( $log ) ) {
 47+ var_dump( $log );
 48+ die( 'wtf' );
 49+ }
4550 foreach( $log as $data ) {
4651 $revCount++;
4752 $delta = microtime( true ) - $startTime;

Status & tagging log