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-----
--- a/.hgignore
+++ b/.hgignore
@@ -7,4 +7,5 @@ build/.*
dist/
MANIFEST$
.pc/
-patches/
\ No newline at end of file
+patches/
+mercurial/__version__.py$
--- a/TODO
+++ b/TODO
@@ -6,7 +6,7 @@ General:
- 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 @@ Commands:
- 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
+++ b/mercurial/commands.py
@@ -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 @@ def show_changeset(ui, repo, rev=0, chan
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 @@ def help(ui, cmd=None):
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 @@ def help(ui, cmd=None):
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 @@ table = {
"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 @@ def dispatch(args):
('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 @@ def dispatch(args):
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:
new file mode 100644
--- /dev/null
+++ b/mercurial/version.py
@@ -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
+++ b/setup.py
@@ -9,24 +9,30 @@ import glob
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
+++ b/tests/test-help
@@ -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
+++ b/tests/test-help.out
@@ -1,4 +1,4 @@
-+ hg help
++ hg -q help
hg commands:
add add the specified files on the next commit
@@ -45,7 +45,7 @@ hg diff [-r A] [-r B] [files]
diff working directory (or selected files)
+ hg help foo
hg: unknown command foo
-+ hg commands
++ hg -q commands
hg: unknown command 'commands'
hg commands: