r113815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113814‎ | r113815 | r113816 >
Date:16:00, 14 March 2012
Author:reedy
Status:ok
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/ExtensionDistributor/svn-invoker.php
@@ -18,7 +18,7 @@
1919 }
2020 require( $confFile );
2121
22 -svnExecute();
 22+executeInvoker();
2323
2424 /**
2525 * @param $s string
@@ -50,7 +50,7 @@
5151 echo json_encode( array( 'error' => $msg, 'errorInfo' => $info ) );
5252 }
5353
54 -function svnExecute() {
 54+function executeInvoker() {
5555 global $wgExtDistWorkingCopy, $wgExtDistLockFile;
5656
5757 $encCommand = '';
@@ -100,21 +100,46 @@
101101 invokerError( 'extdist-remote-error', "Invalid extension parameter" );
102102 return;
103103 }
 104+
104105 $version = $command->version;
105106 $extension = $command->extension;
106107 $vcs = $command->vcs;
 108+ if ( !in_array( $vcs, array( 'git', 'svn' ) ) ) {
 109+ invokerError( 'extdist-remote-error', "Invalid vcs parameter" );
 110+ return;
 111+ }
 112+
107113 $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension";
108114
 115+ $remoteRev = null;
 116+ if ( $vcs === 'svn' ) {
 117+ $remoteRev = svnExecute( $dir );
 118+ } elseif( $vcs === 'git' ) {
 119+ $remoteRev = gitExecute( $dir );
 120+ }
 121+
 122+ if ( $remoteRev === null ) {
 123+ return;
 124+ }
 125+
 126+ echo json_encode( array( 'revision' => $remoteRev ) );
 127+}
 128+
 129+/**
 130+ * @param $dir string
 131+ * @return null|string
 132+ */
 133+function svnExecute( $dir ) {
109134 // Determine last changed revision in the checkout
110135 $localRev = svnGetRev( $dir, $remoteDir );
111136 if ( !$localRev ) {
112 - return;
 137+ return null;
113138 }
114139
115140 // Determine last changed revision in the repo
116141 $remoteRev = svnGetRev( $remoteDir );
117142 if ( !$remoteRev ) {
118 - return;
 143+ return null;
119144 }
120145
121146 if ( $remoteRev != $localRev ) {
@@ -124,11 +149,10 @@
125150 $result = invokerShellExec( $cmd, $retval );
126151 if ( $retval ) {
127152 invokerError( 'extdist-svn-error', $result );
128 - return;
 153+ return null;
129154 }
130155 }
131 -
132 - echo json_encode( array( 'revision' => $remoteRev ) );
 156+ return $remoteRev;
133157 }
134158
135159 /**
@@ -164,6 +188,33 @@
165189
166190 /**
167191 * @param $dir string
 192+ * @return null|string
 193+ */
 194+function gitExecute( $dir ) {
 195+ $localRev = gitGetRev( $dir );
 196+ if ( !$localRev ) {
 197+ return null;
 198+ }
 199+
 200+ // TODO: Need to check remote before attempting update, bit daft unconditionally pulling
 201+ chdir( $dir );
 202+ $cmd = "git pull -q";
 203+ $retval = -1;
 204+ $result = invokerShellExec( $cmd, $retval );
 205+ if ( $retval ) {
 206+ invokerError( 'extdist-svn-error', $result );
 207+ return null;
 208+ }
 209+
 210+ $newLocalRev = gitGetRev( $dir );
 211+ if ( !$newLocalRev ) {
 212+ return null;
 213+ }
 214+ return $newLocalRev;
 215+}
 216+
 217+/**
 218+ * @param $dir string
168219 * @return bool|string
169220 */
170221 function gitGetRev( $dir ) {
@@ -188,19 +239,3 @@
189240 // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars?
190241 return $result;
191242 }
192 -
193 -/**
194 - * @param $dir string
195 - * @return bool
196 - */
197 -function isSVNDir( $dir ) {
198 - return is_dir( "$dir/.svn");
199 -}
200 -
201 -/**
202 - * @param $dir string
203 - * @return bool
204 - */
205 -function isGitDir( $dir ) {
206 - return is_dir( "$dir/.svn");
207 -}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r113665Bug 27812 - Make ExtensionDistributor work with Git...reedy20:55, 12 March 2012
r113813Bug 27812 - Make ExtensionDistributor work with Git...reedy15:37, 14 March 2012

Status & tagging log