diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /maintenance/checkSyntax.php | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'maintenance/checkSyntax.php')
-rw-r--r-- | maintenance/checkSyntax.php | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/maintenance/checkSyntax.php b/maintenance/checkSyntax.php index cc4e5af5..0a22f58c 100644 --- a/maintenance/checkSyntax.php +++ b/maintenance/checkSyntax.php @@ -21,8 +21,13 @@ * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once( __DIR__ . '/Maintenance.php' ); +/** + * Maintenance script to check syntax of all PHP files in MediaWiki. + * + * @ingroup Maintenance + */ class CheckSyntax extends Maintenance { // List of files we're going to check @@ -36,7 +41,7 @@ class CheckSyntax extends Maintenance { $this->addOption( 'path', 'Specific path (file or directory) to check, either with absolute path or relative to the root of this MediaWiki installation', false, true ); $this->addOption( 'list-file', 'Text file containing list of files or directories to check', false, true ); - $this->addOption( 'modified', 'Check only files that were modified (requires SVN command-line client)' ); + $this->addOption( 'modified', 'Check only files that were modified (requires Git command-line client)' ); $this->addOption( 'syntax-only', 'Check for syntax validity only, skip code style warnings' ); } @@ -114,18 +119,10 @@ class CheckSyntax extends Maintenance { fclose( $f ); return; } elseif ( $this->hasOption( 'modified' ) ) { - $this->output( "Retrieving list from Subversion... " ); - $parentDir = wfEscapeShellArg( dirname( __FILE__ ) . '/..' ); - $retval = null; - $output = wfShellExec( "svn status --ignore-externals $parentDir", $retval ); - if ( $retval ) { - $this->error( "Error retrieving list from Subversion!\n", true ); - } else { - $this->output( "done\n" ); - } - - preg_match_all( '/^\s*[AM].{7}(.*?)\r?$/m', $output, $matches ); - foreach ( $matches[1] as $file ) { + $this->output( "Retrieving list from Git... " ); + $files = $this->getGitModifiedFiles( $IP ); + $this->output( "done\n" ); + foreach ( $files as $file ) { if ( $this->isSuitableFile( $file ) && !is_dir( $file ) ) { $this->mFiles[] = $file; } @@ -164,6 +161,59 @@ class CheckSyntax extends Maintenance { } /** + * Returns a list of tracked files in a Git work tree differing from the master branch. + * @param $path string: Path to the repository + * @return array: Resulting list of changed files + */ + private function getGitModifiedFiles( $path ) { + + global $wgMaxShellMemory; + + if ( !is_dir( "$path/.git" ) ) { + $this->error( "Error: Not a Git repository!\n", true ); + } + + // git diff eats memory. + $oldMaxShellMemory = $wgMaxShellMemory; + if ( $wgMaxShellMemory < 1024000 ) { + $wgMaxShellMemory = 1024000; + } + + $ePath = wfEscapeShellArg( $path ); + + // Find an ancestor in common with master (rather than just using its HEAD) + // to prevent files only modified there from showing up in the list. + $cmd = "cd $ePath && git merge-base master HEAD"; + $retval = 0; + $output = wfShellExec( $cmd, $retval ); + if ( $retval !== 0 ) { + $this->error( "Error retrieving base SHA1 from Git!\n", true ); + } + + // Find files in the working tree that changed since then. + $eBase = wfEscapeShellArg( rtrim( $output, "\n" ) ); + $cmd = "cd $ePath && git diff --name-only --diff-filter AM $eBase"; + $retval = 0; + $output = wfShellExec( $cmd, $retval ); + if ( $retval !== 0 ) { + $this->error( "Error retrieving list from Git!\n", true ); + } + + $wgMaxShellMemory = $oldMaxShellMemory; + + $arr = array(); + $filename = strtok( $output, "\n" ); + while ( $filename !== false ) { + if ( $filename !== '' ) { + $arr[] = "$path/$filename"; + } + $filename = strtok( "\n" ); + } + + return $arr; + } + + /** * Returns true if $file is of a type we can check * @param $file string * @return bool |