changeset 429:688d03d6997a

Pull from TAH -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pull from TAH manifest hash: 600d04efbd836d555d11a3bd9d821d1d8c0a9790 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuPFxywK+sNU5EO8RAjfzAKC18Zc2EOkXhy1zcpgGnyPHnFMdmgCfW5Ut I5HSWqZMt8H0WJx1Or7ajNc= =27D5 -----END PGP SIGNATURE-----
author mpm@selenic.com
date Tue, 21 Jun 2005 21:04:49 -0800
parents 183c87d4e1a0 (current diff) 36e644d28edf (diff)
children 5b22029b5aa2
files .hgignore TODO contrib/hgit mercurial/commands.py mercurial/hg.py mercurial/lock.py mercurial/mpatch.c mercurial/transaction.py mercurial/version.py setup.py tests/run-tests tests/test-help tests/test-help.out tests/test-simple-update.out
diffstat 8 files changed, 130 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Jun 21 20:40:53 2005 -0800
+++ b/.hgignore	Tue Jun 21 21:04:49 2005 -0800
@@ -7,4 +7,5 @@
 dist/
 MANIFEST$
 .pc/
-patches/
\ No newline at end of file
+patches/
+mercurial/__version__.py$
--- a/TODO	Tue Jun 21 20:40:53 2005 -0800
+++ b/TODO	Tue Jun 21 21:04:49 2005 -0800
@@ -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	Tue Jun 21 20:40:53 2005 -0800
+++ b/mercurial/commands.py	Tue Jun 21 21:04:49 2005 -0800
@@ -8,7 +8,7 @@
 import os, re, sys, signal
 import fancyopts, ui, hg, util
 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
 
@@ -724,7 +737,7 @@
     "verify": (verify, [], 'hg verify'),
     }
 
-norepo = "init branch help debugindex debugindexdot"
+norepo = "init version help debugindex debugindexdot"
 
 def find(cmd):
     i = None
@@ -749,6 +762,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,
@@ -762,6 +776,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:
--- a/mercurial/hg.py	Tue Jun 21 20:40:53 2005 -0800
+++ b/mercurial/hg.py	Tue Jun 21 21:04:49 2005 -0800
@@ -1365,9 +1365,15 @@
         self.ui = ui
         no_list = [ "localhost", "127.0.0.1" ]
         host = ui.config("http_proxy", "host")
+        if host is None:
+            host = os.environ.get("http_proxy")
+        if host and host.startswith('http://'):
+            host = host[7:]
         user = ui.config("http_proxy", "user")
         passwd = ui.config("http_proxy", "passwd")
         no = ui.config("http_proxy", "no")
+        if no is None:
+            no = os.environ.get("no_proxy")
         if no:
             no_list = no_list + no.split(",")
             
@@ -1380,6 +1386,9 @@
 
         # Note: urllib2 takes proxy values from the environment and those will
         # take precedence
+        for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
+            if os.environ.has_key(env):
+                del os.environ[env]
 
         proxy_handler = urllib2.BaseHandler()
         if host and not no_proxy:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/version.py	Tue Jun 21 21:04:49 2005 -0800
@@ -0,0 +1,66 @@
+# 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'
+remembered_version = False
+
+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(version=None):
+    """Store version information."""
+    global remembered_version
+    if not version and os.path.isdir(".hg"):
+        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')
+    if version:
+        remembered_version = True
+        write_version(version)
+
+def forget_version():
+    """Remove version information."""
+    if remembered_version:
+        write_version(unknown_version)
+
--- a/setup.py	Tue Jun 21 20:40:53 2005 -0800
+++ b/setup.py	Tue Jun 21 21:04:49 2005 -0800
@@ -9,25 +9,34 @@
 from distutils.core import setup, Extension
 from distutils.command.install_data import install_data
 
+import mercurial.version
+
+# specify version string, otherwise 'hg identify' will be used:
+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']),
-                   Extension('mercurial.bdiff', ['mercurial/bdiff.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(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']),
+                       Extension('mercurial.bdiff', ['mercurial/bdiff.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	Tue Jun 21 20:40:53 2005 -0800
+++ b/tests/test-help	Tue Jun 21 21:04:49 2005 -0800
@@ -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	Tue Jun 21 20:40:53 2005 -0800
+++ b/tests/test-help.out	Tue Jun 21 21:04:49 2005 -0800
@@ -1,4 +1,4 @@
-+ hg help
++ hg -q help
 hg commands:
 
  add         add the specified files on the next commit
@@ -46,7 +46,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: