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.
This commit is contained in:
parent
35d39b450f
commit
b36c1d6493
1 changed files with 6 additions and 3 deletions
|
|
@ -51,14 +51,14 @@ def getRepositoryData(module, as_string=True):
|
|||
"""
|
||||
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 @@ def getRepositoryData(module, as_string=True):
|
|||
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 @@ def getRepositoryData(module, as_string=True):
|
|||
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]")
|
||||
|
|
|
|||
Loading…
Reference in a new issue