https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113815

Revision: 113815
Author:   reedy
Date:     2012-03-14 16:00:17 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
Bug 27812 - Make ExtensionDistributor work with Git

Followup r113813, rest of the svn-invoker.php code

Modified Paths:
--------------
    trunk/extensions/ExtensionDistributor/svn-invoker.php

Modified: trunk/extensions/ExtensionDistributor/svn-invoker.php
===================================================================
--- trunk/extensions/ExtensionDistributor/svn-invoker.php       2012-03-14 
15:42:19 UTC (rev 113814)
+++ trunk/extensions/ExtensionDistributor/svn-invoker.php       2012-03-14 
16:00:17 UTC (rev 113815)
@@ -18,7 +18,7 @@
 }
 require( $confFile );
 
-svnExecute();
+executeInvoker();
 
 /**
  * @param $s string
@@ -50,7 +50,7 @@
        echo json_encode( array( 'error' => $msg, 'errorInfo' => $info ) );
 }
 
-function svnExecute() {
+function executeInvoker() {
        global $wgExtDistWorkingCopy, $wgExtDistLockFile;
 
        $encCommand = '';
@@ -100,21 +100,46 @@
                invokerError( 'extdist-remote-error', "Invalid extension 
parameter" );
                return;
        }
+
        $version = $command->version;
        $extension = $command->extension;
        $vcs = $command->vcs;
+       if ( !in_array( $vcs, array( 'git', 'svn' ) ) ) {
+               invokerError( 'extdist-remote-error', "Invalid vcs parameter" );
+               return;
+       }
+
        $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension";
 
+       $remoteRev = null;
+       if ( $vcs === 'svn' ) {
+               $remoteRev = svnExecute( $dir );
+       } elseif( $vcs === 'git' ) {
+               $remoteRev = gitExecute( $dir );
+       }
+
+       if ( $remoteRev === null ) {
+               return;
+       }
+
+       echo json_encode( array( 'revision' => $remoteRev ) );
+}
+
+/**
+ * @param $dir string
+ * @return null|string
+ */
+function svnExecute( $dir ) {
        // Determine last changed revision in the checkout
        $localRev = svnGetRev( $dir, $remoteDir );
        if ( !$localRev ) {
-               return;
+               return null;
        }
 
        // Determine last changed revision in the repo
        $remoteRev = svnGetRev( $remoteDir );
        if ( !$remoteRev ) {
-               return;
+               return null;
        }
 
        if ( $remoteRev != $localRev ) {
@@ -124,11 +149,10 @@
                $result = invokerShellExec( $cmd, $retval );
                if ( $retval ) {
                        invokerError( 'extdist-svn-error', $result );
-                       return;
+                       return null;
                }
        }
-
-       echo json_encode( array( 'revision' => $remoteRev ) );
+       return $remoteRev;
 }
 
 /**
@@ -164,6 +188,33 @@
 
 /**
  * @param $dir string
+ * @return null|string
+ */
+function gitExecute( $dir ) {
+       $localRev = gitGetRev( $dir );
+       if ( !$localRev ) {
+               return null;
+       }
+
+       // TODO: Need to check remote before attempting update, bit daft 
unconditionally pulling
+       chdir( $dir );
+       $cmd = "git pull -q";
+       $retval = -1;
+       $result = invokerShellExec( $cmd, $retval );
+       if ( $retval ) {
+               invokerError( 'extdist-svn-error', $result );
+               return null;
+       }
+
+       $newLocalRev = gitGetRev( $dir );
+       if ( !$newLocalRev ) {
+               return null;
+       }
+       return $newLocalRev;
+}
+
+/**
+ * @param $dir string
  * @return bool|string
  */
 function gitGetRev( $dir ) {
@@ -188,19 +239,3 @@
        // TODO: Should we truncate the 40 character sha1 hash to a more 
common/usable 7 chars?
        return $result;
 }
-
-/**
- * @param $dir string
- * @return bool
- */
-function isSVNDir( $dir ) {
-       return is_dir( "$dir/.svn");
-}
-
-/**
- * @param $dir string
- * @return bool
- */
-function isGitDir( $dir ) {
-       return is_dir( "$dir/.svn");
-}


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to