Index: trunk/extensions/ExtensionDistributor/svn-invoker.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | } |
20 | 20 | require( $confFile ); |
21 | 21 | |
22 | | -svnExecute(); |
| 22 | +executeInvoker(); |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @param $s string |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | echo json_encode( array( 'error' => $msg, 'errorInfo' => $info ) ); |
52 | 52 | } |
53 | 53 | |
54 | | -function svnExecute() { |
| 54 | +function executeInvoker() { |
55 | 55 | global $wgExtDistWorkingCopy, $wgExtDistLockFile; |
56 | 56 | |
57 | 57 | $encCommand = ''; |
— | — | @@ -100,21 +100,46 @@ |
101 | 101 | invokerError( 'extdist-remote-error', "Invalid extension parameter" ); |
102 | 102 | return; |
103 | 103 | } |
| 104 | + |
104 | 105 | $version = $command->version; |
105 | 106 | $extension = $command->extension; |
106 | 107 | $vcs = $command->vcs; |
| 108 | + if ( !in_array( $vcs, array( 'git', 'svn' ) ) ) { |
| 109 | + invokerError( 'extdist-remote-error', "Invalid vcs parameter" ); |
| 110 | + return; |
| 111 | + } |
| 112 | + |
107 | 113 | $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension"; |
108 | 114 | |
| 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 ) { |
109 | 134 | // Determine last changed revision in the checkout |
110 | 135 | $localRev = svnGetRev( $dir, $remoteDir ); |
111 | 136 | if ( !$localRev ) { |
112 | | - return; |
| 137 | + return null; |
113 | 138 | } |
114 | 139 | |
115 | 140 | // Determine last changed revision in the repo |
116 | 141 | $remoteRev = svnGetRev( $remoteDir ); |
117 | 142 | if ( !$remoteRev ) { |
118 | | - return; |
| 143 | + return null; |
119 | 144 | } |
120 | 145 | |
121 | 146 | if ( $remoteRev != $localRev ) { |
— | — | @@ -124,11 +149,10 @@ |
125 | 150 | $result = invokerShellExec( $cmd, $retval ); |
126 | 151 | if ( $retval ) { |
127 | 152 | invokerError( 'extdist-svn-error', $result ); |
128 | | - return; |
| 153 | + return null; |
129 | 154 | } |
130 | 155 | } |
131 | | - |
132 | | - echo json_encode( array( 'revision' => $remoteRev ) ); |
| 156 | + return $remoteRev; |
133 | 157 | } |
134 | 158 | |
135 | 159 | /** |
— | — | @@ -164,6 +188,33 @@ |
165 | 189 | |
166 | 190 | /** |
167 | 191 | * @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 |
168 | 219 | * @return bool|string |
169 | 220 | */ |
170 | 221 | function gitGetRev( $dir ) { |
— | — | @@ -188,19 +239,3 @@ |
189 | 240 | // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars? |
190 | 241 | return $result; |
191 | 242 | } |
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 | | -} |