If portage.VERSION == HEAD then use a proxy to lazily call git describe --tags
authorZac Medico <zmedico@gentoo.org>
Sat, 27 Mar 2010 21:35:11 +0000 (14:35 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 27 Mar 2010 21:35:11 +0000 (14:35 -0700)
if it's accessed.

pym/_emerge/actions.py
pym/portage/__init__.py

index 954123a76c47fd7d031ba5f6b79ed2f98bb7bd0e..4fb08e3adecfe4e68177f700dfc45977faf49ee5 100644 (file)
@@ -2477,7 +2477,8 @@ def getportageversion(portdir, target_root, profile, chost, vardb):
        gccver = getgccversion(chost)
        unameout=platform.release()+" "+platform.machine()
 
-       return "Portage " + portage.VERSION +" ("+profilever+", "+gccver+", "+libcver+", "+unameout+")"
+       return "Portage %s (%s, %s, %s, %s)" % \
+               (portage.VERSION, profilever, gccver, libcver, unameout)
 
 def git_sync_timestamps(settings, portdir):
        """
index 44402edd48af13c356b5391646e55d98304cd2e2..e1de04635205be07265b230df4e37f58934d108d 100644 (file)
@@ -553,6 +553,23 @@ def create_trees(config_root=None, target_root=None, trees=None):
                        binarytree, myroot, mysettings["PKGDIR"], settings=mysettings)
        return trees
 
+if VERSION == 'HEAD':
+       class _LazyVersion(proxy.objectproxy.ObjectProxy):
+               def _get_target(self):
+                       global VERSION
+                       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))
+                               if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
+                                       VERSION = output
+                                       return VERSION
+                       VERSION = 'HEAD'
+                       return VERSION
+       VERSION = _LazyVersion()
+
 class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
 
        __slots__ = ('_name',)