summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-12-05 13:23:54 +0300
committerAndrew Dolgov <[email protected]>2019-12-05 13:23:54 +0300
commitf30287be652295d18e632316a66866697c26638c (patch)
tree18bf35592426824682d9c106553a38688d4f4c7f /include
parent6913158b8291c70cdab79641e771e2e89e11ac3e (diff)
versioning changes
- remove VERSION_STATIC - https://community.tt-rss.org/t/versioning-changes-for-trunk/2974 - report git commit/timestamp properly by invoking git instead of trying to parse .git/HEAD etc - remove git-related global constants used when checking for updates
Diffstat (limited to 'include')
-rw-r--r--include/functions.php1
-rw-r--r--include/version.php41
2 files changed, 14 insertions, 28 deletions
diff --git a/include/functions.php b/include/functions.php
index 0a3082ec1..18885b1ea 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -560,7 +560,6 @@
session_regenerate_id(true);
$_SESSION["uid"] = $user_id;
- $_SESSION["version"] = VERSION_STATIC;
$_SESSION["auth_module"] = $auth_module;
$pdo = DB::pdo();
diff --git a/include/version.php b/include/version.php
index db5c2ec80..1851dea20 100644
--- a/include/version.php
+++ b/include/version.php
@@ -1,43 +1,30 @@
<?php
- define('VERSION_STATIC', '19.8');
- function get_version() {
+ function get_version(&$git_commit = false, &$git_timestamp = false) {
+ $version = "UNKNOWN (Unsupported)";
+
date_default_timezone_set('UTC');
$root_dir = dirname(dirname(__FILE__));
- if (is_dir("$root_dir/.git") && file_exists("$root_dir/.git/HEAD")) {
- $head = trim(file_get_contents("$root_dir/.git/HEAD"));
-
- if ($head) {
- $matches = array();
-
- if (preg_match("/^ref: (.*)/", $head, $matches)) {
- $ref = $matches[1];
+ if (is_dir("$root_dir/.git")) {
+ $rc = 0;
+ $output = [];
- if (!file_exists("$root_dir/.git/$ref"))
- return VERSION_STATIC;
- $suffix = substr(trim(file_get_contents("$root_dir/.git/$ref")), 0, 7);
- $timestamp = filemtime("$root_dir/.git/$ref");
+ exec("git log --pretty='%ct %h' -n1 HEAD " . escapeshellarg($root_dir), $output, $rc);
- define("GIT_VERSION_HEAD", $suffix);
- define("GIT_VERSION_TIMESTAMP", $timestamp);
+ if ($rc == 0) {
+ if (is_array($output) && count($output) > 0) {
+ list ($timestamp, $commit) = explode(" ", $output[0], 2);
- return VERSION_STATIC . " ($suffix)";
+ $git_commit = $commit;
+ $git_timestamp = $timestamp;
- } else {
- $suffix = substr(trim($head), 0, 7);
- $timestamp = filemtime("$root_dir/.git/HEAD");
-
- define("GIT_VERSION_HEAD", $suffix);
- define("GIT_VERSION_TIMESTAMP", $timestamp);
-
- return VERSION_STATIC . " ($suffix)";
+ $version = strftime("%y.%m", $timestamp) . "-$commit";
}
}
}
- return VERSION_STATIC;
-
+ return $version;
}
define('VERSION', get_version());