r41582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41581‎ | r41582 | r41583 >
Date:00:21, 3 October 2008
Author:brion
Status:old
Tags:
Comment:
add in the local svn command version just to test; we seem to get some perf problems with the diffing using the plugin, maybe we can work around it or debug it easier
Modified paths:
  • /trunk/tools/codereview-proxy/index.php (modified) (history)

Diff [purge]

Index: trunk/tools/codereview-proxy/index.php
@@ -53,7 +53,7 @@
5454 if( function_exists( 'svn_log' ) ) {
5555 return new SubversionPecl( $repo );
5656 } else {
57 - throw new Exception("Requires SVN pecl module" );
 57+ return new SubversionShell( $repo );
5858 }
5959 }
6060
@@ -125,3 +125,122 @@
126126 $this->_rev( $endRev, SVN_REVISION_HEAD ) );
127127 }
128128 }
 129+
 130+/**
 131+ * Using the thingy-bobber
 132+ */
 133+class SubversionShell extends SubversionAdaptor {
 134+ function getFile( $path, $rev=null ) {
 135+ if( $rev )
 136+ $path .= "@$rev";
 137+ $command = sprintf(
 138+ "svn cat %s",
 139+ escapeshellarg( $this->mRepo . $path ) );
 140+
 141+ return shell_exec( $command );
 142+ }
 143+
 144+ function getDiff( $path, $rev1, $rev2 ) {
 145+ $command = sprintf(
 146+ "svn diff -r%d:%d %s",
 147+ intval( $rev1 ),
 148+ intval( $rev2 ),
 149+ escapeshellarg( $this->mRepo . $path ) );
 150+
 151+ return shell_exec( $command );
 152+ }
 153+
 154+ function getLog( $path, $startRev=null, $endRev=null ) {
 155+ $command = sprintf(
 156+ "svn log -v -r%s:%s --non-interactive %s",
 157+ escapeshellarg( $this->_rev( $startRev, 'BASE' ) ),
 158+ escapeshellarg( $this->_rev( $endRev, 'HEAD' ) ),
 159+ escapeshellarg( $this->mRepo . $path ) );
 160+
 161+ $lines = explode( "\n", shell_exec( $command ) );
 162+ $out = array();
 163+
 164+ $divider = str_repeat( '-', 72 );
 165+ $formats = array(
 166+ 'rev' => '/^r(\d+)$/',
 167+ 'author' => '/^(.*)$/',
 168+ 'date' => '/^(.*?) \(.*\)$/',
 169+ 'lines' => '/^(\d+) lines?$/',
 170+ );
 171+ $state = "start";
 172+ foreach( $lines as $line ) {
 173+ $line = rtrim( $line );
 174+
 175+ switch( $state ) {
 176+ case "start":
 177+ if( $line == $divider ) {
 178+ $state = "revdata";
 179+ break;
 180+ } else {
 181+ return $out;
 182+ #throw new Exception( "Unexpected start line: $line" );
 183+ }
 184+ case "revdata":
 185+ if( $line == "" ) {
 186+ $state = "done";
 187+ break;
 188+ }
 189+ $data = array();
 190+ $bits = explode( " | ", $line );
 191+ $i = 0;
 192+ foreach( $formats as $key => $regex ) {
 193+ $text = $bits[$i++];
 194+ if( preg_match( $regex, $text, $matches ) ) {
 195+ $data[$key] = $matches[1];
 196+ } else {
 197+ throw new Exception(
 198+ "Unexpected format for $key in '$text'" );
 199+ }
 200+ }
 201+ $data['msg'] = '';
 202+ $data['paths'] = array();
 203+ $state = 'changedpaths';
 204+ break;
 205+ case "changedpaths":
 206+ if( $line == "Changed paths:" ) {
 207+ $state = "path";
 208+ } elseif( $line == "" ) {
 209+ // No changed paths?
 210+ $state = "msg";
 211+ } else {
 212+ throw new Exception(
 213+ "Expected 'Changed paths:' or '', got '$line'" );
 214+ }
 215+ break;
 216+ case "path":
 217+ if( $line == "" ) {
 218+ // Out of paths. Move on to the message...
 219+ $state = 'msg';
 220+ } else {
 221+ if( preg_match( '/^ (.) (.*)$/', $line, $matches ) ) {
 222+ $data['paths'][] = array(
 223+ 'action' => $matches[1],
 224+ 'path' => $matches[2] );
 225+ }
 226+ }
 227+ break;
 228+ case "msg":
 229+ $data['msg'] .= $line;
 230+ if( --$data['lines'] ) {
 231+ $data['msg'] .= "\n";
 232+ } else {
 233+ unset( $data['lines'] );
 234+ $out[] = $data;
 235+ $state = "start";
 236+ }
 237+ break;
 238+ case "done":
 239+ throw new Exception( "Unexpected input after end: $line" );
 240+ default:
 241+ throw new Exception( "Invalid state '$state'" );
 242+ }
 243+ }
 244+
 245+ return $out;
 246+ }
 247+}

Status & tagging log