use a built REVISION file as a backup revision source

This commit is contained in:
Thomas Vander Stichele
2013-07-31 12:18:41 +02:00
parent ad2e89ed97
commit df0daefa27
3 changed files with 28 additions and 5 deletions

View File

@@ -339,10 +339,29 @@ def getRevision():
Get a revision tag for the current git source tree.
Appends -modified in case there are local modifications.
If this is not a git tree, return the top-level REVISION contents instead.
Finally, return unknown.
"""
describe = commands.getoutput('git describe')
topsrcdir = os.path.join(os.path.dirname(__file__), '..', '..')
if commands.getoutput('git diff-index --name-only HEAD --'):
describe += '-modified'
# only use git if our src directory looks like a git checkout
# if you run git regardless, it recurses up until it finds a .git,
# which may be higher than your current source tree
if os.path.exists(os.path.join(topsrcdir, '.git')):
return describe
status, describe = commands.getstatusoutput('git describe')
if status == 0:
if commands.getoutput('git diff-index --name-only HEAD --'):
describe += '-modified'
return describe
# check for a top-level REIVISION file
path = os.path.join(topsrcdir, 'REVISION')
if os.path.exists(path):
revision = open(path).read().strip()
return revision
return '(unknown)'