Index: trunk/extensions/ExtensionDistributor/ExtensionDistributorGit.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ExtensionDistributorGit extends ExtensionDistributorVCS { |
| 5 | + |
| 6 | + /** |
| 7 | + * @param $dir string |
| 8 | + * @return Status |
| 9 | + */ |
| 10 | + public function updateAndGetVersion( $dir ) { |
| 11 | + if ( !chdir( $dir ) ) { |
| 12 | + return Status::newFatal( 'extdist-git-invalid-dir' ); |
| 13 | + } |
| 14 | + // Is -q (quiet) enough? |
| 15 | + $cmd = "git pull -q 2>&1"; |
| 16 | + $retval = -1; |
| 17 | + |
| 18 | + $result = wfShellExec( $cmd, $retval ); |
| 19 | + |
| 20 | + if ( $retval ) { |
| 21 | + return Status::newFatal( 'extdist-git-error', $result ); |
| 22 | + } |
| 23 | + |
| 24 | + // Determine last changed revision |
| 25 | + $cmd = "git rev-parse HEAD"; |
| 26 | + $retval = -1; |
| 27 | + $result = wfShellExec( $cmd, $retval ); |
| 28 | + |
| 29 | + if ( $retval ) { |
| 30 | + return Status::newFatal( 'extdist-git-error', $result ); |
| 31 | + } |
| 32 | + |
| 33 | + // Trim trailing whitespace |
| 34 | + $result = rtrim( $result ); |
| 35 | + |
| 36 | + // Check it looks like a SHA1 hash |
| 37 | + if ( !preg_match( '/^[0-9a-f]{40}$/i', $result ) ) { |
| 38 | + return Status::newFatal( 'extdist-git-invalidsha1', $result ); |
| 39 | + } |
| 40 | + |
| 41 | + return Status::newGood( $result ); |
| 42 | + } |
| 43 | +} |
Property changes on: trunk/extensions/ExtensionDistributor/ExtensionDistributorGit.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 44 | + native |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributorSVN.php |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ExtensionDistributorSVN extends ExtensionDistributorVCS { |
| 5 | + |
| 6 | + /** |
| 7 | + * @param $dir string |
| 8 | + * @return Status |
| 9 | + */ |
| 10 | + public function updateAndGetVersion( $dir ) { |
| 11 | + $cmd = "svn up --non-interactive " . wfEscapeShellArg( $dir ) . " 2>&1"; |
| 12 | + $retval = -1; |
| 13 | + |
| 14 | + $result = wfShellExec( $cmd, $retval ); |
| 15 | + |
| 16 | + if ( $retval ) { |
| 17 | + return Status::newFatal( 'extdist-svn-error', $result ); |
| 18 | + } |
| 19 | + |
| 20 | + // Determine last changed revision |
| 21 | + $cmd = "svn info --non-interactive --xml " . wfEscapeShellArg( $dir ); |
| 22 | + $retval = -1; |
| 23 | + $result = wfShellExec( $cmd, $retval ); |
| 24 | + |
| 25 | + if ( $retval ) { |
| 26 | + return Status::newFatal( 'extdist-svn-error', $result ); |
| 27 | + } |
| 28 | + |
| 29 | + $sx = new SimpleXMLElement( $result ); |
| 30 | + $rev = $sx->entry->commit['revision']; |
| 31 | + |
| 32 | + if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) { |
| 33 | + return Status::newFatal( 'extdist-svn-parse-error', $result ); |
| 34 | + } |
| 35 | + |
| 36 | + return Status::newGood( $rev ); |
| 37 | + } |
| 38 | +} |
Property changes on: trunk/extensions/ExtensionDistributor/ExtensionDistributorSVN.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 39 | + native |
Index: trunk/extensions/ExtensionDistributor/cron.php |
— | — | @@ -35,18 +35,65 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | // Update the files |
39 | | - svnUpdate( "$wgExtDistWorkingCopy/trunk/extensions" ); |
| 39 | + vcsUpdate( "$wgExtDistWorkingCopy/trunk/extensions" ); |
| 40 | + |
40 | 41 | foreach ( glob( "$wgExtDistWorkingCopy/branches/*", GLOB_ONLYDIR ) as $branch ) { |
41 | | - svnUpdate( "$branch/extensions" ); |
| 42 | + vcsUpdate( "$branch/extensions" ); |
42 | 43 | } |
43 | 44 | } |
44 | 45 | |
| 46 | +/** |
| 47 | + * @param $dir string |
| 48 | + * @return bool |
| 49 | + */ |
| 50 | +function isSVNDir( $dir ) { |
| 51 | + return is_dir( "$dir/.svn"); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * @param $dir string |
| 56 | + * @return bool |
| 57 | + */ |
| 58 | +function isGitDir( $dir ) { |
| 59 | + return is_dir( "$dir/.git"); |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * @param $dir string |
| 64 | + */ |
| 65 | +function vcsUpdate( $dir ) { |
| 66 | + if ( isSVNDir( $dir ) ) { |
| 67 | + svnUpdate( $dir ); |
| 68 | + } elseif ( isGitDir( $dir ) ) { |
| 69 | + gitUpdate( $dir ); |
| 70 | + } else { |
| 71 | + // Meh? |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +/** |
| 76 | + * @param $path string |
| 77 | + */ |
45 | 78 | function svnUpdate( $path ) { |
46 | 79 | $cmd = "svn up --non-interactive " . escapeshellarg( $path ); |
47 | | - $retval = 1; |
| 80 | + $retval = -1; |
48 | 81 | system( $cmd, $retval ); |
49 | 82 | if ( $retval ) { |
50 | 83 | echo "Error executing command: $cmd\n"; |
51 | 84 | exit( 1 ); |
52 | 85 | } |
53 | 86 | } |
| 87 | + |
| 88 | +/** |
| 89 | + * @param $path string |
| 90 | + */ |
| 91 | +function gitUpdate( $path ) { |
| 92 | + chdir( $path ); |
| 93 | + $cmd = "git pull -q"; |
| 94 | + $retval = -1; |
| 95 | + system( $cmd, $retval ); |
| 96 | + if ( $retval ) { |
| 97 | + echo "Error executing command: $cmd\n"; |
| 98 | + exit( 1 ); |
| 99 | + } |
| 100 | +} |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributorVCS.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class ExtensionDistributorVCS { |
| 5 | + |
| 6 | + /** |
| 7 | + * @param $vcs string |
| 8 | + * @return ExtensionDistributorGIT|ExtensionDistributorSVN|null |
| 9 | + */ |
| 10 | + public static function factory( $vcs ) { |
| 11 | + if ( $vcs === 'svn' ) { |
| 12 | + return new ExtensionDistributorSVN; |
| 13 | + } elseif ( $vcs === 'git' ) { |
| 14 | + return new ExtensionDistributorGit; |
| 15 | + } |
| 16 | + return null; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * @abstract |
| 21 | + * @param $dir string |
| 22 | + * @return Status |
| 23 | + */ |
| 24 | + abstract function updateAndGetVersion( $dir ); |
| 25 | +} |
Property changes on: trunk/extensions/ExtensionDistributor/ExtensionDistributorVCS.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor_body.php |
— | — | @@ -223,10 +223,11 @@ |
224 | 224 | global $wgExtDistWorkingCopy, $wgExtDistTarDir, $wgExtDistBranches, |
225 | 225 | $wgOut, $wgExtDistTarUrl, $wgExtDistRemoteClient; |
226 | 226 | |
| 227 | + $vcs = isset( $wgExtDistBranches[$version]['vcs'] ) ? $wgExtDistBranches[$version]['vcs'] : 'svn'; |
227 | 228 | if ( $wgExtDistRemoteClient ) { |
228 | | - $rev = $this->updateAndGetRevisionRemote( $extension, $version ); |
| 229 | + $rev = $this->updateAndGetRevisionRemote( $extension, $version, $vcs ); |
229 | 230 | } else { |
230 | | - $rev = $this->updateAndGetRevisionLocal( $extension, $version ); |
| 231 | + $rev = $this->updateAndGetRevisionLocal( $extension, $version, $vcs ); |
231 | 232 | } |
232 | 233 | |
233 | 234 | if ( $rev === false ) { |
— | — | @@ -286,54 +287,45 @@ |
287 | 288 | /** |
288 | 289 | * @param $extension string |
289 | 290 | * @param $version string |
| 291 | + * @param $vcs string Version control system to use for branch |
290 | 292 | * @return bool|string |
291 | 293 | */ |
292 | | - protected function updateAndGetRevisionLocal( $extension, $version ) { |
| 294 | + protected function updateAndGetRevisionLocal( $extension, $version, $vcs ) { |
293 | 295 | global $wgExtDistWorkingCopy, $wgOut; |
294 | 296 | |
295 | 297 | // svn up |
296 | 298 | $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension"; |
297 | 299 | |
298 | | - $cmd = "svn up --non-interactive " . wfEscapeShellArg( $dir ) . " 2>&1"; |
299 | | - $retval = - 1; |
300 | | - |
301 | | - $result = wfShellExec( $cmd, $retval ); |
302 | | - |
303 | | - if ( $retval ) { |
304 | | - $wgOut->addWikiMsg( 'extdist-svn-error', $result ); |
| 300 | + $ed = ExtensionDistributorVCS::factory( $vcs ); |
| 301 | + if ( $ed === null ) { |
| 302 | + $wgOut->addWikiMsg( 'extdist-cvs-unsupported', $vcs ); |
305 | 303 | return false; |
306 | 304 | } |
307 | 305 | |
308 | | - // Determine last changed revision |
309 | | - $cmd = "svn info --non-interactive --xml " . wfEscapeShellArg( $dir ); |
310 | | - $retval = - 1; |
311 | | - $result = wfShellExec( $cmd, $retval ); |
312 | | - |
313 | | - if ( $retval ) { |
314 | | - $wgOut->addWikiMsg( 'extdist-svn-error', $result ); |
| 306 | + $result = $ed->updateAndGetVersion( $dir ); |
| 307 | + if ( !$result->isGood() ) { |
| 308 | + $this->getOutput()->addWikiText( $result->getWikiText() ); |
315 | 309 | return false; |
316 | 310 | } |
317 | | - |
318 | | - $sx = new SimpleXMLElement( $result ); |
319 | | - $rev = $sx->entry->commit['revision']; |
320 | | - |
321 | | - if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) { |
322 | | - $wgOut->addWikiMsg( 'extdist-svn-parse-error', $result ); |
323 | | - return false; |
324 | | - } |
325 | | - |
326 | | - return $rev; |
| 311 | + return $result->value; |
327 | 312 | } |
328 | 313 | |
329 | 314 | /** |
330 | 315 | * @param $extension string |
331 | 316 | * @param $version string |
| 317 | + * @param $vcs string Version control system to use for branch |
332 | 318 | * @return bool|string |
333 | 319 | */ |
334 | | - protected function updateAndGetRevisionRemote( $extension, $version ) { |
| 320 | + protected function updateAndGetRevisionRemote( $extension, $version, $vcs ) { |
335 | 321 | global $wgExtDistRemoteClient, $wgOut; |
336 | 322 | |
337 | | - $cmd = json_encode( array( 'extension' => $extension, 'version' => $version ) ); |
| 323 | + $cmd = json_encode( |
| 324 | + array( |
| 325 | + 'extension' => $extension, |
| 326 | + 'version' => $version, |
| 327 | + 'vcs' => $vcs |
| 328 | + ) |
| 329 | + ); |
338 | 330 | $cmd = str_replace( "\000", '', $cmd ); |
339 | 331 | |
340 | 332 | list( $host, $port ) = explode( ':', $wgExtDistRemoteClient, 2 ); |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor.i18n.php |
— | — | @@ -26,6 +26,8 @@ |
27 | 27 | 'extdist-remote-invalid-response' => 'Invalid response from remote subversion client.', |
28 | 28 | 'extdist-svn-error' => 'Subversion encountered an error: <pre>$1</pre>', |
29 | 29 | 'extdist-svn-parse-error' => 'Unable to process the XML from "svn info": <pre>$1</pre>', |
| 30 | + 'extdist-git-error' => 'Git encountered an error: <pre>$1</pre>', |
| 31 | + 'extdist-git-invalidsha1' => 'Git returned an invalid SHA1 hash for the current revision: <pre>$1<pre>', |
30 | 32 | 'extdist-tar-error' => 'Tar returned exit code $1:', |
31 | 33 | 'extdist-created' => "A snapshot of version <b>$2</b> of the <b>$1</b> extension for MediaWiki <b>$3</b> has been created. Your download should start automatically in 5 seconds. |
32 | 34 | |
— | — | @@ -47,6 +49,8 @@ |
48 | 50 | |
49 | 51 | If you have any questions about this extension distribution system, please go to [[Extension talk:ExtensionDistributor]].", |
50 | 52 | 'extdist-want-more' => 'Get another extension', |
| 53 | + 'extdist-cvs-unsupported' => 'Extension Distributor doesn\'t support the "$1" version control system.', |
| 54 | + 'extdist-git-invalid-dir' => 'Unable to enter directory for git checkout', |
51 | 55 | ); |
52 | 56 | |
53 | 57 | /** Message documentation (Message documentation) |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor.php |
— | — | @@ -49,3 +49,6 @@ |
50 | 50 | $wgSpecialPages['ExtensionDistributor'] = 'ExtensionDistributorPage'; |
51 | 51 | $wgSpecialPageGroups['ExtensionDistributor'] = 'developer'; |
52 | 52 | $wgAutoloadClasses['ExtensionDistributorPage'] = $dir . 'ExtensionDistributor_body.php'; |
| 53 | +$wgAutoloadClasses['ExtensionDistributorSVN'] = $dir . 'ExtensionDistributorSVN.php'; |
| 54 | +$wgAutoloadClasses['ExtensionDistributorVCS'] = $dir . 'ExtensionDistributorVCS.php'; |
| 55 | +$wgAutoloadClasses['ExtensionDistributorGit'] = $dir . 'ExtensionDistributorGit.php'; |