Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/version.py @ 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 | 36e644d28edf |
children | 9ae0034f2772 50da4bb9cab6 |
comparison
equal
deleted
inserted
replaced
428:183c87d4e1a0 | 429:688d03d6997a |
---|---|
1 # Copyright (C) 2005 by Intevation GmbH | |
2 # Author(s): | |
3 # Thomas Arendsen Hein <thomas@intevation.de> | |
4 # | |
5 # This program is free software under the GNU GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 """ | |
9 Mercurial version | |
10 """ | |
11 | |
12 import os | |
13 import os.path | |
14 import re | |
15 import time | |
16 | |
17 unknown_version = 'unknown' | |
18 remembered_version = False | |
19 | |
20 def get_version(): | |
21 """Return version information if available.""" | |
22 try: | |
23 from mercurial.__version__ import version | |
24 except ImportError: | |
25 version = unknown_version | |
26 return version | |
27 | |
28 def write_version(version): | |
29 """Overwrite version file.""" | |
30 filename = os.path.join(os.path.dirname(__file__), '__version__.py') | |
31 f = open(filename, 'w') | |
32 f.write("# This file is auto-generated.\n") | |
33 f.write("version = %r\n" % version) | |
34 f.close() | |
35 | |
36 def remember_version(version=None): | |
37 """Store version information.""" | |
38 global remembered_version | |
39 if not version and os.path.isdir(".hg"): | |
40 f = os.popen("hg identify 2>/dev/null") # use real hg installation | |
41 ident = f.read()[:-1] | |
42 if not f.close() and ident: | |
43 ids = ident.split(' ', 1) | |
44 version = ids.pop(0) | |
45 if version[-1] == '+': | |
46 version = version[:-1] | |
47 modified = True | |
48 else: | |
49 modified = False | |
50 if version.isalnum() and ids: | |
51 for tag in ids[0].split('/'): | |
52 # is a tag is suitable as a version number? | |
53 if re.match(r'^(\d+\.)+[\w.-]+$', tag): | |
54 version = tag | |
55 break | |
56 if modified: | |
57 version += time.strftime('+%Y%m%d') | |
58 if version: | |
59 remembered_version = True | |
60 write_version(version) | |
61 | |
62 def forget_version(): | |
63 """Remove version information.""" | |
64 if remembered_version: | |
65 write_version(unknown_version) | |
66 |