[PATCH] setup: include package/build/distribution id from HG_PACKAGE in version string

Mads Kiilerich mads at kiilerich.com
Wed Oct 27 19:36:24 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1288226146 -7200
# Branch stable
# Node ID 0de6a2a4db2a0bb234edafe74992d0e56a16be4b
# Parent  e1855dee28c164be291755af2e11b26efe77a64e
setup: include package/build/distribution id from HG_PACKAGE in version string

When replying to "issues" we often have to ask which package/installer has been
used. This patch gives packagers a simple way of providing that information
by putting some kind of build tag in the Mercurial version string.

It should be made "mandatory" for packagers to set this to something like
"TortoiseHg 1.2", "thg-winbuild", "thg-winbuild-2.6", "Berkwood", "Debian",
"Ubuntu", "Fedora", "pypi" etc. That would often make it easier to answer
support questions.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3870,7 +3870,7 @@
 def version_(ui):
     """output version and copyright information"""
     ui.write(_("Mercurial Distributed SCM (version %s)\n")
-             % util.version())
+             % util.version(package=True))
     ui.status(_(
         "(see http://mercurial.selenic.com for more information)\n"
         "\nCopyright (C) 2005-2010 Matt Mackall and others\n"
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -174,7 +174,7 @@
         ui.warn(_("**  http://mercurial.selenic.com/wiki/BugTracker\n"))
         ui.warn(_("** Python %s\n") % sys.version.replace('\n', ''))
         ui.warn(_("** Mercurial Distributed SCM (version %s)\n")
-               % util.version())
+               % util.version(package=True))
         ui.warn(_("** Extensions loaded: %s\n")
                % ", ".join([x[0] for x in extensions.extensions()]))
         raise
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -72,10 +72,12 @@
                          env=env)
     return p.stdin, p.stdout, p.stderr
 
-def version():
+def version(package=False):
     """Return version information if available."""
     try:
         import __version__
+        if package and __version__.package:
+            return '%s / %s' % (__version__.version, __version__.package)
         return __version__.version
     except ImportError:
         return 'unknown'
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -176,7 +176,8 @@
 if version:
     f = open("mercurial/__version__.py", "w")
     f.write('# this file is autogenerated by setup.py\n')
-    f.write('version = "%s"\n' % version)
+    f.write('version = %r\n' % version)
+    f.write('package = %r\n' % os.getenv('HG_PACKAGE'))
     f.close()
 
 


More information about the Mercurial-devel mailing list