~abentley/bzrtools/bzrtools.dev

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# based on Robert Collins code

"""Show all 'heads' in shared repository"""


from bzrlib.commands import Command, display_command, register_command


class cmd_heads(Command):
    """Show all revisions in shared repository that does not have descendants.
    """
    encoding_type = "replace"

    @display_command
    def run(self):
        from bzrlib.errors import NoRepositoryPresent
        from bzrlib.osutils import format_date
        import bzrlib.repository
        
        try:
            r = bzrlib.repository.Repository.open('.')
        except NoRepositoryPresent, e:
            print ("You need to run this command "
                   "from the root of shared repository")
            return

        g = r.get_revision_graph()
        possible_heads = set(g.keys())
        not_heads = set()
        for parents in g.values():
            not_heads.update(set(parents))
        
        heads = possible_heads.difference(not_heads)
        
        heads = list(heads)
        heads.sort()
        
        to_file = self.outf
        indent = ' '*2
        show_timezone = 'original'
        
        for head in heads:
            print "revid:", head
            rev = r.get_revision(head)
            # borrowed from LonLogFormatter
            print >>to_file,  indent+'committer:', rev.committer
            try:
                print >>to_file, indent+'branch nick: %s' % \
                    rev.properties['branch-nick']
            except KeyError:
                pass
            date_str = format_date(rev.timestamp,
                                   rev.timezone or 0,
                                   show_timezone)
            print >>to_file,  indent+'timestamp: %s' % date_str
    
            print >>to_file,  indent+'message:'
            if not rev.message:
                print >>to_file,  indent+'  (no message)'
            else:
                message = rev.message.rstrip('\r\n')
                for l in message.split('\n'):
                    print >>to_file,  indent+'  ' + l
            print

        if not heads:
            print 'No heads found'
#/class cmd_heads


register_command(cmd_heads)