~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-18 14:34:50 UTC
  • mto: This revision was merged to the branch mainline in revision 637.
  • Revision ID: bialix@ukr.net-20060718143450-3a7e672183317bbe
first version of heads command. thanks to Robert Collins for algorithm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# based on Robert Collins code
 
2
 
 
3
"""Show all 'heads' in shared repository"""
 
4
 
 
5
 
 
6
from bzrlib.commands import Command, display_command, register_command
 
7
 
 
8
 
 
9
class cmd_heads(Command):
 
10
    """Show all revisions in shared repository that does not have descendants.
 
11
    """
 
12
    encoding_type = "replace"
 
13
 
 
14
    @display_command
 
15
    def run(self):
 
16
        from bzrlib.errors import NoRepositoryPresent
 
17
        from bzrlib.osutils import format_date
 
18
        import bzrlib.repository
 
19
        
 
20
        try:
 
21
            r = bzrlib.repository.Repository.open('.')
 
22
        except NoRepositoryPresent, e:
 
23
            print ("You need to run this command "
 
24
                   "from the root of shared repository")
 
25
            return
 
26
 
 
27
        g = r.get_revision_graph()
 
28
        possible_heads = set(g.keys())
 
29
        not_heads = set()
 
30
        for parents in g.values():
 
31
            not_heads.update(set(parents))
 
32
        
 
33
        heads = possible_heads.difference(not_heads)
 
34
        
 
35
        heads = list(heads)
 
36
        heads.sort()
 
37
        
 
38
        to_file = self.outf
 
39
        indent = ' '*2
 
40
        show_timezone = 'original'
 
41
        
 
42
        for head in heads:
 
43
            print "revid:", head
 
44
            rev = r.get_revision(head)
 
45
            # borrowed from LonLogFormatter
 
46
            print >>to_file,  indent+'committer:', rev.committer
 
47
            try:
 
48
                print >>to_file, indent+'branch nick: %s' % \
 
49
                    rev.properties['branch-nick']
 
50
            except KeyError:
 
51
                pass
 
52
            date_str = format_date(rev.timestamp,
 
53
                                   rev.timezone or 0,
 
54
                                   show_timezone)
 
55
            print >>to_file,  indent+'timestamp: %s' % date_str
 
56
    
 
57
            print >>to_file,  indent+'message:'
 
58
            if not rev.message:
 
59
                print >>to_file,  indent+'  (no message)'
 
60
            else:
 
61
                message = rev.message.rstrip('\r\n')
 
62
                for l in message.split('\n'):
 
63
                    print >>to_file,  indent+'  ' + l
 
64
            print
 
65
 
 
66
        if not heads:
 
67
            print 'No heads found'
 
68
#/class cmd_heads
 
69
 
 
70
 
 
71
register_command(cmd_heads)