File: is-tagged.py

package info (click to toggle)
dovecot 1%3A2.1.7-7%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 33,368 kB
  • sloc: ansic: 284,478; sh: 23,068; makefile: 4,874; cpp: 1,381; perl: 263; xml: 45; python: 34; pascal: 27
file content (57 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Checks if the current revision of the repository is a tagged revision,
    but not 'tip'.

    usage:
    python is-tagged.py [/path/to/repo]
    if no path is given, the current working directory will be used.

    Exit status:
      0 if the current revision is a tagged version OR
        if the current revision was used for signing/tagging OR
        if path is not a Mercurial repository OR
        if module import should fail for some reason
      1 if the current revision has no tag, except 'tip'
"""
import re
import sys
try:
    from mercurial import hg, ui
except ImportError:  # no Mercurial at all
    sys.exit(0)
try:
    from mercurial.error import Abort, RepoError
except ImportError:
    try:
        from mercurial.repo import RepoError
        from mercurial.util import Abort
    except ImportError:  # something old/new?
        sys.exit(0)

RE = r'^Added\s(?:signature|tag)\s(?:[\w\.]+\s)?for\schangeset\s[\da-f]{12,}$'


def main():
    if len(sys.argv) > 1:
        path = sys.argv[1].strip()
    else:
        path = '.'
    try:
        repo = hg.repository(ui.ui(), path)
    except (Abort, RepoError):  # no/bad repo? no extra version info
        return 0
    parents_id = repo.dirstate.parents()[0]
    ctx = repo.changectx(parents_id)
    if re.match(RE, ctx.description()):  # tag or sig was added for a release
        return 0
    for tag, nodeid in repo.tags().iteritems():
        if tag != 'tip' and parents_id == nodeid:  # tagged
            return 0
    # not tagged
    return 1


if __name__ == '__main__':
    sys.exit(main())