/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 breezy/plugins/stats/cmds.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from __future__ import absolute_import
19
19
 
20
 
import operator
21
 
 
22
20
from ... import (
23
21
    branch,
24
22
    commands,
61
59
            info[2][username] = info[2].setdefault(username, 0) + 1
62
60
    res = [(len(revs), revs, emails, fnames)
63
61
           for revs, emails, fnames in committer_to_info.values()]
64
 
 
65
 
    def key_fn(item):
66
 
        return item[0], list(item[2].keys())
67
 
    res.sort(reverse=True, key=key_fn)
 
62
    res.sort(reverse=True)
68
63
    return res
69
64
 
70
65
 
100
95
            # email
101
96
            for user in usernames:
102
97
                if not user:
103
 
                    continue  # The mysterious ('', '') user
 
98
                    continue # The mysterious ('', '') user
104
99
                # When mapping, use case-insensitive names
105
100
                low_user = user.lower()
106
101
                user_id = username_to_id.get(low_user)
136
131
    combo_to_best_combo = {}
137
132
    for cur_id, combos in id_to_combos.items():
138
133
        best_combo = sorted(combos,
139
 
                            key=lambda x: combo_count[x],
 
134
                            key=lambda x:combo_count[x],
140
135
                            reverse=True)[0]
141
136
        for combo in combos:
142
137
            combo_to_best_combo[combo] = best_combo
146
141
def get_revisions_and_committers(a_repo, revids):
147
142
    """Get the Revision information, and the best-match for committer."""
148
143
 
149
 
    email_users = {}  # user@email.com => User Name
 
144
    email_users = {} # user@email.com => User Name
150
145
    combo_count = {}
151
146
    with ui.ui_factory.nested_progress_bar() as pb:
152
147
        trace.note('getting revisions')
172
167
        ancestry = [
173
168
            r for (r, ps) in graph.iter_ancestry([revision])
174
169
            if ps is not None and r != NULL_REVISION]
175
 
        revs, canonical_committer = get_revisions_and_committers(
176
 
            a_repo, ancestry)
 
170
        revs, canonical_committer = get_revisions_and_committers(a_repo, ancestry)
177
171
 
178
172
    return collapse_by_person(revs, canonical_committer)
179
173
 
187
181
        graph = a_repo.get_graph()
188
182
        trace.note('getting ancestry diff')
189
183
        ancestry = graph.find_difference(start_rev, end_rev)[1]
190
 
        revs, canonical_committer = get_revisions_and_committers(
191
 
            a_repo, ancestry)
 
184
        revs, canonical_committer = get_revisions_and_committers(a_repo, ancestry)
192
185
 
193
186
    return collapse_by_person(revs, canonical_committer)
194
187
 
199
192
    for count, revs, emails, fullnames in info:
200
193
        # Get the most common email name
201
194
        sorted_emails = sorted(((count, email)
202
 
                                for email, count in emails.items()),
 
195
                               for email, count in emails.items()),
203
196
                               reverse=True)
204
197
        sorted_fullnames = sorted(((count, fullname)
205
 
                                   for fullname, count in fullnames.items()),
 
198
                                  for fullname, count in fullnames.items()),
206
199
                                  reverse=True)
207
200
        if sorted_fullnames[0][1] == '' and sorted_emails[0][1] == '':
208
201
            to_file.write('%4d %s\n'
233
226
            for name, count in sorted(classes.items(), key=classify_key):
234
227
                if name is None:
235
228
                    name = "Unknown"
236
 
                to_file.write("     %4.0f%% %s\n" %
237
 
                              ((float(count) / total) * 100.0, name))
 
229
                to_file.write("     %4.0f%% %s\n" % ((float(count) / total) * 100.0, name))
238
230
 
239
231
 
240
232
class cmd_committer_statistics(commands.Command):
242
234
 
243
235
    aliases = ['stats', 'committer-stats']
244
236
    takes_args = ['location?']
245
 
    takes_options = ['revision',
246
 
                     option.Option('show-class', help="Show the class of contributions.")]
 
237
    takes_options = ['revision', 
 
238
            option.Option('show-class', help="Show the class of contributions.")]
247
239
 
248
240
    encoding_type = 'replace'
249
241
 
284
276
 
285
277
    encoding_type = 'replace'
286
278
 
287
 
    hidden = True
288
 
 
289
279
    def run(self, location='.'):
290
280
        try:
291
281
            wt = workingtree.WorkingTree.open_containing(location)[0]
318
308
            for delta in repository.get_deltas_for_revisions(revs):
319
309
                pb.update("classifying commits", i, len(revs))
320
310
                for c in classify_delta(delta):
321
 
                    if c not in ret:
 
311
                    if not c in ret:
322
312
                        ret[c] = 0
323
313
                    ret[c] += 1
324
314
                    total += 1
333
323
 
334
324
def display_credits(credits, to_file):
335
325
    (coders, documenters, artists, translators) = credits
336
 
 
337
326
    def print_section(name, lst):
338
327
        if len(lst) == 0:
339
328
            return
372
361
                    continue
373
362
                for c in set(classify_delta(delta)):
374
363
                    for author in rev.get_apparent_authors():
375
 
                        if author not in ret[c]:
 
364
                        if not author in ret[c]:
376
365
                            ret[c][author] = 0
377
366
                        ret[c][author] += 1
378
 
 
379
367
    def sort_class(name):
380
368
        return [author
381
 
                for author, _ in sorted(ret[name].items(), key=classify_key)]
 
369
            for author, _  in sorted(ret[name].items(), key=classify_key)]
382
370
    return (sort_class("code"), sort_class("documentation"), sort_class("art"), sort_class("translation"))
383
371
 
384
372