r111643 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111642‎ | r111643 | r111644 >
Date:15:40, 16 February 2012
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
(bug 34420) - Special:Version should use git

You can test it using git init in our $IP and do a dummy commit with:
git commit -a RELEASE-NOTES-1.19

Then head to Special:Version and look at the magic version number.

This need a backport in REL1_19 / 1.19wmf1 since WMF is going to use
git "soon" (tm).
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -122,6 +122,7 @@
123123 * sha1 xml tag added to XML dump file.
124124 * (bug 33646) Badtitle error page now emits a 400 HTTP status.
125125 * Special:MovePage now has a dropdown menu for namespaces.
 126+* (bug 34420) Special:Version now shows git HEAD sha1 when available
126127
127128 === Bug fixes in 1.19 ===
128129 * $wgUploadNavigationUrl should be used for file redlinks if.
Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -180,37 +180,68 @@
181181
182182 /**
183183 * Return a wikitext-formatted string of the MediaWiki version with a link to
184 - * the SVN revision if available.
 184+ * the SVN revision or the git SHA1 of head if available.
 185+ * Git is prefered over Svn
 186+ * The fallback is just $wgVersion
185187 *
186188 * @return mixed
187189 */
188190 public static function getVersionLinked() {
189 - global $wgVersion, $IP;
 191+ global $wgVersion;
190192 wfProfileIn( __METHOD__ );
191193
 194+ if( $gitVersion = self::getVersionLinkedGit() ) {
 195+ $v = $gitVersion;
 196+ } elseif( $svnVersion = self::getVersionLinkedSvn() ) {
 197+ $v = $svnVersion;
 198+ } else {
 199+ $v = $wgVersion; // fallback
 200+ }
 201+
 202+ wfProfileOut( __METHOD__ );
 203+ return $v;
 204+ }
 205+
 206+ /**
 207+ * @return string wgVersion + a link to subversion revision of svn BASE
 208+ */
 209+ private static function getVersionLinkedSvn() {
 210+ global $wgVersion, $IP;
 211+
192212 $info = self::getSvnInfo( $IP );
 213+ if( !isset( $info['checkout-rev'] ) ) {
 214+ return false;
 215+ }
193216
194 - if ( isset( $info['checkout-rev'] ) ) {
195 - $linkText = wfMsg(
196 - 'version-svn-revision',
197 - isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
198 - $info['checkout-rev']
199 - );
 217+ $linkText = wfMsg(
 218+ 'version-svn-revision',
 219+ isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
 220+ $info['checkout-rev']
 221+ );
200222
201 - if ( isset( $info['viewvc-url'] ) ) {
202 - $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
203 - } else {
204 - $version = "$wgVersion $linkText";
205 - }
 223+ if ( isset( $info['viewvc-url'] ) ) {
 224+ $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
206225 } else {
207 - $version = $wgVersion;
 226+ $version = "$wgVersion $linkText";
208227 }
209228
210 - wfProfileOut( __METHOD__ );
211229 return $version;
212230 }
213231
214232 /**
 233+ * @return false|string wgVersion + HEAD sha1 stripped to the first 7 chars
 234+ */
 235+ private static function getVersionLinkedGit() {
 236+ global $wgVersion, $IP;
 237+ if( ! $sha1 = self::getGitHeadSha1( $IP) ) {
 238+ return false;
 239+ }
 240+ $short_sha1 = substr( $sha1, 0, 7 );
 241+
 242+ return "$wgVersion ($short_sha1)";
 243+ }
 244+
 245+ /**
215246 * Returns an array with the base extension types.
216247 * Type is stored as array key, the message as array value.
217248 *
@@ -678,6 +709,33 @@
679710 }
680711 }
681712
 713+ /**
 714+ * @param $dir String: directory of the git checkout
 715+ * @return false|String sha1 of commit HEAD points to
 716+ */
 717+ public static function getGitHeadSha1( $dir ) {
 718+ $BASEDIR = "{$dir}/.git/";
 719+ $HEADfile = "{$BASEDIR}/HEAD";
 720+
 721+ if( !file_exists( $HEADfile ) ) {
 722+ return false;
 723+ }
 724+
 725+ preg_match( "/ref: (.*)/",
 726+ file_get_contents( $HEADfile), $m );
 727+
 728+ $REFfile = "{$BASEDIR}{$m[1]}";
 729+ if( !file_exists( $REFfile ) ) {
 730+ print "$REFfile doesnot exit?";
 731+ return false;
 732+ }
 733+
 734+ $sha1 = chop(file_get_contents( $REFfile ));
 735+
 736+ return $sha1;
 737+ }
 738+
 739+
682740 function showEasterEgg() {
683741 $rx = $rp = $xe = '';
684742 $alpha = array("", "kbQW", "\$\n()");

Sign-offs

UserFlagDate
Hashartested15:41, 16 February 2012
Werdnatested18:36, 17 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111644remove debug statement from r111643...hashar15:44, 16 February 2012
r112043Improve documentation...reedy21:15, 21 February 2012

Comments

#Comment by Reedy (talk | contribs)   02:17, 17 February 2012

Can probably use something similar for bug 33287 also

#Comment by Werdna (talk | contribs)   18:38, 17 February 2012

Works okay, but feels a bit fragile in its assumption that $IP is the directory that's checked out directly.

#Comment by Krinkle (talk | contribs)   23:11, 22 February 2012

Hm.. yeah, git only has one .git directory in the repo root. Not in every subdirectory.

But on the other hand, Git doesn't support sparse checkouts, so we're safe since phase3 will be a repo, right ?

#Comment by Tim Starling (talk | contribs)   23:05, 22 February 2012

It only needs a 1.19wmf1 backport if we're going to use that exact branch with git and not make a new one from trunk.

#Comment by RobLa-WMF (talk | contribs)   23:12, 22 February 2012

Good point

Status & tagging log