diff options
Diffstat (limited to 'include/version.php')
-rw-r--r-- | include/version.php | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/include/version.php b/include/version.php index db5c2ec80..d1c5e03b5 100644 --- a/include/version.php +++ b/include/version.php @@ -1,43 +1,36 @@ <?php - define('VERSION_STATIC', '19.8'); - function get_version() { - 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(); + /* for package maintainers who don't use git: if version_static.txt exists in tt-rss root + directory, its contents are displayed instead of git commit-based version, this could be generated + based on source git tree commit used when creating the package */ - if (preg_match("/^ref: (.*)/", $head, $matches)) { - $ref = $matches[1]; + function get_version(&$git_commit = false, &$git_timestamp = false) { + $version = "UNKNOWN (Unsupported)"; - 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"); + date_default_timezone_set('UTC'); + $root_dir = dirname(dirname(__FILE__)); - define("GIT_VERSION_HEAD", $suffix); - define("GIT_VERSION_TIMESTAMP", $timestamp); + if (file_exists("$root_dir/version_static.txt")) { + $version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; + } else if (is_dir("$root_dir/.git")) { + $rc = 0; + $output = []; - return VERSION_STATIC . " ($suffix)"; + exec("git log --pretty='%ct %h' -n1 HEAD " . escapeshellarg($root_dir), $output, $rc); - } else { - $suffix = substr(trim($head), 0, 7); - $timestamp = filemtime("$root_dir/.git/HEAD"); + if ($rc == 0) { + if (is_array($output) && count($output) > 0) { + list ($timestamp, $commit) = explode(" ", $output[0], 2); - define("GIT_VERSION_HEAD", $suffix); - define("GIT_VERSION_TIMESTAMP", $timestamp); + $git_commit = $commit; + $git_timestamp = $timestamp; - return VERSION_STATIC . " ($suffix)"; + $version = strftime("%y.%m", $timestamp) . "-$commit"; } } } - return VERSION_STATIC; - + return $version; } define('VERSION', get_version()); |