/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Import processor that dump stats about the input (and doesn't import)."""
18
19
20
from bzrlib.trace import (
21
    note,
22
    warning,
23
    )
24
from bzrlib.plugins.fastimport import (
25
    commands,
26
    processor,
27
    )
28
29
30
# Maximum number of parents for a merge commit
31
_MAX_PARENTS = 16
32
33
34
class InfoProcessor(processor.ImportProcessor):
35
    """An import processor that dumps statistics about the input.
36
37
    No changes to the current repository are made.
38
39
    As well as providing useful information about an import
40
    stream before importing it, this processor is useful for
41
    benchmarking the speed at which data can be extracted from
42
    the source.
43
    """
44
0.64.8 by Ian Clatworthy
custom parameters for processors
45
    def __init__(self, target=None, params=None, verbose=False):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
46
        # Allow creation without a target
0.64.8 by Ian Clatworthy
custom parameters for processors
47
        processor.ImportProcessor.__init__(self, target, params, verbose)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
48
49
    def pre_process(self):
50
        # Init statistics
51
        self.cmd_counts = {}
52
        for cmd in commands.COMMAND_NAMES:
53
            self.cmd_counts[cmd] = 0
54
        self.file_cmd_counts = {}
55
        for fc in commands.FILE_COMMAND_NAMES:
56
            self.file_cmd_counts[fc] = 0
57
        self.parent_counts = {}
58
        for i in xrange(0, _MAX_PARENTS):
59
            self.parent_counts[i] = 0
60
        self.committers = set()
61
        self.separate_authors_found = False
62
        self.symlinks_found = False
63
        self.executables_found = False
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
64
        self.lightweight_tags = 0
65
        self.named_branches = []
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
66
67
    def post_process(self):
68
        # Dump statistics
69
        note("Command counts:")
70
        for cmd in commands.COMMAND_NAMES:
71
            note("\t%d\t%s", self.cmd_counts[cmd], cmd)
72
        note("File command counts:")
73
        for fc in commands.FILE_COMMAND_NAMES:
74
            note("\t%d\t%s", self.file_cmd_counts[fc], fc)
75
        if self.cmd_counts['commit']:
76
            note("Parent counts:")
77
            for i in xrange(0, _MAX_PARENTS):
78
                count = self.parent_counts[i]
79
                if count > 0:
80
                    note("\t%d\t%d", count, i)
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
81
            note("Other commit information:")
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
82
            note("\t%d\t%s" % (len(self.committers), 'unique committers'))
83
            note("\t%s\t%s" % (_found(self.separate_authors_found),
84
                'separate authors'))
85
            note("\t%s\t%s" % (_found(self.executables_found), 'executables'))
86
            note("\t%s\t%s" % (_found(self.symlinks_found), 'symlinks'))
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
87
        if self.cmd_counts['reset']:
88
            note("Reset information:")
89
            note("\t%d\t%s" % (self.lightweight_tags, 'of the reset commands are lightweight tags'))
90
            note("\t%s\t%s" % ('others', self.named_branches))
0.64.9 by Ian Clatworthy
dump parameter for info processor
91
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
92
    def progress_handler(self, cmd):
93
        """Process a ProgressCommand."""
94
        self.cmd_counts[cmd.name] += 1
95
96
    def blob_handler(self, cmd):
97
        """Process a BlobCommand."""
98
        self.cmd_counts[cmd.name] += 1
99
100
    def checkpoint_handler(self, cmd):
101
        """Process a CheckpointCommand."""
102
        self.cmd_counts[cmd.name] += 1
103
104
    def commit_handler(self, cmd):
105
        """Process a CommitCommand."""
106
        self.cmd_counts[cmd.name] += 1
107
        self.parent_counts[len(cmd.parents)] += 1
108
        self.committers.add(cmd.committer)
109
        if cmd.author is not None:
110
            self.separate_authors_found = True
111
        for fc in cmd.file_iter():
112
            self.file_cmd_counts[fc.name] += 1
113
            if isinstance(fc, commands.FileModifyCommand):
114
                if fc.is_executable:
115
                    self.executables_found = True
116
                if fc.kind == commands.SYMLINK_KIND:
117
                    self.symlinks_found = True
118
119
    def reset_handler(self, cmd):
120
        """Process a ResetCommand."""
121
        self.cmd_counts[cmd.name] += 1
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
122
        if cmd.ref.startswith('refs/tags/'):
123
            self.lightweight_tags += 1
124
        else:
125
            self.named_branches.append(cmd.ref)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
126
127
    def tag_handler(self, cmd):
128
        """Process a TagCommand."""
129
        self.cmd_counts[cmd.name] += 1
130
131
132
def _found(b):
133
    """Format a found boolean as a string."""
134
    return ['no', 'found'][b]