Merge lp:~spiv/bzr/reconcile-cleanup-503878 into lp:bzr

Proposed by Andrew Bennetts
Status: Merged
Approved by: John A Meinel
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~spiv/bzr/reconcile-cleanup-503878
Merge into: lp:bzr
Diff against target: 120 lines (+37/-34)
2 files modified
NEWS (+3/-0)
bzrlib/reconcile.py (+34/-34)
To merge this branch: bzr merge lp:~spiv/bzr/reconcile-cleanup-503878
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+16944@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

This replaces some try/finally blocks in reconcile.py with more robust add_cleanup calls using OperationWithCleanups. This fixes bug 503878 and probably a few unreported ones like it.

(This borrows the definition of OperationWithCleanups.run_simple from <https://code.edge.launchpad.net/~spiv/bzr/command-cleanup/+merge/16943>)

Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-01-13 23:26:10 +0000
+++ NEWS 2010-01-13 23:33:13 +0000
@@ -71,6 +71,9 @@
71 returns ``EINTR`` by calling ``PyErr_CheckSignals``. This affected the71 returns ``EINTR`` by calling ``PyErr_CheckSignals``. This affected the
72 optional ``_readdir_pyx`` extension. (Andrew Bennetts, #495023)72 optional ``_readdir_pyx`` extension. (Andrew Bennetts, #495023)
7373
74* Fix "Too many concurrent requests" in reconcile when network connection
75 fails. (Andrew Bennetts, #503878)
76
74* Fixed a side effect mutation of ``RemoteBzrDirFormat._network_name``77* Fixed a side effect mutation of ``RemoteBzrDirFormat._network_name``
75 that caused some tests to fail when run in a non-default order.78 that caused some tests to fail when run in a non-default order.
76 Probably no user impact. (Martin Pool, #504102)79 Probably no user impact. (Martin Pool, #504102)
7780
=== modified file 'bzrlib/reconcile.py'
--- bzrlib/reconcile.py 2009-09-24 04:54:19 +0000
+++ bzrlib/reconcile.py 2010-01-13 23:33:13 +0000
@@ -27,12 +27,12 @@
2727
2828
29from bzrlib import (29from bzrlib import (
30 cleanup,
30 errors,31 errors,
31 ui,32 ui,
32 repository,33 repository,
33 repofmt,
34 )34 )
35from bzrlib.trace import mutter, note35from bzrlib.trace import mutter
36from bzrlib.tsort import topo_sort36from bzrlib.tsort import topo_sort
37from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory37from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
3838
@@ -120,15 +120,16 @@
120 self.branch = a_branch120 self.branch = a_branch
121121
122 def reconcile(self):122 def reconcile(self):
123 operation = cleanup.OperationWithCleanups(self._reconcile)
124 self.add_cleanup = operation.add_cleanup
125 operation.run_simple()
126
127 def _reconcile(self):
123 self.branch.lock_write()128 self.branch.lock_write()
124 try:129 self.add_cleanup(self.branch.unlock)
125 self.pb = ui.ui_factory.nested_progress_bar()130 self.pb = ui.ui_factory.nested_progress_bar()
126 try:131 self.add_cleanup(self.pb.finished)
127 self._reconcile_steps()132 self._reconcile_steps()
128 finally:
129 self.pb.finished()
130 finally:
131 self.branch.unlock()
132133
133 def _reconcile_steps(self):134 def _reconcile_steps(self):
134 self._reconcile_revision_history()135 self._reconcile_revision_history()
@@ -192,15 +193,16 @@
192 garbage_inventories: The number of inventory objects without revisions193 garbage_inventories: The number of inventory objects without revisions
193 that were garbage collected.194 that were garbage collected.
194 """195 """
196 operation = cleanup.OperationWithCleanups(self._reconcile)
197 self.add_cleanup = operation.add_cleanup
198 operation.run_simple()
199
200 def _reconcile(self):
195 self.repo.lock_write()201 self.repo.lock_write()
196 try:202 self.add_cleanup(self.repo.unlock)
197 self.pb = ui.ui_factory.nested_progress_bar()203 self.pb = ui.ui_factory.nested_progress_bar()
198 try:204 self.add_cleanup(self.pb.finished)
199 self._reconcile_steps()205 self._reconcile_steps()
200 finally:
201 self.pb.finished()
202 finally:
203 self.repo.unlock()
204206
205 def _reconcile_steps(self):207 def _reconcile_steps(self):
206 """Perform the steps to reconcile this repository."""208 """Perform the steps to reconcile this repository."""
@@ -502,23 +504,21 @@
502 collection = self.repo._pack_collection504 collection = self.repo._pack_collection
503 collection.ensure_loaded()505 collection.ensure_loaded()
504 collection.lock_names()506 collection.lock_names()
505 try:507 self.add_cleanup(collection._unlock_names)
506 packs = collection.all_packs()508 packs = collection.all_packs()
507 all_revisions = self.repo.all_revision_ids()509 all_revisions = self.repo.all_revision_ids()
508 total_inventories = len(list(510 total_inventories = len(list(
509 collection.inventory_index.combined_index.iter_all_entries()))511 collection.inventory_index.combined_index.iter_all_entries()))
510 if len(all_revisions):512 if len(all_revisions):
511 new_pack = self.repo._reconcile_pack(collection, packs,513 new_pack = self.repo._reconcile_pack(collection, packs,
512 ".reconcile", all_revisions, self.pb)514 ".reconcile", all_revisions, self.pb)
513 if new_pack is not None:515 if new_pack is not None:
514 self._discard_and_save(packs)
515 else:
516 # only make a new pack when there is data to copy.
517 self._discard_and_save(packs)516 self._discard_and_save(packs)
518 self.garbage_inventories = total_inventories - len(list(517 else:
519 collection.inventory_index.combined_index.iter_all_entries()))518 # only make a new pack when there is data to copy.
520 finally:519 self._discard_and_save(packs)
521 collection._unlock_names()520 self.garbage_inventories = total_inventories - len(list(
521 collection.inventory_index.combined_index.iter_all_entries()))
522522
523 def _discard_and_save(self, packs):523 def _discard_and_save(self, packs):
524 """Discard some packs from the repository.524 """Discard some packs from the repository.