Wikinaut has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/54986


Change subject: (bug 38783) add git HEAD date to Special:Version for core and 
extensions
......................................................................

(bug 38783) add git HEAD date to Special:Version for core and extensions

The information from logs/HEAD contains the last git operation.
That is exactly what is needed. I see how long I didn't check for an update.

Because when I take the date from the commit I always think that
I have to pull for new updates just because there where
no changes for a long time.

The show the exact date of the commit (Dereckson want's this)
would however require connecting to remote within the PHP Skript
-- we assume, that nobody wants this.

The conclusion is:
==================

we show the available date of the last local git operation for core,
and for each extension.

Selected Timestamp ISO format YYYYMMDDHHMMSSZ" to make it compact and
self-explaining.

This is implemented in the present commit.


-------------------------------------------------------------------

Some important comments, worth to be noted here:


Dereckson wrote in https://bugzilla.wikimedia.org/show_bug.cgi?id=38783#c17 :

As I indicated in the Ib66be27a review in December,
I've tested your patch and it doesn't work as intended.

First, the logs/HEAD file contains other operations than commits.
There would have been a need to filter to only process "commit" lines.

But there is a bigger issue:
the patch currently reads the .git/logs/HEAD file.
This won't always contain the information we want.

It contains the operation you did to the git repository (e.g. clone, checkout).

It will only contain the date of the last commit when committed locally.

DaSch answered:

what Dereckson want's is only possible by connecting to remote within the PHP 
Skript.

git information in .git only have local changes.

The information from logs/HEAD contains the last git operation.
And that is exactly what is needed. But only there I see how long I
didn't check for an update. Because when I take the date from the
commit I always think that I have to pull for new updates just because
there where no changes for a long time!

selected Timestamp ISO format YYYYMMDDHHMMSSZ" to make it compact and
self-explaining. I am not in favour/favor of localising this date from git.

Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768
---
M includes/GitInfo.php
M includes/specials/SpecialVersion.php
2 files changed, 45 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/54986/9

diff --git a/includes/GitInfo.php b/includes/GitInfo.php
index 6f7f802..e008f9e 100644
--- a/includes/GitInfo.php
+++ b/includes/GitInfo.php
@@ -121,6 +121,27 @@
        }
 
        /**
+        * Return the date of last log entry in HEAD of the repo
+        * @return string of date or false
+        */
+       public function getHeadDate() {
+
+               $LOGfile = $this->basedir . '/logs/HEAD';
+               if ( !is_readable( $LOGfile ) ) {
+                       return false;
+               }
+               $filearray = file( $LOGfile );
+               $lastline = end( $filearray );
+
+               $lastlinearray = explode( ' ', $lastline );
+               $tempTimezone = date_default_timezone_get();
+               date_default_timezone_set( 'UTC' );
+               $datestring = date( 'YmdHis', $lastlinearray[4] ) . "Z";
+               date_default_timezone_set( $tempTimezone );
+               return $datestring;
+        }
+
+       /**
         * Return the name of the current branch, or HEAD if not found
         * @return string The branch name, HEAD, or false
         */
diff --git a/includes/specials/SpecialVersion.php 
b/includes/specials/SpecialVersion.php
index 81d1781..77f73fe 100644
--- a/includes/specials/SpecialVersion.php
+++ b/includes/specials/SpecialVersion.php
@@ -279,7 +279,7 @@
         * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 
chars. False on failure
         */
        private static function getVersionLinkedGit() {
-               global $IP;
+               global $IP, $wgVersion;
 
                $gitInfo = new GitInfo( $IP );
                $headSHA1 = $gitInfo->getHeadSHA1();
@@ -288,10 +288,17 @@
                }
 
                $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
-               $viewerUrl = $gitInfo->getHeadViewUrl();
-               if ( $viewerUrl !== false ) {
-                       $shortSHA1 = "[$viewerUrl $shortSHA1]";
+
+               $gitHeadUrl = $gitInfo->getHeadViewUrl();
+               if ( $gitHeadUrl !== false ) {
+                       $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
                }
+
+               $gitHeadDate = $gitInfo->getHeadDate();
+               if ( $gitHeadDate !== false ) {
+                       $shortSHA1 .= "<br/>$gitHeadDate";
+               }
+
                return self::getwgVersionLinked() . " $shortSHA1";
        }
 
@@ -475,6 +482,10 @@
                                $gitViewerUrl = $gitInfo->getHeadViewUrl();
                                if ( $gitViewerUrl !== false ) {
                                        $vcsText = "[$gitViewerUrl $vcsText]";
+                               }
+                               $gitHeadDate = $gitInfo->getHeadDate();
+                               if ( $gitHeadDate !== false ) {
+                                       $vcsText .= "<br/>$gitHeadDate";
                                }
                        } else {
                                $svnInfo = self::getSvnInfo( dirname( 
$extension['path'] ) );
@@ -780,6 +791,15 @@
        }
 
        /**
+        * @param $dir String: directory of the git checkout
+        * @return bool|String date of commit HEAD points to
+        */
+       public static function getGitHeadDate( $dir ) {
+               $repo = new GitInfo( $dir );
+               return $repo->getHeadDate();
+       }
+
+       /**
         * Get the list of entry points and their URLs
         * @return string Wikitext
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/54986
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Wikinaut <[email protected]>
Gerrit-Reviewer: DaSch <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to