summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-09-19 16:33:03 -0700
committerZac Medico <zmedico@gentoo.org>2010-09-19 16:33:03 -0700
commit213dce575a3302ea3b24a81382a587533fd665e1 (patch)
treeb820aee41ea95646e78dbfb8a33729a8b3deb2f4
parent6085103bdd7623d941e3c6ae5905e66658c49fd7 (diff)
downloadportage-213dce575a3302ea3b24a81382a587533fd665e1.tar.gz
portage-213dce575a3302ea3b24a81382a587533fd665e1.tar.bz2
portage-213dce575a3302ea3b24a81382a587533fd665e1.zip
Bug #338002 - Make _LazyVersion format portage.VERSION so that it is
a valid version.
-rw-r--r--pym/portage/__init__.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 3c8d5ced6..895e8457e 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -125,6 +125,7 @@ try:
'cpv_getkey@getCPFromCPV,endversion_keys,' + \
'suffix_value@endversion,pkgcmp,pkgsplit,vercmp,ververify',
'portage.xpak',
+ 'time',
)
try:
@@ -541,12 +542,39 @@ if VERSION == 'HEAD':
if VERSION is not self:
return VERSION
if os.path.isdir(os.path.join(PORTAGE_BASE_PATH, '.git')):
- status, output = subprocess_getstatusoutput(
- "cd %s ; git describe --tags" % \
- _shell_quote(PORTAGE_BASE_PATH))
+ status, output = subprocess_getstatusoutput((
+ "cd %s ; git describe --tags || exit $? ; " + \
+ "if [ -n \"`git diff-index --name-only --diff-filter=M HEAD`\" ] ; " + \
+ "then echo modified ; git rev-list --pretty=raw -n 1 HEAD ; fi ; " + \
+ "exit 0") % _shell_quote(PORTAGE_BASE_PATH))
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
- VERSION = output
- return VERSION
+ output_lines = output.splitlines()
+ if output_lines:
+ version_split = output_lines[0].split('-')
+ if version_split:
+ VERSION = version_split[0].lstrip('v')
+ patchlevel = False
+ if len(version_split) > 1:
+ patchlevel = True
+ VERSION = "%s_p%s" %(VERSION, version_split[1])
+ if len(output_lines) > 1 and output_lines[1] == 'modified':
+ head_timestamp = None
+ for line in output_lines[2:]:
+ if line.startswith('author '):
+ author_split = line.split()
+ if len(author_split) > 1:
+ try:
+ head_timestamp = long(author_split[-2])
+ except ValueError:
+ pass
+ break
+ timestamp = long(time.time())
+ if head_timestamp is not None and timestamp > head_timestamp:
+ timestamp = timestamp - head_timestamp
+ if not patchlevel:
+ VERSION = "%s_p0" % (VERSION,)
+ VERSION = "%s_p%d" % (VERSION, timestamp)
+ return VERSION
VERSION = 'HEAD'
return VERSION
VERSION = _LazyVersion()