annotate is-tagged.py @ 18149:0e74934072e0

lib-charset: Added charset_utf8_to_utf8_begin() wrapper function. It's never supposed to fail, so it makes it nicer for the callers who need to use it.
author Timo Sirainen <tss@iki.fi>
date Thu, 15 Jan 2015 01:05:13 +0200
parents 84ffb38839b9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10999
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
1 #!/usr/bin/env python
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
3 """
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
4 Checks if the current revision of the repository is a tagged revision,
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
5 but not 'tip'.
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
6
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
7 usage:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
8 python is-tagged.py [/path/to/repo]
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
9 if no path is given, the current working directory will be used.
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
10
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
11 Exit status:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
12 0 if the current revision is a tagged version OR
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
13 if the current revision was used for signing/tagging OR
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
14 if path is not a Mercurial repository OR
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
15 if module import should fail for some reason
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
16 1 if the current revision has no tag, except 'tip'
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
17 """
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
18 import re
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
19 import sys
11012
84ffb38839b9 is-tagged.py: Don't fail if Mercurial isn't available.
Pascal Volk <user@localhost.localdomain.org>
parents: 10999
diff changeset
20 try:
84ffb38839b9 is-tagged.py: Don't fail if Mercurial isn't available.
Pascal Volk <user@localhost.localdomain.org>
parents: 10999
diff changeset
21 from mercurial import hg, ui
84ffb38839b9 is-tagged.py: Don't fail if Mercurial isn't available.
Pascal Volk <user@localhost.localdomain.org>
parents: 10999
diff changeset
22 except ImportError: # no Mercurial at all
84ffb38839b9 is-tagged.py: Don't fail if Mercurial isn't available.
Pascal Volk <user@localhost.localdomain.org>
parents: 10999
diff changeset
23 sys.exit(0)
10999
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
24 try:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
25 from mercurial.error import Abort, RepoError
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
26 except ImportError:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
27 try:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
28 from mercurial.repo import RepoError
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
29 from mercurial.util import Abort
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
30 except ImportError: # something old/new?
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
31 sys.exit(0)
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
32
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
33 RE = r'^Added\s(?:signature|tag)\s(?:[\w\.]+\s)?for\schangeset\s[\da-f]{12,}$'
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
34
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
35
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
36 def main():
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
37 if len(sys.argv) > 1:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
38 path = sys.argv[1].strip()
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
39 else:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
40 path = '.'
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
41 try:
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
42 repo = hg.repository(ui.ui(), path)
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
43 except (Abort, RepoError): # no/bad repo? no extra version info
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
44 return 0
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
45 parents_id = repo.dirstate.parents()[0]
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
46 ctx = repo.changectx(parents_id)
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
47 if re.match(RE, ctx.description()): # tag or sig was added for a release
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
48 return 0
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
49 for tag, nodeid in repo.tags().iteritems():
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
50 if tag != 'tip' and parents_id == nodeid: # tagged
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
51 return 0
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
52 # not tagged
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
53 return 1
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
54
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
55
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
56 if __name__ == '__main__':
a2c6c91635b5 {master,doveconf}: Show the version with hg's node id, if unreleased.
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
57 sys.exit(main())