Ubuntu Pastebin

Paste from greyback at Tue, 28 Apr 2015 11:38:52 +0000

Download as text
 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
#!/usr/bin/env python

import sys
from bzrlib.plugin import load_plugins
from bzrlib.branch import Branch
from bzrlib.errors import BzrError

# load plugins to resolve lp: and colo: shortcuts
load_plugins()

if len(sys.argv) == 1:
    print("ERROR: Please pass a list of references to branches to be cleaned up"
          " as command line arguments.")
    sys.exit(1)

for branch_url in sys.argv[1:]:
    try:
        branch = Branch.open(branch_url)
    except BzrError as e:
        print e
        continue

    tags = branch.tags.get_tag_dict()
    revids = branch.repository.all_revision_ids()
    bad_tags = set()

    for tag, revid in tags.iteritems():
        if revid not in revids:
            bad_tags.add(tag)

    if not bad_tags:
        print("{0}: clean".format(branch_url))
        continue

    try:
        for tag in bad_tags:
            branch.tags.delete_tag(tag)
            print("Deleted {0}/{1}".format(branch_url, tag))
    except BzrError as e:
        print("{0}: would delete {1}".format(branch_url, ",".join(bad_tags)))
        print e
Download as text