/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to processors/info_processor.py

blob tracking analysis and verbose mode for info processor

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        self.separate_authors_found = False
62
62
        self.symlinks_found = False
63
63
        self.executables_found = False
 
64
        self.sha_blob_references = False
64
65
        self.lightweight_tags = 0
65
66
        self.named_branches = []
 
67
        # Blob usage tracking
 
68
        self.blobs = {}
 
69
        for usage in ['new', 'used', 'multi', 'unknown']:
 
70
            self.blobs[usage] = set()
 
71
 
66
72
 
67
73
    def post_process(self):
68
74
        # 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.verbose:
 
76
            note('# Configuration file generated by bzr fast-import --info')
 
77
        cmd_names = commands.COMMAND_NAMES
 
78
        fc_names = commands.FILE_COMMAND_NAMES
 
79
        cmd_values = [self.cmd_counts[c] for c in cmd_names]
 
80
        fc_values = [self.file_cmd_counts[c] for c in fc_names]
 
81
        self._dump_stats_group("Command counts", cmd_names, cmd_values, str)
 
82
        self._dump_stats_group("File command counts", fc_names, fc_values, str)
 
83
 
 
84
        # Commit stats
75
85
        if self.cmd_counts['commit']:
76
 
            note("Parent counts:")
 
86
            p_names = []
 
87
            p_values = []
77
88
            for i in xrange(0, _MAX_PARENTS):
78
89
                count = self.parent_counts[i]
79
90
                if count > 0:
80
 
                    note("\t%d\t%d", count, i)
81
 
            note("Other commit information:")
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'))
 
91
                    p_names.append("parents-%d" % i)
 
92
                    p_values.append(count)
 
93
            flags = {
 
94
                'separate authors found': self.separate_authors_found,
 
95
                'executables': self.executables_found,
 
96
                'symlinks': self.symlinks_found,
 
97
                'blobs referenced by SHA': self.sha_blob_references,
 
98
                }
 
99
            self._dump_stats_group("Parent counts", p_names, p_values, str)
 
100
            self._dump_stats_group("Commit analysis", flags.keys(),
 
101
                flags.values(), _found)
 
102
            # note("\t%d\t%s" % (len(self.committers), 'unique committers'))
 
103
 
 
104
        # Blob stats
 
105
        if self.cmd_counts['blob']:
 
106
            # In verbose mode, don't list every blob used
 
107
            if self.verbose:
 
108
                del self.blobs['used']
 
109
            self._dump_stats_group("Blob usage tracking", self.blobs.keys(),
 
110
                self.blobs.values(), len)
 
111
 
 
112
        # Other stats
87
113
        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))
 
114
            reset_stats = {
 
115
                'lightweight tags': self.lightweight_tags,
 
116
                'other resets': self.named_branches,
 
117
                }
 
118
            self._dump_stats_group("Reset analysis", reset_stats.keys(),
 
119
                reset_stats.values())
 
120
 
 
121
    def _dump_stats_group(self, title, names, values, formatter):
 
122
        """Dump a statistics group.
 
123
        
 
124
        In verbose mode, do so as a config file so
 
125
        that other processors can load the information if they want to.
 
126
        """
 
127
        if self.verbose:
 
128
            print "[%s]" % (title,)
 
129
            for name, value in zip(names, values):
 
130
                print "%s = %s" % (name.replace(' ', '-'),value)
 
131
            print ""
 
132
        else:
 
133
            print "%s:" % (title,)
 
134
            for name, value in zip(names, values):
 
135
                if formatter is not None:
 
136
                    value = formatter(value)
 
137
                print "\t%s\t%s" % (value,name)
91
138
 
92
139
    def progress_handler(self, cmd):
93
140
        """Process a ProgressCommand."""
96
143
    def blob_handler(self, cmd):
97
144
        """Process a BlobCommand."""
98
145
        self.cmd_counts[cmd.name] += 1
 
146
        self.blobs['new'].add(cmd.mark)
99
147
 
100
148
    def checkpoint_handler(self, cmd):
101
149
        """Process a CheckpointCommand."""
115
163
                    self.executables_found = True
116
164
                if fc.kind == commands.SYMLINK_KIND:
117
165
                    self.symlinks_found = True
 
166
                if fc.dataref is not None:
 
167
                    if fc.dataref[0] == ':':
 
168
                        self._track_blob(fc.dataref[1:])
 
169
                    else:
 
170
                        self.sha_blob_references = True
118
171
 
119
172
    def reset_handler(self, cmd):
120
173
        """Process a ResetCommand."""
128
181
        """Process a TagCommand."""
129
182
        self.cmd_counts[cmd.name] += 1
130
183
 
 
184
    def _track_blob(self, mark):
 
185
        if mark in self.blobs['multi']:
 
186
            pass
 
187
        elif mark in self.blobs['used']:
 
188
            self.blobs['multi'].add(mark)
 
189
            self.blobs['used'].remove(mark)
 
190
        elif mark in self.blobs['new']:
 
191
            self.blobs['used'].add(mark)
 
192
            self.blobs['new'].remove(mark)
 
193
        else:
 
194
            self.blobs['unknown'].add(mark)
131
195
 
132
196
def _found(b):
133
197
    """Format a found boolean as a string."""