From b6ddda8f1795304ad5e8921dccffe3f16efae24a Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git@the-compiler.org>
Date: Mon, 23 Jun 2014 16:19:43 +0200
Subject: [PATCH] Show git timestamp in version

---
 doc/TODO                     |  1 -
 qutebrowser/utils/version.py | 10 +++++++---
 scripts/setupcommon.py       |  8 ++++++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/doc/TODO b/doc/TODO
index 5d0654d5d..0d3a5558f 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -45,7 +45,6 @@ Improvements / minor features
 - Color statusbar in insert mode
 - set_toggle to toggle setting between two states
 - Customizable statusbar
-- Timestamp of git commit in version
 - Show size of widgets in __repr__
 - Ask whether to close when downloads are running or maybe if form fields are
   unsubmitted (book page 187)
diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py
index 3e423d4ca..a3e05fa57 100644
--- a/qutebrowser/utils/version.py
+++ b/qutebrowser/utils/version.py
@@ -97,20 +97,24 @@ def _git_str():
 
 
 def _git_str_subprocess(gitpath):
-    """Try to get the git commit ID by calling git.
+    """Try to get the git commit ID and timestamp by calling git.
 
     Args:
         gitpath: The path where the .git folder is.
 
     Return:
-        The path on success, None on failure.
+        The ID/timestamp on success, None on failure.
     """
     if not os.path.isdir(os.path.join(gitpath, ".git")):
         return None
     try:
-        return subprocess.check_output(
+        cid = subprocess.check_output(
             ['git', 'describe', '--tags', '--dirty', '--always'],
             cwd=gitpath).decode('UTF-8').strip()
+        date = subprocess.check_output(
+            ['git', 'show', '-s', '--format=%ci', 'HEAD'],
+            cwd=gitpath).decode('UTF-8').strip()
+        return '{} ({})'.format(cid, date)
     except (subprocess.CalledProcessError, FileNotFoundError):
         return None
 
diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py
index 43a955612..b1737391b 100644
--- a/scripts/setupcommon.py
+++ b/scripts/setupcommon.py
@@ -61,7 +61,7 @@ def _git_str():
     """Try to find out git version.
 
     Return:
-        string containing the git commit ID.
+        string containing the git commit ID and timestamp.
         None if there was an error or we're not in a git repo.
     """
     if BASEDIR is None:
@@ -69,9 +69,13 @@ def _git_str():
     if not os.path.isdir(os.path.join(BASEDIR, ".git")):
         return None
     try:
-        return subprocess.check_output(
+        cid = subprocess.check_output(
             ['git', 'describe', '--tags', '--dirty', '--always'],
             cwd=BASEDIR).decode('UTF-8').strip()
+        date = subprocess.check_output(
+            ['git', 'show', '-s', '--format=%ci', 'HEAD'],
+            cwd=BASEDIR).decode('UTF-8').strip()
+        return '{} ({})'.format(cid, date)
     except (subprocess.CalledProcessError, FileNotFoundError):
         return None