/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-03-24 17:48:04 UTC
  • mfrom: (6921 work)
  • mto: This revision was merged to the branch mainline in revision 6923.
  • Revision ID: jelmer@jelmer.uk-20180324174804-xf22o05byoj12x1q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
 
144
144
    email_users = {} # user@email.com => User Name
145
145
    combo_count = {}
146
 
    pb = ui.ui_factory.nested_progress_bar()
147
 
    try:
 
146
    with ui.ui_factory.nested_progress_bar() as pb:
148
147
        trace.note('getting revisions')
149
 
        revisions = a_repo.iter_revisions(revids)
 
148
        revisions = list(a_repo.iter_revisions(revids))
150
149
        for count, (revid, rev) in enumerate(revisions):
151
150
            pb.update('checking', count, len(revids))
152
151
            for author in rev.get_apparent_authors():
156
155
                email_users.setdefault(email, set()).add(username)
157
156
                combo = (username, email)
158
157
                combo_count[combo] = combo_count.setdefault(combo, 0) + 1
159
 
    finally:
160
 
        pb.finished()
161
 
    return revisions, collapse_email_and_users(email_users, combo_count)
 
158
    return ((rev for (revid, rev) in revisions),
 
159
            collapse_email_and_users(email_users, combo_count))
162
160
 
163
161
 
164
162
def get_info(a_repo, revision):
165
163
    """Get all of the information for a particular revision"""
166
 
    pb = ui.ui_factory.nested_progress_bar()
167
 
    a_repo.lock_read()
168
 
    try:
 
164
    with ui.ui_factory.nested_progress_bar() as pb, a_repo.lock_read():
169
165
        trace.note('getting ancestry')
170
166
        graph = a_repo.get_graph()
171
167
        ancestry = [
172
168
            r for (r, ps) in graph.iter_ancestry([revision])
173
169
            if ps is not None and r != NULL_REVISION]
174
170
        revs, canonical_committer = get_revisions_and_committers(a_repo, ancestry)
175
 
    finally:
176
 
        a_repo.unlock()
177
 
        pb.finished()
178
171
 
179
172
    return collapse_by_person(revs, canonical_committer)
180
173
 
184
177
 
185
178
    This lets us figure out what has actually changed between 2 revisions.
186
179
    """
187
 
    pb = ui.ui_factory.nested_progress_bar()
188
 
    a_repo.lock_read()
189
 
    try:
 
180
    with ui.ui_factory.nested_progress_bar() as pb, a_repo.lock_read():
190
181
        graph = a_repo.get_graph()
191
182
        trace.note('getting ancestry diff')
192
183
        ancestry = graph.find_difference(start_rev, end_rev)[1]
193
184
        revs, canonical_committer = get_revisions_and_committers(a_repo, ancestry)
194
 
    finally:
195
 
        a_repo.unlock()
196
 
        pb.finished()
197
185
 
198
186
    return collapse_by_person(revs, canonical_committer)
199
187
 
314
302
def gather_class_stats(repository, revs):
315
303
    ret = {}
316
304
    total = 0
317
 
    pb = ui.ui_factory.nested_progress_bar()
318
 
    try:
 
305
    with ui.ui_factory.nested_progress_bar() as pb:
319
306
        with repository.lock_read():
320
307
            i = 0
321
308
            for delta in repository.get_deltas_for_revisions(revs):
326
313
                    ret[c] += 1
327
314
                    total += 1
328
315
                i += 1
329
 
    finally:
330
 
        pb.finished()
331
316
    return ret, total
332
317
 
333
318
 
367
352
        ancestry = [r for (r, ps) in graph.iter_ancestry([revid])
368
353
                    if ps is not None and r != NULL_REVISION]
369
354
        revs = repository.get_revisions(ancestry)
370
 
        pb = ui.ui_factory.nested_progress_bar()
371
 
        try:
 
355
        with ui.ui_factory.nested_progress_bar() as pb:
372
356
            iterator = zip(revs, repository.get_deltas_for_revisions(revs))
373
357
            for i, (rev, delta) in enumerate(iterator):
374
358
                pb.update("analysing revisions", i, len(revs))
380
364
                        if not author in ret[c]:
381
365
                            ret[c][author] = 0
382
366
                        ret[c][author] += 1
383
 
        finally:
384
 
            pb.finished()
385
367
    def sort_class(name):
386
368
        return [author
387
369
            for author, _  in sorted(ret[name].items(), key=classify_key)]