/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: Vincent Ladeuil
  • Author(s): Jelmer Vernooij
  • Date: 2018-03-01 05:46:59 UTC
  • mfrom: (6861.4.1 pb-context)
  • Revision ID: v.ladeuil+lp@free.fr-20180301054659-7fzum8cexsk421r3
Make progress bars context managers.

Merged from https://code.launchpad.net/~jelmer/brz/pb-context/+merge/339449

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