/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 send.py

Use context managers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
    def _generate_commit(cls, repository, revision_id, num, total):
132
132
        s = StringIO()
133
133
        store = get_object_store(repository)
134
 
        store.lock_read()
135
 
        try:
 
134
        with store.lock_read():
136
135
            commit = store[store._lookup_revision_sha1(revision_id)]
137
 
        finally:
138
 
            store.unlock()
139
136
        from dulwich.patch import write_commit_patch, get_summary
140
137
        try:
141
138
            lhs_parent = repository.get_revision(revision_id).parent_ids[0]
158
155
                     public_branch=None, message=None):
159
156
        patches = []
160
157
        submit_branch = _mod_branch.Branch.open(target_branch)
161
 
        submit_branch.lock_read()
162
 
        try:
 
158
        with submit_branch.lock_read():
163
159
            submit_revision_id = submit_branch.last_revision()
164
160
            repository.fetch(submit_branch.repository, submit_revision_id)
165
161
            graph = repository.get_graph()
168
164
            for i, revid in enumerate(graph.iter_topo_order(todo)):
169
165
                patches.append(cls._generate_commit(repository, revid, i+1,
170
166
                    total))
171
 
        finally:
172
 
            submit_branch.unlock()
173
167
        return cls(revision_id, None, time, timezone,
174
168
            target_branch=target_branch, source_branch=public_branch,
175
169
            message=message, patches=patches)