annotate mercurial/version.py @ 6286:90a4329a6b4a

filectx.ancestor: use fctx._repopath to cache filelogs (issue1035) _repopath may be different from _path for workingfilectx when there are renames involved.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sun, 16 Mar 2008 06:10:47 -0300
parents 4b81eecc8aa2
children d6e5e6f7b2d8 9c195637ac0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5931
6482d34974ac Remove unneeded "import os.path"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5481
diff changeset
1 # Copyright (C) 2005, 2006, 2008 by Intevation GmbH
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
2 # Author(s):
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
3 # Thomas Arendsen Hein <thomas@intevation.de>
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
4 #
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
5 # This program is free software under the GNU GPL (>=v2)
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
7
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
8 """
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
9 Mercurial version
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
10 """
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
11
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
12 import os
6285
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
13 import os.path
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
14 import sys
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
15 import re
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
16 import time
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
17
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
18 unknown_version = 'unknown'
425
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
19 remembered_version = False
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
20
4066
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
21 def get_version(doreload=False):
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
22 """Return version information if available."""
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
23 try:
4066
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
24 import mercurial.__version__
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
25 if doreload:
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
26 reload(mercurial.__version__)
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
27 version = mercurial.__version__.version
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
28 except ImportError:
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
29 version = unknown_version
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
30 return version
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
31
6285
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
32 def get_useragent():
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
33 """Return some extended version information for the User-Agent
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
34 field in http requests."""
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
35 hgver = get_version()
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
36 pyver = '%s(%s)' % (sys.version.split()[0], hex(sys.hexversion))
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
37 ostype = os.name
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
38 plat = sys.platform
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
39 return 'mercurial/proto-1.0 (Python/%s; Mercurial/%s; %s/%s)' % \
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
40 (pyver, hgver, ostype, plat)
4b81eecc8aa2 Change User-agent field in client to have a lot more info.
Eric Hopper <hopper@omnifarious.org>
parents: 6237
diff changeset
41
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
42 def write_version(version):
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
43 """Overwrite version file."""
1977
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
44 if version == get_version():
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
45 return
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
46 directory = os.path.dirname(__file__)
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
47 for suffix in ['py', 'pyc', 'pyo']:
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
48 try:
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
49 os.unlink(os.path.join(directory, '__version__.%s' % suffix))
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
50 except OSError:
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
51 pass
7eb694a1c1af Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 464
diff changeset
52 f = open(os.path.join(directory, '__version__.py'), 'w')
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
53 f.write("# This file is auto-generated.\n")
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
54 f.write("version = %r\n" % version)
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
55 f.close()
4066
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
56 # reload the file we've just written
cff3e4b4a8de setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2859
diff changeset
57 get_version(True)
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
58
427
36e644d28edf Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 425
diff changeset
59 def remember_version(version=None):
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
60 """Store version information."""
425
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
61 global remembered_version
427
36e644d28edf Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 425
diff changeset
62 if not version and os.path.isdir(".hg"):
6237
4a85a9077136 Make mercurial easy installable
Ralf Schmitt <schmir@gmail.com>
parents: 5931
diff changeset
63 f = os.popen("hg identify") # use real hg installation
425
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
64 ident = f.read()[:-1]
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
65 if not f.close() and ident:
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
66 ids = ident.split(' ', 1)
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
67 version = ids.pop(0)
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
68 if version[-1] == '+':
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
69 version = version[:-1]
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
70 modified = True
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
71 else:
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
72 modified = False
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
73 if version.isalnum() and ids:
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
74 for tag in ids[0].split('/'):
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
75 # is a tag is suitable as a version number?
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
76 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
77 version = tag
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
78 break
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
79 if modified:
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
80 version += time.strftime('+%Y%m%d')
427
36e644d28edf Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 425
diff changeset
81 if version:
36e644d28edf Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 425
diff changeset
82 remembered_version = True
36e644d28edf Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 425
diff changeset
83 write_version(version)
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
84
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
85 def forget_version():
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
86 """Remove version information."""
425
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
87 if remembered_version:
719663b7f235 remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 423
diff changeset
88 write_version(unknown_version)
423
25afb21d97ba Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
89