/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.140.1 by John Arbash Meinel
A simple plugin for generating author statistics, may grow into more.
1
"""A Simple bzr plugin to generate statistics about the history."""
2
3
from bzrlib.branch import Branch
4
import bzrlib.commands
5
from bzrlib.config import extract_email_address
6
from bzrlib import errors
7
from bzrlib.workingtree import WorkingTree
8
9
10
class cmd_statistics(bzrlib.commands.Command):
11
    """Generate statistics for LOCATION."""
12
13
    aliases = ['stats']
14
    takes_args = ['location?']
15
16
    def run(self, location='.'):
17
        try:
18
            wt = WorkingTree.open_containing(location)[0]
19
        except errors.NoWorkingTree:
20
            b = Branch.open(location)
21
            last_rev = b.last_revision()
22
        else:
23
            b = wt.branch
24
            last_rev = wt.last_revision()
25
0.140.2 by John Arbash Meinel
add a little bit of progress since it takes a while.
26
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
0.140.1 by John Arbash Meinel
A simple plugin for generating author statistics, may grow into more.
27
        committers = {}
28
        b.lock_read()
29
        try:
0.140.2 by John Arbash Meinel
add a little bit of progress since it takes a while.
30
            pb.note('getting ancestry')
31
            ancestry = b.repository.get_ancestry(last_rev)[1:]
32
            pb.note('getting revisions')
33
            revisions = b.repository.get_revisions(ancestry)
0.140.1 by John Arbash Meinel
A simple plugin for generating author statistics, may grow into more.
34
0.140.2 by John Arbash Meinel
add a little bit of progress since it takes a while.
35
            for count, rev in enumerate(revisions):
36
                pb.update('checking', count, len(ancestry))
0.140.1 by John Arbash Meinel
A simple plugin for generating author statistics, may grow into more.
37
                try:
38
                    email = extract_email_address(rev.committer)
39
                except errors.BzrError:
40
                    email = rev.committer
41
                committers.setdefault(email, []).append(rev)
42
        finally:
43
            b.unlock()
0.140.2 by John Arbash Meinel
add a little bit of progress since it takes a while.
44
        pb.clear()
0.140.1 by John Arbash Meinel
A simple plugin for generating author statistics, may grow into more.
45
46
        committer_list = sorted(((len(v), k, v) for k,v in committers.iteritems()), reverse=True)
47
        for count, k, v in committer_list:
48
            name = v[0].committer
49
            print '%4d %s' % (count, name)
50
51
52
bzrlib.commands.register_command(cmd_statistics)