changeset 1471:934e402c90bf

core: tools.utils.getRepositoryData now return "hg log -r -1" and short form of node + fixed crash if mercurial is not present: short form is now returned in string version for better readability. Even if a collision is possible, it's not a big deal as it is used mainly in about dialog to help identify a version in case of e.g. bug.
author Goffi <goffi@goffi.org>
date Tue, 18 Aug 2015 09:37:25 +0200
parents 8bfbf5cb0e28
children c005c212b538
files src/tools/utils.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/tools/utils.py	Tue Aug 18 09:01:18 2015 +0200
+++ b/src/tools/utils.py	Tue Aug 18 09:37:25 2015 +0200
@@ -51,14 +51,14 @@
     """
     from distutils.spawn import find_executable
     import subprocess
-    KEYS=("node", "branch", "date", "tag")
+    KEYS=("node", "node_short", "branch", "date", "tag")
     repos_root = os.path.dirname(module.__file__)
     hg_path = find_executable('hg')
 
     if hg_path is not None:
         os.chdir(repos_root)
         try:
-            hg_data_raw = subprocess.check_output(["hg","parents","--template","{node}\n{branch}\n{date|isodate}\n{latesttag}"])
+            hg_data_raw = subprocess.check_output(["hg","log", "-r", "-1", "--template","{node}\n{node|short}\n{branch}\n{date|isodate}\n{latesttag}"])
         except subprocess.CalledProcessError:
             hg_data = {}
         else:
@@ -67,6 +67,8 @@
             hg_data['modified'] = '+' in subprocess.check_output(["hg","id","-i"])
         except subprocess.CalledProcessError:
             pass
+    else:
+        hg_data = {}
 
     if not hg_data:
         log.debug(u"Mercurial not available or working, trying to get data from dirstate")
@@ -74,13 +76,14 @@
         try:
             with open('.hg/dirstate') as hg_dirstate:
                 hg_data['node'] = hg_dirstate.read(20).encode('hex')
+                hg_data['node_short'] = hg_data['node'][:12]
         except IOError:
             log.warning(u"Can't access repository data")
 
     if as_string:
         if not hg_data:
             return u'repository data unknown'
-        strings = [u'rev', hg_data['node']]
+        strings = [u'rev', hg_data['node_short']]
         try:
             if hg_data['modified']:
                 strings.append(u"[M]")