Mercurial > hg
changeset 423:25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Support for 'hg --version'. setup.py stores version from hg repository.
manifest hash: c69058298ea12035f2cf356f987ba2fb5ff4bbae
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCtD6ZW7P1GVgWeRoRAnGHAKCLscthht2UlBEMDmxL9cku4PlcswCffOVo
wTOhYkW4Ie5+8bdmL8EqsvY=
=uGpn
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sat, 18 Jun 2005 16:32:41 +0100 |
parents | 8f8bb77d560e |
children | 9294dce4b633 |
files | .hgignore TODO mercurial/commands.py mercurial/version.py setup.py tests/test-help tests/test-help.out |
diffstat | 7 files changed, 113 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Jun 17 20:37:23 2005 +0100 +++ b/.hgignore Sat Jun 18 16:32:41 2005 +0100 @@ -7,4 +7,5 @@ dist/ MANIFEST$ .pc/ -patches/ \ No newline at end of file +patches/ +mercurial/__version__.py$
--- a/TODO Fri Jun 17 20:37:23 2005 +0100 +++ b/TODO Sat Jun 18 16:32:41 2005 +0100 @@ -6,7 +6,7 @@ - python 2.2 support - better import support - export to git -- Add standard files: AUTHORS, CREDITS, COPYING. ChangeLog? What else? +- Add standard files: AUTHORS, CREDITS, ChangeLog? What else? - Code cleanup: apply http://python.org/peps/pep-0008.html Core: @@ -33,7 +33,6 @@ - hg -v history doesn't show tkmerge as modified (removed). - hg import vs. hg patch in help etc., import is a reserved python word, PEP8 mentions trailing underscore as a convention for this. -- version reporting (hg --version / version.py / setup.py etc.) - hg pull default in a subdir doesn't work, if it is a relative path - optionally only show merges (two parents or parent != changeset-1, etc.)
--- a/mercurial/commands.py Fri Jun 17 20:37:23 2005 +0100 +++ b/mercurial/commands.py Sat Jun 18 16:32:41 2005 +0100 @@ -8,7 +8,7 @@ import os, re, sys, signal import fancyopts, ui, hg from demandload import * -demandload(globals(), "mdiff time hgweb traceback random signal errno") +demandload(globals(), "mdiff time hgweb traceback random signal errno version") class UnknownCommand(Exception): pass @@ -134,6 +134,16 @@ ui.status("summary: %s\n" % description.splitlines()[0]) ui.status("\n") +def show_version(ui): + """output version and copyright information""" + ui.write("Mercurial version %s\n" % version.get_version()) + ui.status( + "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" + "This is free software; see the source for copying conditions. " + "There is NO\nwarranty; " + "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" + ) + def help(ui, cmd=None): '''show help for a given command or all commands''' if cmd: @@ -156,7 +166,10 @@ ui.warn("hg: unknown command %s\n" % cmd) sys.exit(0) else: - ui.status('hg commands:\n\n') + if not ui.quiet: + show_version(ui) + ui.write('\n') + ui.write('hg commands:\n\n') h = {} for e in table.values(): @@ -171,7 +184,7 @@ fns.sort() m = max(map(len, fns)) for f in fns: - ui.status(' %-*s %s\n' % (m, f, h[f])) + ui.write(' %-*s %s\n' % (m, f, h[f])) # Commands start here, listed alphabetically @@ -679,7 +692,7 @@ "verify": (verify, [], 'hg verify'), } -norepo = "init branch help debugindex debugindexdot" +norepo = "init version help debugindex debugindexdot" def find(cmd): i = None @@ -704,6 +717,7 @@ ('q', 'quiet', None, 'quiet'), ('p', 'profile', None, 'profile'), ('y', 'noninteractive', None, 'run non-interactively'), + ('', 'version', None, 'output version information and exit'), ] args = fancyopts.fancyopts(args, opts, options, @@ -717,6 +731,10 @@ u = ui.ui(options["verbose"], options["debug"], options["quiet"], not options["noninteractive"]) + if options["version"]: + show_version(u) + sys.exit(0) + try: i = find(cmd) except UnknownCommand:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/version.py Sat Jun 18 16:32:41 2005 +0100 @@ -0,0 +1,62 @@ +# Copyright (C) 2005 by Intevation GmbH +# Author(s): +# Thomas Arendsen Hein <thomas@intevation.de> +# +# This program is free software under the GNU GPL (>=v2) +# Read the file COPYING coming with the software for details. + +""" +Mercurial version +""" + +import os +import os.path +import re +import time + +unknown_version = 'unknown' + +def get_version(): + """Return version information if available.""" + try: + from mercurial.__version__ import version + except ImportError: + version = unknown_version + return version + +def write_version(version): + """Overwrite version file.""" + filename = os.path.join(os.path.dirname(__file__), '__version__.py') + f = open(filename, 'w') + f.write("# This file is auto-generated.\n") + f.write("version = %r\n" % version) + f.close() + +def remember_version(): + """Store version information.""" + f = os.popen("hg identify 2>/dev/null") # use real hg installation + ident = f.read()[:-1] + if not f.close() and ident: + ids = ident.split(' ', 1) + version = ids.pop(0) + if version[-1] == '+': + version = version[:-1] + modified = True + else: + modified = False + if version.isalnum() and ids: + for tag in ids[0].split('/'): + # is a tag is suitable as a version number? + if re.match(r'^(\d+\.)+[\w.-]+$', tag): + version = tag + break + if modified: + version += time.strftime('+%Y%m%d') + else: + version = unknown_version + write_version(version) + +def forget_version(): + """Remove version information.""" + write_version(unknown_version) +
--- a/setup.py Fri Jun 17 20:37:23 2005 +0100 +++ b/setup.py Sat Jun 18 16:32:41 2005 +0100 @@ -9,24 +9,30 @@ from distutils.core import setup, Extension from distutils.command.install_data import install_data +import mercurial.version + class install_package_data(install_data): def finalize_options(self): self.set_undefined_options('install', ('install_lib', 'install_dir')) install_data.finalize_options(self) -setup(name='mercurial', - version='0.5b', - author='Matt Mackall', - author_email='mpm@selenic.com', - url='http://selenic.com/mercurial', - description='scalable distributed SCM', - license='GNU GPL', - packages=['mercurial'], - ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])], - data_files=[('mercurial/templates', - ['templates/map'] + - glob.glob('templates/map-*') + - glob.glob('templates/*.tmpl'))], - cmdclass = { 'install_data' : install_package_data }, - scripts=['hg', 'hgmerge']) +try: + mercurial.version.remember_version() + setup(name='mercurial', + version=mercurial.version.get_version(), + author='Matt Mackall', + author_email='mpm@selenic.com', + url='http://selenic.com/mercurial', + description='scalable distributed SCM', + license='GNU GPL', + packages=['mercurial'], + ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])], + data_files=[('mercurial/templates', + ['templates/map'] + + glob.glob('templates/map-*') + + glob.glob('templates/*.tmpl'))], + cmdclass = { 'install_data' : install_package_data }, + scripts=['hg', 'hgmerge']) +finally: + mercurial.version.forget_version()
--- a/tests/test-help Fri Jun 17 20:37:23 2005 +0100 +++ b/tests/test-help Sat Jun 18 16:32:41 2005 +0100 @@ -2,10 +2,10 @@ set -x -hg help +hg -q help hg add -h hg help diff hg help foo -hg commands +hg -q commands -exit 0 \ No newline at end of file +exit 0
--- a/tests/test-help.out Fri Jun 17 20:37:23 2005 +0100 +++ b/tests/test-help.out Sat Jun 18 16:32:41 2005 +0100 @@ -1,4 +1,4 @@ -+ hg help ++ hg -q help hg commands: add add the specified files on the next commit @@ -45,7 +45,7 @@ diff working directory (or selected files) + hg help foo hg: unknown command foo -+ hg commands ++ hg -q commands hg: unknown command 'commands' hg commands: