diff --git a/.gitignore b/.gitignore index ff01510..0fbf43a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ install-sh missing morituri.spec py-compile +REVISION diff --git a/Makefile.am b/Makefile.am index dc8e9f7..8d8d232 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,7 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = morituri bin etc doc m4 misc -EXTRA_DIST = morituri.spec morituri.doap RELEASE README HACKING +EXTRA_DIST = morituri.spec morituri.doap RELEASE README HACKING REVISION SOURCES = $(top_srcdir)/morituri/*.py $(top_srcdir)/morituri/*/*.py @@ -38,6 +38,9 @@ PYCHECKER_BLACKLIST = \ release: dist make $(PACKAGE)-$(VERSION).tar.bz2.md5 +REVISION: $(top_srcdir)/.git + $(PYTHON) -c 'from morituri.configure import configure; print configure.revision' > REVISION + # generate md5 sum files %.md5: % md5sum $< > $@ diff --git a/morituri/common/common.py b/morituri/common/common.py index aa964e9..1a30eaf 100644 --- a/morituri/common/common.py +++ b/morituri/common/common.py @@ -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)'