Mercurial > hg
comparison mercurial/version.py @ 425:719663b7f235
remember_version() only writes version if called in a Mercurial repository.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
remember_version() only writes version if called in a Mercurial repository.
forget_version() resets version only if remember_version() wrote it.
manifest hash: b30df9d93c233f4bf07150cc5067f294a98c16f4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCtXFiW7P1GVgWeRoRAgkjAJ9jkwCAHf3yJyDI8R582XjNFNFeWgCZAe27
iqGPYzrRErf6gPKZcoBMsD4=
=t2Bx
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sun, 19 Jun 2005 14:21:38 +0100 |
parents | 25afb21d97ba |
children | 36e644d28edf |
comparison
equal
deleted
inserted
replaced
424:9294dce4b633 | 425:719663b7f235 |
---|---|
13 import os.path | 13 import os.path |
14 import re | 14 import re |
15 import time | 15 import time |
16 | 16 |
17 unknown_version = 'unknown' | 17 unknown_version = 'unknown' |
18 remembered_version = False | |
18 | 19 |
19 def get_version(): | 20 def get_version(): |
20 """Return version information if available.""" | 21 """Return version information if available.""" |
21 try: | 22 try: |
22 from mercurial.__version__ import version | 23 from mercurial.__version__ import version |
32 f.write("version = %r\n" % version) | 33 f.write("version = %r\n" % version) |
33 f.close() | 34 f.close() |
34 | 35 |
35 def remember_version(): | 36 def remember_version(): |
36 """Store version information.""" | 37 """Store version information.""" |
37 f = os.popen("hg identify 2>/dev/null") # use real hg installation | 38 global remembered_version |
38 ident = f.read()[:-1] | 39 if os.access(".hg", os.F_OK): |
39 if not f.close() and ident: | 40 f = os.popen("hg identify 2>/dev/null") # use real hg installation |
40 ids = ident.split(' ', 1) | 41 ident = f.read()[:-1] |
41 version = ids.pop(0) | 42 if not f.close() and ident: |
42 if version[-1] == '+': | 43 ids = ident.split(' ', 1) |
43 version = version[:-1] | 44 version = ids.pop(0) |
44 modified = True | 45 if version[-1] == '+': |
45 else: | 46 version = version[:-1] |
46 modified = False | 47 modified = True |
47 if version.isalnum() and ids: | 48 else: |
48 for tag in ids[0].split('/'): | 49 modified = False |
49 # is a tag is suitable as a version number? | 50 if version.isalnum() and ids: |
50 if re.match(r'^(\d+\.)+[\w.-]+$', tag): | 51 for tag in ids[0].split('/'): |
51 version = tag | 52 # is a tag is suitable as a version number? |
52 break | 53 if re.match(r'^(\d+\.)+[\w.-]+$', tag): |
53 if modified: | 54 version = tag |
54 version += time.strftime('+%Y%m%d') | 55 break |
55 else: | 56 if modified: |
56 version = unknown_version | 57 version += time.strftime('+%Y%m%d') |
57 write_version(version) | 58 remembered_version = True |
59 write_version(version) | |
58 | 60 |
59 def forget_version(): | 61 def forget_version(): |
60 """Remove version information.""" | 62 """Remove version information.""" |
61 write_version(unknown_version) | 63 if remembered_version: |
64 write_version(unknown_version) | |
62 | 65 |