~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Alexander Belchenko
  • Date: 2006-11-06 10:03:44 UTC
  • mto: This revision was merged to the branch mainline in revision 637.
  • Revision ID: bialix@ukr.net-20061106100344-86ca4fca07fbe551
bzrtool's iter_branches is too slow. Added --debug-time feature show this fact

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Show all 'heads' in a repository"""
19
19
 
20
20
 
 
21
import os
 
22
import time
 
23
 
21
24
from bzrlib.commands import Command, display_command, register_command
22
25
from bzrlib.option import Option
23
26
 
28
31
    takes_options = [Option('by-date', help='Sort heads by date (descending)'),
29
32
                     Option('all', help='Show all heads (dead and alive)'),
30
33
                     Option('dead-only', help='Show only dead heads'),
 
34
                     Option('debug-time', help='Enable debug print of operations times'),
31
35
                    ]
32
36
 
33
37
    encoding_type = "replace"
34
38
 
35
39
    @display_command
36
 
    def run(self, by_date=False, all=False, dead_only=False):
 
40
    def run(self, by_date=False, all=False, dead_only=False, debug_time=False):
37
41
        from bzrlib import errors
38
42
        from bzrlib.osutils import format_date
39
43
        import bzrlib.repository
40
44
 
 
45
        self._init_elapsed_time(debug_time)
 
46
 
41
47
        to_file = self.outf
42
48
 
43
49
        branch = None
66
72
        heads = list(heads)
67
73
        heads.sort()
68
74
 
 
75
        self._print_elapsed_time('get heads:')
 
76
 
69
77
        # sorting by date
70
78
        if by_date:
71
79
            dates = {}
79
87
            heads = []
80
88
            for k in keys:
81
89
                heads.append(dates[k])
 
90
            self._print_elapsed_time('sort by date:')
82
91
 
83
92
        ## mark heads as dead or alive
84
93
        # mark all heads as dead
97
106
        else:
98
107
            # runs from branch
99
108
            raise NotImplementedError('TODO: need to detect is there is shared repo or not')
 
109
        self._print_elapsed_time('get head marks:')
100
110
 
101
111
        # show time
102
112
        indent = ' '*2
137
147
                message = rev.message.rstrip('\r\n')
138
148
                for l in message.split('\n'):
139
149
                    print >>to_file,  indent+'  ' + l
 
150
            self._print_elapsed_time('print head:')
140
151
            print
141
152
 
142
153
        if not heads:
143
154
            print >>to_file, 'No heads found'
144
155
            return 1
 
156
 
 
157
    def _init_elapsed_time(self, debug_time=False):
 
158
        self.debug_time = debug_time
 
159
        if debug_time:
 
160
            self._time = time.time()
 
161
 
 
162
    def _print_elapsed_time(self, msg):
 
163
        if self.debug_time:
 
164
            last_time = time.time()
 
165
            print msg, last_time - self._time
 
166
            self._time = last_time
145
167
#/class cmd_heads
146
168
 
147
169