Merge lp:~jelmer/brz/write-group-context into lp:brz
- write-group-context
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | no longer in the source branch. |
Merge reported by: | The Breezy Bot |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/brz/write-group-context |
Merge into: | lp:brz |
Diff against target: |
857 lines (+116/-282) 20 files modified
breezy/builtins.py (+4/-21) breezy/bundle/serializer/v4.py (+3/-8) breezy/bzr/vf_repository.py (+2/-7) breezy/commit_signature_commands.py (+2/-7) breezy/plugins/repodebug/missing_keys_for_stacking_fixer.py (+2/-7) breezy/repository.py (+22/-0) breezy/tests/blackbox/test_reconcile.py (+3/-4) breezy/tests/per_controldir/test_controldir.py (+3/-5) breezy/tests/per_interrepository/test_fetch.py (+3/-13) breezy/tests/per_interrepository/test_interrepository.py (+9/-13) breezy/tests/per_pack_repository.py (+4/-19) breezy/tests/per_repository/test_signatures.py (+2/-12) breezy/tests/per_repository_chk/test_supported.py (+15/-51) breezy/tests/per_repository_reference/test_add_inventory.py (+3/-12) breezy/tests/per_repository_reference/test_add_revision.py (+5/-14) breezy/tests/per_repository_reference/test_add_signature_text.py (+6/-14) breezy/tests/per_repository_vf/helpers.py (+5/-13) breezy/tests/per_repository_vf/test_check_reconcile.py (+4/-9) breezy/tests/per_repository_vf/test_repository.py (+6/-21) breezy/tests/test_inv.py (+13/-32) |
To merge this branch: | bzr merge lp:~jelmer/brz/write-group-context |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+358465@code.launchpad.net |
Commit message
Add a WriteGroup() context manager.
Description of the change
Add a WriteGroup() context manager.
To post a comment you must log in.
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/builtins.py' | |||
2 | --- breezy/builtins.py 2019-05-28 21:53:23 +0000 | |||
3 | +++ breezy/builtins.py 2019-05-29 03:45:01 +0000 | |||
4 | @@ -5260,29 +5260,18 @@ | |||
5 | 5260 | return self._run(b, revision_id_list, revision) | 5260 | return self._run(b, revision_id_list, revision) |
6 | 5261 | 5261 | ||
7 | 5262 | def _run(self, b, revision_id_list, revision): | 5262 | def _run(self, b, revision_id_list, revision): |
8 | 5263 | from .repository import WriteGroup | ||
9 | 5263 | gpg_strategy = gpg.GPGStrategy(b.get_config_stack()) | 5264 | gpg_strategy = gpg.GPGStrategy(b.get_config_stack()) |
10 | 5264 | if revision_id_list is not None: | 5265 | if revision_id_list is not None: |
13 | 5265 | b.repository.start_write_group() | 5266 | with WriteGroup(b.repository): |
12 | 5266 | try: | ||
14 | 5267 | for revision_id in revision_id_list: | 5267 | for revision_id in revision_id_list: |
15 | 5268 | revision_id = cache_utf8.encode(revision_id) | 5268 | revision_id = cache_utf8.encode(revision_id) |
16 | 5269 | b.repository.sign_revision(revision_id, gpg_strategy) | 5269 | b.repository.sign_revision(revision_id, gpg_strategy) |
17 | 5270 | except BaseException: | ||
18 | 5271 | b.repository.abort_write_group() | ||
19 | 5272 | raise | ||
20 | 5273 | else: | ||
21 | 5274 | b.repository.commit_write_group() | ||
22 | 5275 | elif revision is not None: | 5270 | elif revision is not None: |
23 | 5276 | if len(revision) == 1: | 5271 | if len(revision) == 1: |
24 | 5277 | revno, rev_id = revision[0].in_history(b) | 5272 | revno, rev_id = revision[0].in_history(b) |
27 | 5278 | b.repository.start_write_group() | 5273 | with WriteGroup(b.repository): |
26 | 5279 | try: | ||
28 | 5280 | b.repository.sign_revision(rev_id, gpg_strategy) | 5274 | b.repository.sign_revision(rev_id, gpg_strategy) |
29 | 5281 | except BaseException: | ||
30 | 5282 | b.repository.abort_write_group() | ||
31 | 5283 | raise | ||
32 | 5284 | else: | ||
33 | 5285 | b.repository.commit_write_group() | ||
34 | 5286 | elif len(revision) == 2: | 5275 | elif len(revision) == 2: |
35 | 5287 | # are they both on rh- if so we can walk between them | 5276 | # are they both on rh- if so we can walk between them |
36 | 5288 | # might be nice to have a range helper for arbitrary | 5277 | # might be nice to have a range helper for arbitrary |
37 | @@ -5294,16 +5283,10 @@ | |||
38 | 5294 | if from_revno is None or to_revno is None: | 5283 | if from_revno is None or to_revno is None: |
39 | 5295 | raise errors.BzrCommandError( | 5284 | raise errors.BzrCommandError( |
40 | 5296 | gettext('Cannot sign a range of non-revision-history revisions')) | 5285 | gettext('Cannot sign a range of non-revision-history revisions')) |
43 | 5297 | b.repository.start_write_group() | 5286 | with WriteGroup(b.repository): |
42 | 5298 | try: | ||
44 | 5299 | for revno in range(from_revno, to_revno + 1): | 5287 | for revno in range(from_revno, to_revno + 1): |
45 | 5300 | b.repository.sign_revision(b.get_rev_id(revno), | 5288 | b.repository.sign_revision(b.get_rev_id(revno), |
46 | 5301 | gpg_strategy) | 5289 | gpg_strategy) |
47 | 5302 | except BaseException: | ||
48 | 5303 | b.repository.abort_write_group() | ||
49 | 5304 | raise | ||
50 | 5305 | else: | ||
51 | 5306 | b.repository.commit_write_group() | ||
52 | 5307 | else: | 5290 | else: |
53 | 5308 | raise errors.BzrCommandError( | 5291 | raise errors.BzrCommandError( |
54 | 5309 | gettext('Please supply either one revision, or a range.')) | 5292 | gettext('Please supply either one revision, or a range.')) |
55 | 5310 | 5293 | ||
56 | === modified file 'breezy/bundle/serializer/v4.py' | |||
57 | --- breezy/bundle/serializer/v4.py 2018-11-11 04:08:32 +0000 | |||
58 | +++ breezy/bundle/serializer/v4.py 2019-05-29 03:45:01 +0000 | |||
59 | @@ -26,6 +26,7 @@ | |||
60 | 26 | lru_cache, | 26 | lru_cache, |
61 | 27 | multiparent, | 27 | multiparent, |
62 | 28 | osutils, | 28 | osutils, |
63 | 29 | repository as _mod_repository, | ||
64 | 29 | revision as _mod_revision, | 30 | revision as _mod_revision, |
65 | 30 | trace, | 31 | trace, |
66 | 31 | ui, | 32 | ui, |
67 | @@ -519,14 +520,8 @@ | |||
68 | 519 | 520 | ||
69 | 520 | Must be called with the Repository locked. | 521 | Must be called with the Repository locked. |
70 | 521 | """ | 522 | """ |
79 | 522 | self._repository.start_write_group() | 523 | with _mod_repository.WriteGroup(self._repository): |
80 | 523 | try: | 524 | return self._install_in_write_group() |
73 | 524 | result = self._install_in_write_group() | ||
74 | 525 | except: | ||
75 | 526 | self._repository.abort_write_group() | ||
76 | 527 | raise | ||
77 | 528 | self._repository.commit_write_group() | ||
78 | 529 | return result | ||
81 | 530 | 525 | ||
82 | 531 | def _install_in_write_group(self): | 526 | def _install_in_write_group(self): |
83 | 532 | current_file = None | 527 | current_file = None |
84 | 533 | 528 | ||
85 | === modified file 'breezy/bzr/vf_repository.py' | |||
86 | --- breezy/bzr/vf_repository.py 2019-02-04 19:39:30 +0000 | |||
87 | +++ breezy/bzr/vf_repository.py 2019-05-29 03:45:01 +0000 | |||
88 | @@ -68,6 +68,7 @@ | |||
89 | 68 | InterRepository, | 68 | InterRepository, |
90 | 69 | Repository, | 69 | Repository, |
91 | 70 | RepositoryFormat, | 70 | RepositoryFormat, |
92 | 71 | WriteGroup, | ||
93 | 71 | ) | 72 | ) |
94 | 72 | from .repository import ( | 73 | from .repository import ( |
95 | 73 | MetaDirRepository, | 74 | MetaDirRepository, |
96 | @@ -2863,8 +2864,7 @@ | |||
97 | 2863 | Accepts an iterable of revision, tree, signature tuples. The signature | 2864 | Accepts an iterable of revision, tree, signature tuples. The signature |
98 | 2864 | may be None. | 2865 | may be None. |
99 | 2865 | """ | 2866 | """ |
102 | 2866 | repository.start_write_group() | 2867 | with WriteGroup(repository): |
101 | 2867 | try: | ||
103 | 2868 | inventory_cache = lru_cache.LRUCache(10) | 2868 | inventory_cache = lru_cache.LRUCache(10) |
104 | 2869 | for n, (revision, revision_tree, signature) in enumerate(iterable): | 2869 | for n, (revision, revision_tree, signature) in enumerate(iterable): |
105 | 2870 | _install_revision(repository, revision, revision_tree, signature, | 2870 | _install_revision(repository, revision, revision_tree, signature, |
106 | @@ -2872,11 +2872,6 @@ | |||
107 | 2872 | if pb is not None: | 2872 | if pb is not None: |
108 | 2873 | pb.update(gettext('Transferring revisions'), | 2873 | pb.update(gettext('Transferring revisions'), |
109 | 2874 | n + 1, num_revisions) | 2874 | n + 1, num_revisions) |
110 | 2875 | except: | ||
111 | 2876 | repository.abort_write_group() | ||
112 | 2877 | raise | ||
113 | 2878 | else: | ||
114 | 2879 | repository.commit_write_group() | ||
115 | 2880 | 2875 | ||
116 | 2881 | 2876 | ||
117 | 2882 | def _install_revision(repository, rev, revision_tree, signature, | 2877 | def _install_revision(repository, rev, revision_tree, signature, |
118 | 2883 | 2878 | ||
119 | === modified file 'breezy/commit_signature_commands.py' | |||
120 | --- breezy/commit_signature_commands.py 2018-11-12 01:41:38 +0000 | |||
121 | +++ breezy/commit_signature_commands.py 2019-05-29 03:45:01 +0000 | |||
122 | @@ -22,6 +22,7 @@ | |||
123 | 22 | controldir, | 22 | controldir, |
124 | 23 | errors, | 23 | errors, |
125 | 24 | gpg, | 24 | gpg, |
126 | 25 | repository as _mod_repository, | ||
127 | 25 | revision as _mod_revision, | 26 | revision as _mod_revision, |
128 | 26 | ) | 27 | ) |
129 | 27 | from .commands import Command | 28 | from .commands import Command |
130 | @@ -66,8 +67,7 @@ | |||
131 | 66 | count = 0 | 67 | count = 0 |
132 | 67 | with repo.lock_write(): | 68 | with repo.lock_write(): |
133 | 68 | graph = repo.get_graph() | 69 | graph = repo.get_graph() |
136 | 69 | repo.start_write_group() | 70 | with _mod_repository.WriteGroup(repo): |
135 | 70 | try: | ||
137 | 71 | for rev_id, parents in graph.iter_ancestry( | 71 | for rev_id, parents in graph.iter_ancestry( |
138 | 72 | [branch.last_revision()]): | 72 | [branch.last_revision()]): |
139 | 73 | if _mod_revision.is_null(rev_id): | 73 | if _mod_revision.is_null(rev_id): |
140 | @@ -86,11 +86,6 @@ | |||
141 | 86 | count += 1 | 86 | count += 1 |
142 | 87 | if not dry_run: | 87 | if not dry_run: |
143 | 88 | repo.sign_revision(rev_id, gpg_strategy) | 88 | repo.sign_revision(rev_id, gpg_strategy) |
144 | 89 | except BaseException: | ||
145 | 90 | repo.abort_write_group() | ||
146 | 91 | raise | ||
147 | 92 | else: | ||
148 | 93 | repo.commit_write_group() | ||
149 | 94 | self.outf.write( | 89 | self.outf.write( |
150 | 95 | ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', | 90 | ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', |
151 | 96 | count) % count) | 91 | count) % count) |
152 | 97 | 92 | ||
153 | === modified file 'breezy/plugins/repodebug/missing_keys_for_stacking_fixer.py' | |||
154 | --- breezy/plugins/repodebug/missing_keys_for_stacking_fixer.py 2018-11-11 04:08:32 +0000 | |||
155 | +++ breezy/plugins/repodebug/missing_keys_for_stacking_fixer.py 2019-05-29 03:45:01 +0000 | |||
156 | @@ -21,6 +21,7 @@ | |||
157 | 21 | from ... import errors | 21 | from ... import errors |
158 | 22 | from ...sixish import viewvalues | 22 | from ...sixish import viewvalues |
159 | 23 | from ...bzr.vf_search import PendingAncestryResult | 23 | from ...bzr.vf_search import PendingAncestryResult |
160 | 24 | from ...repository import WriteGroup | ||
161 | 24 | from ...revision import NULL_REVISION | 25 | from ...revision import NULL_REVISION |
162 | 25 | 26 | ||
163 | 26 | 27 | ||
164 | @@ -77,14 +78,8 @@ | |||
165 | 77 | assert raw_r._format.network_name() == b.repository._format.network_name() | 78 | assert raw_r._format.network_name() == b.repository._format.network_name() |
166 | 78 | stream = b.repository.inventories.get_record_stream( | 79 | stream = b.repository.inventories.get_record_stream( |
167 | 79 | needed, 'topological', True) | 80 | needed, 'topological', True) |
170 | 80 | raw_r.start_write_group() | 81 | with WriteGroup(raw_r): |
169 | 81 | try: | ||
171 | 82 | raw_r.inventories.insert_record_stream(stream) | 82 | raw_r.inventories.insert_record_stream(stream) |
172 | 83 | except: | ||
173 | 84 | raw_r.abort_write_group() | ||
174 | 85 | raise | ||
175 | 86 | else: | ||
176 | 87 | raw_r.commit_write_group() | ||
177 | 88 | finally: | 83 | finally: |
178 | 89 | raw_r.unlock() | 84 | raw_r.unlock() |
179 | 90 | b.unlock() | 85 | b.unlock() |
180 | 91 | 86 | ||
181 | === modified file 'breezy/repository.py' | |||
182 | --- breezy/repository.py 2019-02-04 19:39:30 +0000 | |||
183 | +++ breezy/repository.py 2019-05-29 03:45:01 +0000 | |||
184 | @@ -236,6 +236,28 @@ | |||
185 | 236 | self.unlock) | 236 | self.unlock) |
186 | 237 | 237 | ||
187 | 238 | 238 | ||
188 | 239 | class WriteGroup(object): | ||
189 | 240 | """Context manager that manages a write group. | ||
190 | 241 | |||
191 | 242 | Raising an exception will result in the write group being aborted. | ||
192 | 243 | """ | ||
193 | 244 | |||
194 | 245 | def __init__(self, repository, suppress_errors=False): | ||
195 | 246 | self.repository = repository | ||
196 | 247 | self._suppress_errors = suppress_errors | ||
197 | 248 | |||
198 | 249 | def __enter__(self): | ||
199 | 250 | self.repository.start_write_group() | ||
200 | 251 | return self | ||
201 | 252 | |||
202 | 253 | def __exit__(self, exc_type, exc_val, exc_tb): | ||
203 | 254 | if exc_type: | ||
204 | 255 | self.repository.abort_write_group(self._suppress_errors) | ||
205 | 256 | return False | ||
206 | 257 | else: | ||
207 | 258 | self.repository.commit_write_group() | ||
208 | 259 | |||
209 | 260 | |||
210 | 239 | ###################################################################### | 261 | ###################################################################### |
211 | 240 | # Repositories | 262 | # Repositories |
212 | 241 | 263 | ||
213 | 242 | 264 | ||
214 | === modified file 'breezy/tests/blackbox/test_reconcile.py' | |||
215 | --- breezy/tests/blackbox/test_reconcile.py 2018-11-11 04:08:32 +0000 | |||
216 | +++ breezy/tests/blackbox/test_reconcile.py 2019-05-29 03:45:01 +0000 | |||
217 | @@ -21,6 +21,7 @@ | |||
218 | 21 | controldir, | 21 | controldir, |
219 | 22 | tests, | 22 | tests, |
220 | 23 | ) | 23 | ) |
221 | 24 | from breezy.repository import WriteGroup | ||
222 | 24 | from breezy.bzr import ( | 25 | from breezy.bzr import ( |
223 | 25 | inventory, | 26 | inventory, |
224 | 26 | ) | 27 | ) |
225 | @@ -53,10 +54,8 @@ | |||
226 | 53 | inv = inventory.Inventory(revision_id=b'missing') | 54 | inv = inventory.Inventory(revision_id=b'missing') |
227 | 54 | inv.root.revision = b'missing' | 55 | inv.root.revision = b'missing' |
228 | 55 | repo.lock_write() | 56 | repo.lock_write() |
233 | 56 | repo.start_write_group() | 57 | with repo.lock_write(), WriteGroup(repo): |
234 | 57 | repo.add_inventory(b'missing', inv, []) | 58 | repo.add_inventory(b'missing', inv, []) |
231 | 58 | repo.commit_write_group() | ||
232 | 59 | repo.unlock() | ||
235 | 60 | (out, err) = self.run_bzr('reconcile') | 59 | (out, err) = self.run_bzr('reconcile') |
236 | 61 | if repo._reconcile_backsup_inventory: | 60 | if repo._reconcile_backsup_inventory: |
237 | 62 | does_backup_text = ( | 61 | does_backup_text = ( |
238 | 63 | 62 | ||
239 | === modified file 'breezy/tests/per_controldir/test_controldir.py' | |||
240 | --- breezy/tests/per_controldir/test_controldir.py 2018-11-11 04:08:32 +0000 | |||
241 | +++ breezy/tests/per_controldir/test_controldir.py 2019-05-29 03:45:01 +0000 | |||
242 | @@ -24,6 +24,7 @@ | |||
243 | 24 | errors, | 24 | errors, |
244 | 25 | gpg, | 25 | gpg, |
245 | 26 | osutils, | 26 | osutils, |
246 | 27 | repository as _mod_repository, | ||
247 | 27 | revision as _mod_revision, | 28 | revision as _mod_revision, |
248 | 28 | transport, | 29 | transport, |
249 | 29 | ui, | 30 | ui, |
250 | @@ -319,11 +320,8 @@ | |||
251 | 319 | tree_repo = tree.branch.repository | 320 | tree_repo = tree.branch.repository |
252 | 320 | if not tree_repo._format.supports_revision_signatures: | 321 | if not tree_repo._format.supports_revision_signatures: |
253 | 321 | self.skipTest('repository format does not support signing') | 322 | self.skipTest('repository format does not support signing') |
259 | 322 | tree_repo.lock_write() | 323 | with tree_repo.lock_write(), _mod_repository.WriteGroup(tree_repo): |
260 | 323 | tree_repo.start_write_group() | 324 | tree_repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None)) |
256 | 324 | tree_repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None)) | ||
257 | 325 | tree_repo.commit_write_group() | ||
258 | 326 | tree_repo.unlock() | ||
261 | 327 | target = self.make_branch('target') | 325 | target = self.make_branch('target') |
262 | 328 | tree.branch.repository.copy_content_into(target.repository) | 326 | tree.branch.repository.copy_content_into(target.repository) |
263 | 329 | tree.branch.copy_content_into(target) | 327 | tree.branch.copy_content_into(target) |
264 | 330 | 328 | ||
265 | === modified file 'breezy/tests/per_interrepository/test_fetch.py' | |||
266 | --- breezy/tests/per_interrepository/test_fetch.py 2018-11-11 04:08:32 +0000 | |||
267 | +++ breezy/tests/per_interrepository/test_fetch.py 2019-05-29 03:45:01 +0000 | |||
268 | @@ -32,6 +32,7 @@ | |||
269 | 32 | from breezy.bzr.vf_search import ( | 32 | from breezy.bzr.vf_search import ( |
270 | 33 | SearchResult, | 33 | SearchResult, |
271 | 34 | ) | 34 | ) |
272 | 35 | from breezy.repository import WriteGroup | ||
273 | 35 | from breezy.revision import ( | 36 | from breezy.revision import ( |
274 | 36 | NULL_REVISION, | 37 | NULL_REVISION, |
275 | 37 | Revision, | 38 | Revision, |
276 | @@ -110,8 +111,7 @@ | |||
277 | 110 | source = tree.branch.repository | 111 | source = tree.branch.repository |
278 | 111 | source.lock_write() | 112 | source.lock_write() |
279 | 112 | self.addCleanup(source.unlock) | 113 | self.addCleanup(source.unlock) |
282 | 113 | source.start_write_group() | 114 | with WriteGroup(source): |
281 | 114 | try: | ||
283 | 115 | # We need two revisions: OLD and NEW. NEW will claim to need a file | 115 | # We need two revisions: OLD and NEW. NEW will claim to need a file |
284 | 116 | # 'FOO' changed in 'OLD'. OLD will not have that file at all. | 116 | # 'FOO' changed in 'OLD'. OLD will not have that file at all. |
285 | 117 | source.texts.insert_record_stream([ | 117 | source.texts.insert_record_stream([ |
286 | @@ -133,11 +133,6 @@ | |||
287 | 133 | revision_id=b'new', | 133 | revision_id=b'new', |
288 | 134 | parent_ids=[revid]) | 134 | parent_ids=[revid]) |
289 | 135 | source.add_revision(rev.revision_id, rev) | 135 | source.add_revision(rev.revision_id, rev) |
290 | 136 | except: | ||
291 | 137 | source.abort_write_group() | ||
292 | 138 | raise | ||
293 | 139 | else: | ||
294 | 140 | source.commit_write_group() | ||
295 | 141 | to_repo.fetch(source, b'new') | 136 | to_repo.fetch(source, b'new') |
296 | 142 | to_repo.lock_read() | 137 | to_repo.lock_read() |
297 | 143 | self.addCleanup(to_repo.unlock) | 138 | self.addCleanup(to_repo.unlock) |
298 | @@ -448,17 +443,12 @@ | |||
299 | 448 | # We build a broken revision so that we can test the fetch code dies | 443 | # We build a broken revision so that we can test the fetch code dies |
300 | 449 | # properly. So copy the inventory and revision, but not the text. | 444 | # properly. So copy the inventory and revision, but not the text. |
301 | 450 | with to_repo.lock_write(): | 445 | with to_repo.lock_write(): |
304 | 451 | to_repo.start_write_group() | 446 | with WriteGroup(to_repo, suppress_errors=True): |
303 | 452 | try: | ||
305 | 453 | inv = tree.branch.repository.get_inventory(rev1) | 447 | inv = tree.branch.repository.get_inventory(rev1) |
306 | 454 | to_repo.add_inventory(rev1, inv, []) | 448 | to_repo.add_inventory(rev1, inv, []) |
307 | 455 | rev = tree.branch.repository.get_revision(rev1) | 449 | rev = tree.branch.repository.get_revision(rev1) |
308 | 456 | to_repo.add_revision(rev1, rev, inv=inv) | 450 | to_repo.add_revision(rev1, rev, inv=inv) |
309 | 457 | self.disable_commit_write_group_paranoia(to_repo) | 451 | self.disable_commit_write_group_paranoia(to_repo) |
310 | 458 | to_repo.commit_write_group() | ||
311 | 459 | except: | ||
312 | 460 | to_repo.abort_write_group(suppress_errors=True) | ||
313 | 461 | raise | ||
314 | 462 | 452 | ||
315 | 463 | # Implementations can either ensure that the target of the delta is | 453 | # Implementations can either ensure that the target of the delta is |
316 | 464 | # reconstructable, or raise an exception (which stream based copies | 454 | # reconstructable, or raise an exception (which stream based copies |
317 | 465 | 455 | ||
318 | === modified file 'breezy/tests/per_interrepository/test_interrepository.py' | |||
319 | --- breezy/tests/per_interrepository/test_interrepository.py 2018-11-11 04:08:32 +0000 | |||
320 | +++ breezy/tests/per_interrepository/test_interrepository.py 2019-05-29 03:45:01 +0000 | |||
321 | @@ -22,6 +22,7 @@ | |||
322 | 22 | import breezy.errors as errors | 22 | import breezy.errors as errors |
323 | 23 | import breezy.gpg | 23 | import breezy.gpg |
324 | 24 | from breezy.bzr.inventory import Inventory | 24 | from breezy.bzr.inventory import Inventory |
325 | 25 | from breezy.repository import WriteGroup | ||
326 | 25 | from breezy.revision import NULL_REVISION | 26 | from breezy.revision import NULL_REVISION |
327 | 26 | from breezy.tests import ( | 27 | from breezy.tests import ( |
328 | 27 | TestNotApplicable, | 28 | TestNotApplicable, |
329 | @@ -65,13 +66,10 @@ | |||
330 | 65 | tree_a = self.make_branch_and_tree('a') | 66 | tree_a = self.make_branch_and_tree('a') |
331 | 66 | self.controldir = tree_a.branch.controldir | 67 | self.controldir = tree_a.branch.controldir |
332 | 67 | # add a corrupt inventory 'orphan' | 68 | # add a corrupt inventory 'orphan' |
340 | 68 | tree_a.branch.repository.lock_write() | 69 | with tree_a.branch.repository.lock_write(), WriteGroup(tree_a.branch.repository): |
341 | 69 | tree_a.branch.repository.start_write_group() | 70 | if tree_a.branch.repository._format.supports_ghosts: |
342 | 70 | if tree_a.branch.repository._format.supports_ghosts: | 71 | inv_file = tree_a.branch.repository.inventories |
343 | 71 | inv_file = tree_a.branch.repository.inventories | 72 | inv_file.add_lines((b'orphan',), [], []) |
337 | 72 | inv_file.add_lines((b'orphan',), [], []) | ||
338 | 73 | tree_a.branch.repository.commit_write_group() | ||
339 | 74 | tree_a.branch.repository.unlock() | ||
344 | 75 | # add a real revision 'rev1' | 73 | # add a real revision 'rev1' |
345 | 76 | self.rev1 = tree_a.commit('rev1', allow_pointless=True) | 74 | self.rev1 = tree_a.commit('rev1', allow_pointless=True) |
346 | 77 | # add a real revision 'rev2' based on rev1 | 75 | # add a real revision 'rev2' based on rev1 |
347 | @@ -149,12 +147,10 @@ | |||
348 | 149 | 'to repository does not support signatures') | 147 | 'to repository does not support signatures') |
349 | 150 | # and sign 'rev2' | 148 | # and sign 'rev2' |
350 | 151 | tree_a = WorkingTree.open('a') | 149 | tree_a = WorkingTree.open('a') |
357 | 152 | tree_a.branch.repository.lock_write() | 150 | with tree_a.branch.repository.lock_write(), \ |
358 | 153 | tree_a.branch.repository.start_write_group() | 151 | WriteGroup(tree_a.branch.repository): |
359 | 154 | tree_a.branch.repository.sign_revision(self.rev2, | 152 | tree_a.branch.repository.sign_revision( |
360 | 155 | breezy.gpg.LoopbackGPGStrategy(None)) | 153 | self.rev2, breezy.gpg.LoopbackGPGStrategy(None)) |
355 | 156 | tree_a.branch.repository.commit_write_group() | ||
356 | 157 | tree_a.branch.repository.unlock() | ||
361 | 158 | 154 | ||
362 | 159 | from_repo = self.controldir.open_repository() | 155 | from_repo = self.controldir.open_repository() |
363 | 160 | from_signature = from_repo.get_signature_text(self.rev2) | 156 | from_signature = from_repo.get_signature_text(self.rev2) |
364 | 161 | 157 | ||
365 | === modified file 'breezy/tests/per_pack_repository.py' | |||
366 | --- breezy/tests/per_pack_repository.py 2019-01-09 00:04:02 +0000 | |||
367 | +++ breezy/tests/per_pack_repository.py 2019-05-29 03:45:01 +0000 | |||
368 | @@ -473,26 +473,15 @@ | |||
369 | 473 | r1 = repository.Repository.open('.') | 473 | r1 = repository.Repository.open('.') |
370 | 474 | r2 = repository.Repository.open('.') | 474 | r2 = repository.Repository.open('.') |
371 | 475 | # add a pack to drop | 475 | # add a pack to drop |
376 | 476 | r1.lock_write() | 476 | with r1.lock_write(): |
377 | 477 | try: | 477 | with repository.WriteGroup(r1): |
374 | 478 | r1.start_write_group() | ||
375 | 479 | try: | ||
378 | 480 | self._add_text(r1, b'fileidr1') | 478 | self._add_text(r1, b'fileidr1') |
379 | 481 | except: | ||
380 | 482 | r1.abort_write_group() | ||
381 | 483 | raise | ||
382 | 484 | else: | ||
383 | 485 | r1.commit_write_group() | ||
384 | 486 | r1._pack_collection.ensure_loaded() | 479 | r1._pack_collection.ensure_loaded() |
385 | 487 | name_to_drop = r1._pack_collection.all_packs()[0].name | 480 | name_to_drop = r1._pack_collection.all_packs()[0].name |
390 | 488 | finally: | 481 | with r1.lock_write(): |
387 | 489 | r1.unlock() | ||
388 | 490 | r1.lock_write() | ||
389 | 491 | try: | ||
391 | 492 | # access enough data to load the names list | 482 | # access enough data to load the names list |
392 | 493 | list(r1.all_revision_ids()) | 483 | list(r1.all_revision_ids()) |
395 | 494 | r2.lock_write() | 484 | with r2.lock_write(): |
394 | 495 | try: | ||
396 | 496 | # access enough data to load the names list | 485 | # access enough data to load the names list |
397 | 497 | list(r2.all_revision_ids()) | 486 | list(r2.all_revision_ids()) |
398 | 498 | r1._pack_collection.ensure_loaded() | 487 | r1._pack_collection.ensure_loaded() |
399 | @@ -533,10 +522,6 @@ | |||
400 | 533 | r2._pack_collection.names()) | 522 | r2._pack_collection.names()) |
401 | 534 | self.assertEqual(1, len(r1._pack_collection.names())) | 523 | self.assertEqual(1, len(r1._pack_collection.names())) |
402 | 535 | self.assertFalse(name_to_drop in r1._pack_collection.names()) | 524 | self.assertFalse(name_to_drop in r1._pack_collection.names()) |
403 | 536 | finally: | ||
404 | 537 | r2.unlock() | ||
405 | 538 | finally: | ||
406 | 539 | r1.unlock() | ||
407 | 540 | 525 | ||
408 | 541 | def test_concurrent_pack_triggers_reload(self): | 526 | def test_concurrent_pack_triggers_reload(self): |
409 | 542 | # create 2 packs, which we will then collapse | 527 | # create 2 packs, which we will then collapse |
410 | 543 | 528 | ||
411 | === modified file 'breezy/tests/per_repository/test_signatures.py' | |||
412 | --- breezy/tests/per_repository/test_signatures.py 2018-11-29 23:42:41 +0000 | |||
413 | +++ breezy/tests/per_repository/test_signatures.py 2019-05-29 03:45:01 +0000 | |||
414 | @@ -22,7 +22,7 @@ | |||
415 | 22 | tests, | 22 | tests, |
416 | 23 | urlutils, | 23 | urlutils, |
417 | 24 | ) | 24 | ) |
419 | 25 | 25 | from breezy.repository import WriteGroup | |
420 | 26 | from breezy.bzr.testament import Testament | 26 | from breezy.bzr.testament import Testament |
421 | 27 | from breezy.tests import per_repository | 27 | from breezy.tests import per_repository |
422 | 28 | 28 | ||
423 | @@ -58,24 +58,14 @@ | |||
424 | 58 | def test_store_signature(self): | 58 | def test_store_signature(self): |
425 | 59 | wt = self.make_branch_and_tree('.') | 59 | wt = self.make_branch_and_tree('.') |
426 | 60 | branch = wt.branch | 60 | branch = wt.branch |
430 | 61 | branch.lock_write() | 61 | with branch.lock_write(), WriteGroup(branch.repository): |
428 | 62 | try: | ||
429 | 63 | branch.repository.start_write_group() | ||
431 | 64 | try: | 62 | try: |
432 | 65 | branch.repository.store_revision_signature( | 63 | branch.repository.store_revision_signature( |
433 | 66 | gpg.LoopbackGPGStrategy(None), b'FOO', b'A') | 64 | gpg.LoopbackGPGStrategy(None), b'FOO', b'A') |
434 | 67 | except errors.NoSuchRevision: | 65 | except errors.NoSuchRevision: |
435 | 68 | branch.repository.abort_write_group() | ||
436 | 69 | raise tests.TestNotApplicable( | 66 | raise tests.TestNotApplicable( |
437 | 70 | "repository does not support signing non-present" | 67 | "repository does not support signing non-present" |
438 | 71 | "revisions") | 68 | "revisions") |
439 | 72 | except: | ||
440 | 73 | branch.repository.abort_write_group() | ||
441 | 74 | raise | ||
442 | 75 | else: | ||
443 | 76 | branch.repository.commit_write_group() | ||
444 | 77 | finally: | ||
445 | 78 | branch.unlock() | ||
446 | 79 | # A signature without a revision should not be accessible. | 69 | # A signature without a revision should not be accessible. |
447 | 80 | self.assertRaises(errors.NoSuchRevision, | 70 | self.assertRaises(errors.NoSuchRevision, |
448 | 81 | branch.repository.has_signature_for_revision_id, | 71 | branch.repository.has_signature_for_revision_id, |
449 | 82 | 72 | ||
450 | === modified file 'breezy/tests/per_repository_chk/test_supported.py' | |||
451 | --- breezy/tests/per_repository_chk/test_supported.py 2018-11-16 11:37:47 +0000 | |||
452 | +++ breezy/tests/per_repository_chk/test_supported.py 2019-05-29 03:45:01 +0000 | |||
453 | @@ -38,24 +38,14 @@ | |||
454 | 38 | 38 | ||
455 | 39 | def test_add_bytes_to_chk_bytes_store(self): | 39 | def test_add_bytes_to_chk_bytes_store(self): |
456 | 40 | repo = self.make_repository('.') | 40 | repo = self.make_repository('.') |
475 | 41 | repo.lock_write() | 41 | with repo.lock_write(), repository.WriteGroup(repo): |
476 | 42 | try: | 42 | sha1, len, _ = repo.chk_bytes.add_lines( |
477 | 43 | repo.start_write_group() | 43 | (None,), None, [b"foo\n", b"bar\n"], random_id=True) |
478 | 44 | try: | 44 | self.assertEqual( |
479 | 45 | sha1, len, _ = repo.chk_bytes.add_lines((None,), | 45 | b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', sha1) |
480 | 46 | None, [b"foo\n", b"bar\n"], random_id=True) | 46 | self.assertEqual( |
481 | 47 | self.assertEqual(b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', | 47 | {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)}, |
482 | 48 | sha1) | 48 | repo.chk_bytes.keys()) |
465 | 49 | self.assertEqual( | ||
466 | 50 | {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)}, | ||
467 | 51 | repo.chk_bytes.keys()) | ||
468 | 52 | except: | ||
469 | 53 | repo.abort_write_group() | ||
470 | 54 | raise | ||
471 | 55 | else: | ||
472 | 56 | repo.commit_write_group() | ||
473 | 57 | finally: | ||
474 | 58 | repo.unlock() | ||
483 | 59 | # And after an unlock/lock pair | 49 | # And after an unlock/lock pair |
484 | 60 | with repo.lock_read(): | 50 | with repo.lock_read(): |
485 | 61 | self.assertEqual( | 51 | self.assertEqual( |
486 | @@ -76,46 +66,25 @@ | |||
487 | 76 | node_sha1 = osutils.sha_strings(node_lines) | 66 | node_sha1 = osutils.sha_strings(node_lines) |
488 | 77 | expected_set = {(b'sha1:' + leaf_sha1,), (b'sha1:' + node_sha1,)} | 67 | expected_set = {(b'sha1:' + leaf_sha1,), (b'sha1:' + node_sha1,)} |
489 | 78 | repo = self.make_repository('.') | 68 | repo = self.make_repository('.') |
494 | 79 | repo.lock_write() | 69 | with repo.lock_write(): |
495 | 80 | try: | 70 | with repository.WriteGroup(repo): |
492 | 81 | repo.start_write_group() | ||
493 | 82 | try: | ||
496 | 83 | # Internal node pointing at a leaf. | 71 | # Internal node pointing at a leaf. |
506 | 84 | repo.chk_bytes.add_lines( | 72 | repo.chk_bytes.add_lines((None,), None, node_lines, random_id=True) |
507 | 85 | (None,), None, node_lines, random_id=True) | 73 | with repository.WriteGroup(repo): |
499 | 86 | except: | ||
500 | 87 | repo.abort_write_group() | ||
501 | 88 | raise | ||
502 | 89 | else: | ||
503 | 90 | repo.commit_write_group() | ||
504 | 91 | repo.start_write_group() | ||
505 | 92 | try: | ||
508 | 93 | # Leaf in a separate pack. | 74 | # Leaf in a separate pack. |
516 | 94 | repo.chk_bytes.add_lines( | 75 | repo.chk_bytes.add_lines((None,), None, leaf_lines, random_id=True) |
510 | 95 | (None,), None, leaf_lines, random_id=True) | ||
511 | 96 | except: | ||
512 | 97 | repo.abort_write_group() | ||
513 | 98 | raise | ||
514 | 99 | else: | ||
515 | 100 | repo.commit_write_group() | ||
517 | 101 | repo.pack() | 76 | repo.pack() |
518 | 102 | self.assertEqual(expected_set, repo.chk_bytes.keys()) | 77 | self.assertEqual(expected_set, repo.chk_bytes.keys()) |
519 | 103 | finally: | ||
520 | 104 | repo.unlock() | ||
521 | 105 | # and reopening | 78 | # and reopening |
522 | 106 | repo = repo.controldir.open_repository() | 79 | repo = repo.controldir.open_repository() |
525 | 107 | repo.lock_read() | 80 | with repo.lock_read(): |
524 | 108 | try: | ||
526 | 109 | self.assertEqual(expected_set, repo.chk_bytes.keys()) | 81 | self.assertEqual(expected_set, repo.chk_bytes.keys()) |
527 | 110 | finally: | ||
528 | 111 | repo.unlock() | ||
529 | 112 | 82 | ||
530 | 113 | def test_chk_bytes_are_fully_buffered(self): | 83 | def test_chk_bytes_are_fully_buffered(self): |
531 | 114 | repo = self.make_repository('.') | 84 | repo = self.make_repository('.') |
532 | 115 | repo.lock_write() | 85 | repo.lock_write() |
533 | 116 | self.addCleanup(repo.unlock) | 86 | self.addCleanup(repo.unlock) |
536 | 117 | repo.start_write_group() | 87 | with repository.WriteGroup(repo): |
535 | 118 | try: | ||
537 | 119 | sha1, len, _ = repo.chk_bytes.add_lines((None,), | 88 | sha1, len, _ = repo.chk_bytes.add_lines((None,), |
538 | 120 | None, [b"foo\n", b"bar\n"], random_id=True) | 89 | None, [b"foo\n", b"bar\n"], random_id=True) |
539 | 121 | self.assertEqual(b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', | 90 | self.assertEqual(b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', |
540 | @@ -123,11 +92,6 @@ | |||
541 | 123 | self.assertEqual( | 92 | self.assertEqual( |
542 | 124 | {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)}, | 93 | {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)}, |
543 | 125 | repo.chk_bytes.keys()) | 94 | repo.chk_bytes.keys()) |
544 | 126 | except: | ||
545 | 127 | repo.abort_write_group() | ||
546 | 128 | raise | ||
547 | 129 | else: | ||
548 | 130 | repo.commit_write_group() | ||
549 | 131 | # This may not always be correct if we change away from BTreeGraphIndex | 95 | # This may not always be correct if we change away from BTreeGraphIndex |
550 | 132 | # in the future. But for now, lets check that chk_bytes are fully | 96 | # in the future. But for now, lets check that chk_bytes are fully |
551 | 133 | # buffered | 97 | # buffered |
552 | 134 | 98 | ||
553 | === modified file 'breezy/tests/per_repository_reference/test_add_inventory.py' | |||
554 | --- breezy/tests/per_repository_reference/test_add_inventory.py 2018-11-11 04:08:32 +0000 | |||
555 | +++ breezy/tests/per_repository_reference/test_add_inventory.py 2019-05-29 03:45:01 +0000 | |||
556 | @@ -17,6 +17,7 @@ | |||
557 | 17 | """Tests for add_inventory on a repository with external references.""" | 17 | """Tests for add_inventory on a repository with external references.""" |
558 | 18 | 18 | ||
559 | 19 | from breezy import errors | 19 | from breezy import errors |
560 | 20 | from breezy.repository import WriteGroup | ||
561 | 20 | from breezy.tests.per_repository_reference import ( | 21 | from breezy.tests.per_repository_reference import ( |
562 | 21 | TestCaseWithExternalReferenceRepository, | 22 | TestCaseWithExternalReferenceRepository, |
563 | 22 | ) | 23 | ) |
564 | @@ -34,18 +35,8 @@ | |||
565 | 34 | self.addCleanup(tree.unlock) | 35 | self.addCleanup(tree.unlock) |
566 | 35 | base = self.make_repository('base') | 36 | base = self.make_repository('base') |
567 | 36 | repo = self.make_referring('referring', base) | 37 | repo = self.make_referring('referring', base) |
580 | 37 | repo.lock_write() | 38 | with repo.lock_write(), WriteGroup(repo): |
581 | 38 | try: | 39 | repo.add_inventory(revid, inv, []) |
570 | 39 | repo.start_write_group() | ||
571 | 40 | try: | ||
572 | 41 | repo.add_inventory(revid, inv, []) | ||
573 | 42 | except: | ||
574 | 43 | repo.abort_write_group() | ||
575 | 44 | raise | ||
576 | 45 | else: | ||
577 | 46 | repo.commit_write_group() | ||
578 | 47 | finally: | ||
579 | 48 | repo.unlock() | ||
582 | 49 | repo.lock_read() | 40 | repo.lock_read() |
583 | 50 | self.addCleanup(repo.unlock) | 41 | self.addCleanup(repo.unlock) |
584 | 51 | inv2 = repo.get_inventory(revid) | 42 | inv2 = repo.get_inventory(revid) |
585 | 52 | 43 | ||
586 | === modified file 'breezy/tests/per_repository_reference/test_add_revision.py' | |||
587 | --- breezy/tests/per_repository_reference/test_add_revision.py 2017-05-21 18:10:28 +0000 | |||
588 | +++ breezy/tests/per_repository_reference/test_add_revision.py 2019-05-29 03:45:01 +0000 | |||
589 | @@ -17,6 +17,7 @@ | |||
590 | 17 | """Tests for add_revision on a repository with external references.""" | 17 | """Tests for add_revision on a repository with external references.""" |
591 | 18 | 18 | ||
592 | 19 | from breezy import errors | 19 | from breezy import errors |
593 | 20 | from breezy.repository import WriteGroup | ||
594 | 20 | from breezy.tests.per_repository_reference import ( | 21 | from breezy.tests.per_repository_reference import ( |
595 | 21 | TestCaseWithExternalReferenceRepository, | 22 | TestCaseWithExternalReferenceRepository, |
596 | 22 | ) | 23 | ) |
597 | @@ -35,20 +36,10 @@ | |||
598 | 35 | rev = tree.branch.repository.get_revision(revid) | 36 | rev = tree.branch.repository.get_revision(revid) |
599 | 36 | base = self.make_repository('base') | 37 | base = self.make_repository('base') |
600 | 37 | repo = self.make_referring('referring', base) | 38 | repo = self.make_referring('referring', base) |
615 | 38 | repo.lock_write() | 39 | with repo.lock_write(), WriteGroup(repo): |
616 | 39 | try: | 40 | rev = tree.branch.repository.get_revision(revid) |
617 | 40 | repo.start_write_group() | 41 | repo.texts.add_lines((inv.root.file_id, revid), [], []) |
618 | 41 | try: | 42 | repo.add_revision(revid, rev, inv=inv) |
605 | 42 | rev = tree.branch.repository.get_revision(revid) | ||
606 | 43 | repo.texts.add_lines((inv.root.file_id, revid), [], []) | ||
607 | 44 | repo.add_revision(revid, rev, inv=inv) | ||
608 | 45 | except: | ||
609 | 46 | repo.abort_write_group() | ||
610 | 47 | raise | ||
611 | 48 | else: | ||
612 | 49 | repo.commit_write_group() | ||
613 | 50 | finally: | ||
614 | 51 | repo.unlock() | ||
619 | 52 | rev2 = repo.get_revision(revid) | 43 | rev2 = repo.get_revision(revid) |
620 | 53 | self.assertEqual(rev, rev2) | 44 | self.assertEqual(rev, rev2) |
621 | 54 | self.assertRaises(errors.NoSuchRevision, base.get_revision, revid) | 45 | self.assertRaises(errors.NoSuchRevision, base.get_revision, revid) |
622 | 55 | 46 | ||
623 | === modified file 'breezy/tests/per_repository_reference/test_add_signature_text.py' | |||
624 | --- breezy/tests/per_repository_reference/test_add_signature_text.py 2018-11-11 04:08:32 +0000 | |||
625 | +++ breezy/tests/per_repository_reference/test_add_signature_text.py 2019-05-29 03:45:01 +0000 | |||
626 | @@ -17,6 +17,7 @@ | |||
627 | 17 | """Tests for add_signature_text on a repository with external references.""" | 17 | """Tests for add_signature_text on a repository with external references.""" |
628 | 18 | 18 | ||
629 | 19 | from breezy import errors | 19 | from breezy import errors |
630 | 20 | from breezy.repository import WriteGroup | ||
631 | 20 | from breezy.tests.per_repository_reference import ( | 21 | from breezy.tests.per_repository_reference import ( |
632 | 21 | TestCaseWithExternalReferenceRepository, | 22 | TestCaseWithExternalReferenceRepository, |
633 | 22 | ) | 23 | ) |
634 | @@ -34,20 +35,11 @@ | |||
635 | 34 | self.addCleanup(tree.unlock) | 35 | self.addCleanup(tree.unlock) |
636 | 35 | base = self.make_repository('base') | 36 | base = self.make_repository('base') |
637 | 36 | repo = self.make_referring('referring', base) | 37 | repo = self.make_referring('referring', base) |
652 | 37 | repo.lock_write() | 38 | with repo.lock_write(), WriteGroup(repo): |
653 | 38 | try: | 39 | rev = tree.branch.repository.get_revision(revid) |
654 | 39 | repo.start_write_group() | 40 | repo.texts.add_lines((inv.root.file_id, revid), [], []) |
655 | 40 | try: | 41 | repo.add_revision(revid, rev, inv=inv) |
656 | 41 | rev = tree.branch.repository.get_revision(revid) | 42 | repo.add_signature_text(revid, b"text") |
643 | 42 | repo.texts.add_lines((inv.root.file_id, revid), [], []) | ||
644 | 43 | repo.add_revision(revid, rev, inv=inv) | ||
645 | 44 | repo.add_signature_text(revid, b"text") | ||
646 | 45 | repo.commit_write_group() | ||
647 | 46 | except: | ||
648 | 47 | repo.abort_write_group() | ||
649 | 48 | raise | ||
650 | 49 | finally: | ||
651 | 50 | repo.unlock() | ||
657 | 51 | repo.get_signature_text(revid) | 43 | repo.get_signature_text(revid) |
658 | 52 | self.assertRaises(errors.NoSuchRevision, base.get_signature_text, | 44 | self.assertRaises(errors.NoSuchRevision, base.get_signature_text, |
659 | 53 | revid) | 45 | revid) |
660 | 54 | 46 | ||
661 | === modified file 'breezy/tests/per_repository_vf/helpers.py' | |||
662 | --- breezy/tests/per_repository_vf/helpers.py 2018-11-11 04:08:32 +0000 | |||
663 | +++ breezy/tests/per_repository_vf/helpers.py 2019-05-29 03:45:01 +0000 | |||
664 | @@ -20,6 +20,7 @@ | |||
665 | 20 | osutils, | 20 | osutils, |
666 | 21 | revision as _mod_revision, | 21 | revision as _mod_revision, |
667 | 22 | ) | 22 | ) |
668 | 23 | from ...repository import WriteGroup | ||
669 | 23 | from ...bzr import ( | 24 | from ...bzr import ( |
670 | 24 | inventory, | 25 | inventory, |
671 | 25 | ) | 26 | ) |
672 | @@ -50,9 +51,7 @@ | |||
673 | 50 | "%s isn't a knit format" % self.repository_format) | 51 | "%s isn't a knit format" % self.repository_format) |
674 | 51 | 52 | ||
675 | 52 | repo = self.make_repository('broken') | 53 | repo = self.make_repository('broken') |
679 | 53 | repo.lock_write() | 54 | with repo.lock_write(), WriteGroup(repo): |
677 | 54 | repo.start_write_group() | ||
678 | 55 | try: | ||
680 | 56 | inv = inventory.Inventory(revision_id=b'revision-id') | 55 | inv = inventory.Inventory(revision_id=b'revision-id') |
681 | 57 | inv.root.revision = b'revision-id' | 56 | inv.root.revision = b'revision-id' |
682 | 58 | inv_sha1 = repo.add_inventory(b'revision-id', inv, []) | 57 | inv_sha1 = repo.add_inventory(b'revision-id', inv, []) |
683 | @@ -66,16 +65,9 @@ | |||
684 | 66 | # Manually add the revision text using the RevisionStore API, with | 65 | # Manually add the revision text using the RevisionStore API, with |
685 | 67 | # bad parents. | 66 | # bad parents. |
686 | 68 | rev_text = repo._serializer.write_revision_to_string(revision) | 67 | rev_text = repo._serializer.write_revision_to_string(revision) |
697 | 69 | repo.revisions.add_lines((revision.revision_id,), | 68 | repo.revisions.add_lines( |
698 | 70 | [(b'incorrect-parent',)], | 69 | (revision.revision_id,), [(b'incorrect-parent',)], |
699 | 71 | osutils.split_lines(rev_text)) | 70 | osutils.split_lines(rev_text)) |
690 | 72 | except: | ||
691 | 73 | repo.abort_write_group() | ||
692 | 74 | repo.unlock() | ||
693 | 75 | raise | ||
694 | 76 | else: | ||
695 | 77 | repo.commit_write_group() | ||
696 | 78 | repo.unlock() | ||
700 | 79 | 71 | ||
701 | 80 | repo.lock_write() | 72 | repo.lock_write() |
702 | 81 | self.addCleanup(repo.unlock) | 73 | self.addCleanup(repo.unlock) |
703 | 82 | 74 | ||
704 | === modified file 'breezy/tests/per_repository_vf/test_check_reconcile.py' | |||
705 | --- breezy/tests/per_repository_vf/test_check_reconcile.py 2018-11-11 04:08:32 +0000 | |||
706 | +++ breezy/tests/per_repository_vf/test_check_reconcile.py 2019-05-29 03:45:01 +0000 | |||
707 | @@ -25,6 +25,7 @@ | |||
708 | 25 | Inventory, | 25 | Inventory, |
709 | 26 | InventoryFile, | 26 | InventoryFile, |
710 | 27 | ) | 27 | ) |
711 | 28 | from breezy.repository import WriteGroup | ||
712 | 28 | from breezy.revision import ( | 29 | from breezy.revision import ( |
713 | 29 | NULL_REVISION, | 30 | NULL_REVISION, |
714 | 30 | Revision, | 31 | Revision, |
715 | @@ -793,15 +794,9 @@ | |||
716 | 793 | def make_populated_repository(self, factory): | 794 | def make_populated_repository(self, factory): |
717 | 794 | """Create a new repository populated by the given factory.""" | 795 | """Create a new repository populated by the given factory.""" |
718 | 795 | repo = self.make_repository('broken-repo') | 796 | repo = self.make_repository('broken-repo') |
728 | 796 | with repo.lock_write(): | 797 | with repo.lock_write(), WriteGroup(repo): |
729 | 797 | repo.start_write_group() | 798 | factory(repo) |
730 | 798 | try: | 799 | return repo |
722 | 799 | factory(repo) | ||
723 | 800 | repo.commit_write_group() | ||
724 | 801 | return repo | ||
725 | 802 | except: | ||
726 | 803 | repo.abort_write_group() | ||
727 | 804 | raise | ||
731 | 805 | 800 | ||
732 | 806 | def add_revision(self, repo, revision_id, inv, parent_ids): | 801 | def add_revision(self, repo, revision_id, inv, parent_ids): |
733 | 807 | """Add a revision with a given inventory and parents to a repository. | 802 | """Add a revision with a given inventory and parents to a repository. |
734 | 808 | 803 | ||
735 | === modified file 'breezy/tests/per_repository_vf/test_repository.py' | |||
736 | --- breezy/tests/per_repository_vf/test_repository.py 2019-01-01 21:08:01 +0000 | |||
737 | +++ breezy/tests/per_repository_vf/test_repository.py 2019-05-29 03:45:01 +0000 | |||
738 | @@ -327,19 +327,9 @@ | |||
739 | 327 | self.controldir = tree_a.branch.controldir | 327 | self.controldir = tree_a.branch.controldir |
740 | 328 | # add a corrupt inventory 'orphan' | 328 | # add a corrupt inventory 'orphan' |
741 | 329 | # this may need some generalising for knits. | 329 | # this may need some generalising for knits. |
755 | 330 | tree_a.lock_write() | 330 | with tree_a.lock_write(), _mod_repository.WriteGroup(tree_a.branch.repository): |
756 | 331 | try: | 331 | inv_file = tree_a.branch.repository.inventories |
757 | 332 | tree_a.branch.repository.start_write_group() | 332 | inv_file.add_lines((b'orphan',), [], []) |
745 | 333 | try: | ||
746 | 334 | inv_file = tree_a.branch.repository.inventories | ||
747 | 335 | inv_file.add_lines((b'orphan',), [], []) | ||
748 | 336 | except: | ||
749 | 337 | tree_a.branch.repository.commit_write_group() | ||
750 | 338 | raise | ||
751 | 339 | else: | ||
752 | 340 | tree_a.branch.repository.abort_write_group() | ||
753 | 341 | finally: | ||
754 | 342 | tree_a.unlock() | ||
758 | 343 | # add a real revision 'rev1' | 333 | # add a real revision 'rev1' |
759 | 344 | tree_a.commit('rev1', rev_id=b'rev1', allow_pointless=True) | 334 | tree_a.commit('rev1', rev_id=b'rev1', allow_pointless=True) |
760 | 345 | # add a real revision 'rev2' based on rev1 | 335 | # add a real revision 'rev2' based on rev1 |
761 | @@ -385,18 +375,13 @@ | |||
762 | 385 | 375 | ||
763 | 386 | def test_reserved_id(self): | 376 | def test_reserved_id(self): |
764 | 387 | repo = self.make_repository('repository') | 377 | repo = self.make_repository('repository') |
768 | 388 | repo.lock_write() | 378 | with repo.lock_write(), _mod_repository.WriteGroup(repo): |
766 | 389 | repo.start_write_group() | ||
767 | 390 | try: | ||
769 | 391 | self.assertRaises(errors.ReservedId, repo.add_inventory, | 379 | self.assertRaises(errors.ReservedId, repo.add_inventory, |
770 | 392 | b'reserved:', None, None) | 380 | b'reserved:', None, None) |
771 | 393 | self.assertRaises(errors.ReservedId, repo.add_inventory_by_delta, | 381 | self.assertRaises(errors.ReservedId, repo.add_inventory_by_delta, |
772 | 394 | "foo", [], b'reserved:', None) | 382 | "foo", [], b'reserved:', None) |
778 | 395 | self.assertRaises(errors.ReservedId, repo.add_revision, | 383 | self.assertRaises( |
779 | 396 | b'reserved:', None) | 384 | errors.ReservedId, repo.add_revision, b'reserved:', None) |
775 | 397 | finally: | ||
776 | 398 | repo.abort_write_group() | ||
777 | 399 | repo.unlock() | ||
780 | 400 | 385 | ||
781 | 401 | 386 | ||
782 | 402 | class TestCaseWithCorruptRepository(TestCaseWithRepository): | 387 | class TestCaseWithCorruptRepository(TestCaseWithRepository): |
783 | 403 | 388 | ||
784 | === modified file 'breezy/tests/test_inv.py' | |||
785 | --- breezy/tests/test_inv.py 2018-11-16 11:37:47 +0000 | |||
786 | +++ breezy/tests/test_inv.py 2019-05-29 03:45:01 +0000 | |||
787 | @@ -141,8 +141,7 @@ | |||
788 | 141 | 141 | ||
789 | 142 | 142 | ||
790 | 143 | def _create_repo_revisions(repo, basis, delta, invalid_delta): | 143 | def _create_repo_revisions(repo, basis, delta, invalid_delta): |
793 | 144 | repo.start_write_group() | 144 | with repository.WriteGroup(repo): |
792 | 145 | try: | ||
794 | 146 | rev = revision.Revision(b'basis', timestamp=0, timezone=None, | 145 | rev = revision.Revision(b'basis', timestamp=0, timezone=None, |
795 | 147 | message="", committer="foo@example.com") | 146 | message="", committer="foo@example.com") |
796 | 148 | basis.revision_id = b'basis' | 147 | basis.revision_id = b'basis' |
797 | @@ -161,19 +160,13 @@ | |||
798 | 161 | rev = revision.Revision(b'result', timestamp=0, timezone=None, | 160 | rev = revision.Revision(b'result', timestamp=0, timezone=None, |
799 | 162 | message="", committer="foo@example.com") | 161 | message="", committer="foo@example.com") |
800 | 163 | repo.add_revision(b'result', rev, result_inv) | 162 | repo.add_revision(b'result', rev, result_inv) |
801 | 164 | repo.commit_write_group() | ||
802 | 165 | except: | ||
803 | 166 | repo.abort_write_group() | ||
804 | 167 | raise | ||
805 | 168 | return target_entries | 163 | return target_entries |
806 | 169 | 164 | ||
807 | 170 | 165 | ||
808 | 171 | def _get_basis_entries(tree): | 166 | def _get_basis_entries(tree): |
809 | 172 | basis_tree = tree.basis_tree() | 167 | basis_tree = tree.basis_tree() |
814 | 173 | basis_tree.lock_read() | 168 | with basis_tree.lock_read(): |
815 | 174 | basis_tree_entries = list(basis_tree.inventory.iter_entries_by_dir()) | 169 | return list(basis_tree.inventory.iter_entries_by_dir()) |
812 | 175 | basis_tree.unlock() | ||
813 | 176 | return basis_tree_entries | ||
816 | 177 | 170 | ||
817 | 178 | 171 | ||
818 | 179 | def _populate_different_tree(tree, basis, delta): | 172 | def _populate_different_tree(tree, basis, delta): |
819 | @@ -253,28 +246,16 @@ | |||
820 | 253 | format = self.format() | 246 | format = self.format() |
821 | 254 | control = self.make_controldir('tree', format=format._matchingcontroldir) | 247 | control = self.make_controldir('tree', format=format._matchingcontroldir) |
822 | 255 | repo = format.initialize(control) | 248 | repo = format.initialize(control) |
845 | 256 | with repo.lock_write(): | 249 | with repo.lock_write(), repository.WriteGroup(repo): |
846 | 257 | repo.start_write_group() | 250 | rev = revision.Revision( |
847 | 258 | try: | 251 | b'basis', timestamp=0, timezone=None, message="", |
848 | 259 | rev = revision.Revision(b'basis', timestamp=0, timezone=None, | 252 | committer="foo@example.com") |
849 | 260 | message="", committer="foo@example.com") | 253 | basis.revision_id = b'basis' |
850 | 261 | basis.revision_id = b'basis' | 254 | create_texts_for_inv(repo, basis) |
851 | 262 | create_texts_for_inv(repo, basis) | 255 | repo.add_revision(b'basis', rev, basis) |
852 | 263 | repo.add_revision(b'basis', rev, basis) | 256 | with repo.lock_write(), repository.WriteGroup(repo): |
853 | 264 | repo.commit_write_group() | 257 | inv_sha1 = repo.add_inventory_by_delta( |
854 | 265 | except: | 258 | b'basis', delta, b'result', [b'basis']) |
833 | 266 | repo.abort_write_group() | ||
834 | 267 | raise | ||
835 | 268 | with repo.lock_write(): | ||
836 | 269 | repo.start_write_group() | ||
837 | 270 | try: | ||
838 | 271 | inv_sha1 = repo.add_inventory_by_delta(b'basis', delta, | ||
839 | 272 | b'result', [b'basis']) | ||
840 | 273 | except: | ||
841 | 274 | repo.abort_write_group() | ||
842 | 275 | raise | ||
843 | 276 | else: | ||
844 | 277 | repo.commit_write_group() | ||
855 | 278 | # Fresh lock, reads disk again. | 259 | # Fresh lock, reads disk again. |
856 | 279 | repo = repo.controldir.open_repository() | 260 | repo = repo.controldir.open_repository() |
857 | 280 | repo.lock_read() | 261 | repo.lock_read() |
Looks reasonable, thanks!