r113813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113812‎ | r113813 | r113814 >
Date:15:37, 14 March 2012
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Bug 27812 - Make ExtensionDistributor work with Git

Added gitGetRev and possibly unneeded isGitDir/isSvnDir from cron.php. Soem refactoring of method names

Still need to actually make use of the git code in svn-invoker.php

Followup r113665

TODO: Return more useful first 7 chars of SHA1 hash (what github etc do), rather than 40?
Modified paths:
  • /trunk/extensions/ExtensionDistributor/ExtensionDistributor.php (modified) (history)
  • /trunk/extensions/ExtensionDistributor/ExtensionDistributorGit.php (modified) (history)
  • /trunk/extensions/ExtensionDistributor/svn-invoker.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ExtensionDistributor/ExtensionDistributorGit.php
@@ -37,6 +37,7 @@
3838 return Status::newFatal( 'extdist-git-invalidsha1', $result );
3939 }
4040
 41+ // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars?
4142 return Status::newGood( $result );
4243 }
4344 }
Index: trunk/extensions/ExtensionDistributor/svn-invoker.php
@@ -33,7 +33,7 @@
3434 * @param $retval
3535 * @return string
3636 */
37 -function svnShellExec( $cmd, &$retval ) {
 37+function invokerShellExec( $cmd, &$retval ) {
3838 $retval = 1; // error by default?
3939 ob_start();
4040 passthru( $cmd, $retval );
@@ -46,7 +46,7 @@
4747 * @param $msg
4848 * @param bool $info
4949 */
50 -function svnError( $msg, $info = false ) {
 50+function invokerError( $msg, $info = false ) {
5151 echo json_encode( array( 'error' => $msg, 'errorInfo' => $info ) );
5252 }
5353
@@ -65,14 +65,14 @@
6666 $encCommand .= $buf;
6767 }
6868 if ( !$encCommand ) {
69 - svnError( 'extdist-remote-error', "Invalid command." );
 69+ invokerError( 'extdist-remote-error', "Invalid command." );
7070 return;
7171 }
7272
7373 if ( $wgExtDistLockFile ) {
7474 $lockFile = fopen( $wgExtDistLockFile, 'a' );
7575 if ( !$lockFile ) {
76 - svnError( 'extdist-remote-error', "Unable to open lock file." );
 76+ invokerError( 'extdist-remote-error', "Unable to open lock file." );
7777 return;
7878 }
7979 $timeout = 3;
@@ -83,25 +83,26 @@
8484 sleep( 1 );
8585 }
8686 if ( $i == $timeout ) {
87 - svnError( 'extdist-remote-error', "Lock wait timeout." );
 87+ invokerError( 'extdist-remote-error', "Lock wait timeout." );
8888 return;
8989 }
9090 }
9191
9292 $command = json_decode( $encCommand );
93 - if ( !isset( $command->version ) || !isset( $command->extension ) ) {
94 - svnError( 'extdist-remote-error', "Missing version or extension parameter." );
 93+ if ( !isset( $command->version ) || !isset( $command->extension ) || !isset( $command->vcs ) ) {
 94+ invokerError( 'extdist-remote-error', "Missing version, extension or vcs parameter." );
9595 return;
9696 }
9797 if ( !svnValidate( $command->version ) ) {
98 - svnError( 'extdist-remote-error', "Invalid version parameter" );
 98+ invokerError( 'extdist-remote-error', "Invalid version parameter" );
9999 return;
100100 } elseif ( !svnValidate( $command->extension ) ) {
101 - svnError( 'extdist-remote-error', "Invalid extension parameter" );
 101+ invokerError( 'extdist-remote-error', "Invalid extension parameter" );
102102 return;
103103 }
104104 $version = $command->version;
105105 $extension = $command->extension;
 106+ $vcs = $command->vcs;
106107 $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension";
107108
108109 // Determine last changed revision in the checkout
@@ -119,10 +120,10 @@
120121 if ( $remoteRev != $localRev ) {
121122 // Bad luck, we need to svn up
122123 $cmd = "svn up --non-interactive " . escapeshellarg( $dir ) . " 2>&1";
123 - $retval = - 1;
124 - $result = svnShellExec( $cmd, $retval );
 124+ $retval = -1;
 125+ $result = invokerShellExec( $cmd, $retval );
125126 if ( $retval ) {
126 - svnError( 'extdist-svn-error', $result );
 127+ invokerError( 'extdist-svn-error', $result );
127128 return;
128129 }
129130 }
@@ -138,12 +139,11 @@
139140 * @return bool|string
140141 */
141142 function svnGetRev( $dir, &$url = null ) {
142 -
143143 $cmd = "svn info --non-interactive --xml " . escapeshellarg( $dir );
144 - $retval = - 1;
145 - $result = svnShellExec( $cmd, $retval );
 144+ $retval = -1;
 145+ $result = invokerShellExec( $cmd, $retval );
146146 if ( $retval ) {
147 - svnError( 'extdist-svn-error', $result );
 147+ invokerError( 'extdist-svn-error', $result );
148148 return false;
149149 }
150150
@@ -155,9 +155,52 @@
156156 $rev = false;
157157 }
158158 if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) {
159 - svnError( 'extdist-svn-parse-error', $result );
 159+ invokerError( 'extdist-svn-parse-error', $result );
160160 return false;
161161 }
162162
163163 return $rev;
164164 }
 165+
 166+/**
 167+ * @param $dir string
 168+ * @return bool|string
 169+ */
 170+function gitGetRev( $dir ) {
 171+ chdir( $dir );
 172+ $cmd = "git rev-parse HEAD";
 173+ $retval = -1;
 174+ $result = invokerShellExec( $cmd, $retval );
 175+ if ( $retval ) {
 176+ invokerError( 'extdist-git-error', $result );
 177+ return false;
 178+ }
 179+
 180+ // Trim trailing whitespace
 181+ $result = rtrim( $result );
 182+
 183+ // Check it looks like a SHA1 hash
 184+ if ( !preg_match( '/^[0-9a-f]{40}$/i', $result ) ) {
 185+ invokerError( 'extdist-git-invalidsha1', $result );
 186+ return false;
 187+ }
 188+
 189+ // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars?
 190+ return $result;
 191+}
 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+}
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor.php
@@ -8,7 +8,7 @@
99 $wgExtensionCredits['specialpage'][] = array(
1010 'path' => __FILE__,
1111 'name' => 'Extension Distributor',
12 - 'author' => 'Tim Starling',
 12+ 'author' => array( 'Tim Starling', 'Sam Reed' ),
1313 'url' => 'https://www.mediawiki.org/wiki/Extension:ExtensionDistributor',
1414 'descriptionmsg' => 'extensiondistributor-desc',
1515 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r113815Bug 27812 - Make ExtensionDistributor work with Git...reedy16:00, 14 March 2012

Past revisions this follows-up on

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

Comments

#Comment by 😂 (talk | contribs)   05:14, 21 March 2012

On those todos: For display we'll probably want to use the 7-character version. For actual version comparison, the full sha1 should be used.

Status & tagging log