[Patch] Link to "current commit vs master" in Preferences footer

Development-related discussion, including bundled plugins
wn_
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 14 Apr 2013, 01:07

[Patch] Link to "current commit vs master" in Preferences footer

Postby wn_ » 04 Feb 2017, 23:28

This patch adds "VERSION_WITH_COMPARE_LINK", which makes the short commit hash a link to comparing against master (e.g. https://tt-rss.org/gitlab/fox/tt-rss/co ... 2...master ), and puts it to use in the Preferences page footer. This is typically something I would do manually to see what's changed since the last update.

If this looks okay my GitLab username is "wn_", and I don't currently have developer privileges. Just let me know if anything needs to be tweaked.

Code: Select all

commit 38d3697800967857d3b67562a0d8fe4163ad2747
Author: wn_ <[email protected]>
Date:   Sat Feb 4 14:05:22 2017 -0600

    Add 'VERSION_WITH_COMPARE_LINK', which includes a link to compare the current commit to master.
   
    Use 'VERSION_WITH_COMPARE_LINK' in the Preferences page footer.

diff --git a/include/version.php b/include/version.php
index bc8e869..a7af431 100644
--- a/include/version.php
+++ b/include/version.php
@@ -1,7 +1,7 @@
 <?php
    define('VERSION_STATIC', '17.1');
 
-   function get_version() {
+   function get_version($compare_master_link = false) {
       date_default_timezone_set('UTC');
       $root_dir = dirname(dirname(__FILE__));
 
@@ -11,26 +11,23 @@
          if ($head) {
             $matches = array();
 
-            if (preg_match("/^ref: (.*)/", $head, $matches)) {
+            if (preg_match('/^ref: (.*)/', $head, $matches)) {
                $ref = $matches[1];
-
-               $suffix = substr(trim(file_get_contents("$root_dir/.git/$ref")), 0, 7);
+               $commit_hash = trim(file_get_contents("$root_dir/.git/$ref"));
                $timestamp = filemtime("$root_dir/.git/$ref");
-
-               define("GIT_VERSION_HEAD", $suffix);
-               define("GIT_VERSION_TIMESTAMP", $timestamp);
-
-               return VERSION_STATIC . " ($suffix)";
-
             } else {
-               $suffix = substr(trim($head), 0, 7);
+               $commit_hash = $head;
                $timestamp = filemtime("$root_dir/.git/HEAD");
+            }
 
-               define("GIT_VERSION_HEAD", $suffix);
-               define("GIT_VERSION_TIMESTAMP", $timestamp);
+            $commit_hash_short = substr($commit_hash, 0, 7);
+            define('GIT_VERSION_HEAD', $commit_hash_short);
+            define('GIT_VERSION_TIMESTAMP', $timestamp);
 
-               return VERSION_STATIC . " ($suffix)";
+            if ($compare_master_link) {
+               return VERSION_STATIC . " (<a href='https://tt-rss.org/gitlab/fox/tt-rss/compare/{$commit_hash}...master'>$commit_hash_short</a>)";
             }
+            return VERSION_STATIC . " ($commit_hash_short)";
          }
       }
 
@@ -39,4 +36,5 @@
    }
 
    define('VERSION', get_version());
+   define('VERSION_WITH_COMPARE_LINK', get_version(true));
 ?>
diff --git a/prefs.php b/prefs.php
index b1cdb0b..141dca6 100644
--- a/prefs.php
+++ b/prefs.php
@@ -161,7 +161,7 @@
    <a class="insensitive" target="_blank" href="http://tt-rss.org/">
    Tiny Tiny RSS</a>
    <?php if (!defined('HIDE_VERSION')) { ?>
-       v<?php echo VERSION ?>
+       v<?php echo VERSION_WITH_COMPARE_LINK ?>
    <?php } ?>
    &copy; 2005-<?php echo date('Y') ?>
    <a class="insensitive" target="_blank"

JustAMacUser
Bear Rating Overlord
Bear Rating Overlord
Posts: 373
Joined: 20 Aug 2013, 23:13

Re: [Patch] Link to "current commit vs master" in Preferences footer

Postby JustAMacUser » 04 Feb 2017, 23:40

GitLab is already pretty heavy on the server, while it's all in fox's control, I wouldn't want that. Sometimes GitLab will actually not do a full comparison because of the load and instead prompt the user if they're sure they want to continue to do that.

Instead, just do this from the terminal:

Code: Select all

$ git remote update

Fetching origin
remote: Counting objects: 91, done.
remote: Compressing objects: 100% (88/88), done.
remote: Total 91 (delta 65), reused 0 (delta 0)
Unpacking objects: 100% (91/91), done.
From git.tt-rss.org:fox/tt-rss
   e3cdbd8..23c8ef7  master     -> origin/master

$ git diff e3cdbd8..23c8ef7
$ git pull


The git remote update brings your local copy up-to-date (without merging the changes into the working copy). You'll notice it already reports the commit range for the difference (e3cdbd8..23c8ef7 master -> origin/master), which lets you copy/paste into git diff e3cdbd8..23c8ef7 and if you're okay with the results you just git pull.

Easy as can be and since it's almost entirely local to your system it doesn't put undue burden on fox's server!

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [Patch] Link to "current commit vs master" in Preferences footer

Postby fox » 04 Feb 2017, 23:56

yeah i don't really see the point of this, also please don't abuse the vm this site runs on, use local git instead

wn_
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 14 Apr 2013, 01:07

Re: [Patch] Link to "current commit vs master" in Preferences footer

Postby wn_ » 05 Feb 2017, 00:06

Hm, okay. I'm familiar with doing this locally, but preferred GitLab's view. I'll definitely stop using GitLab for that if it's killing the server.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [Patch] Link to "current commit vs master" in Preferences footer

Postby fox » 05 Feb 2017, 00:13

its not but there's no reason to make a habit of it, like mentioned above any larger diff is likely going to be incomplete anyway

why bake a useless, and yet resource expensive feature into the ui

disconn3ct
Bear Rating Trainee
Bear Rating Trainee
Posts: 37
Joined: 12 Apr 2013, 15:07

Re: [Patch] Link to "current commit vs master" in Preferences footer

Postby disconn3ct » 05 Feb 2017, 18:51

JustAMacUser wrote:Instead, just do this from the terminal:


As an alternative, I prefer to show commits with patches instead of the overall diff. (and no need to c&p revisions)

Code: Select all

 
 $ git fetch
 $ git show HEAD..origin/master
....
$ git pull
 


There is a way to get it in chronological order (instead of reversed) but I don't think it is as easy as swapping the compare. (Because git..) And diff (instead of show) works the same as the other example.

If you want to annoy fox you can use the github desktop app against your copy of the code to get a fancy UI. It doesn't care where the upstream is hosted.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 9 guests