Show More
@@ -204,6 +204,7 b' class dirstate:' | |||||
204 | msg = "entering a changing context, but dirstate is already dirty" |
|
204 | msg = "entering a changing context, but dirstate is already dirty" | |
205 | raise error.ProgrammingError(msg) |
|
205 | raise error.ProgrammingError(msg) | |
206 |
|
206 | |||
|
207 | assert self._changing_level >= 0 | |||
207 | # different type of change are mutually exclusive |
|
208 | # different type of change are mutually exclusive | |
208 | if self._change_type is None: |
|
209 | if self._change_type is None: | |
209 | assert self._changing_level == 0 |
|
210 | assert self._changing_level == 0 | |
@@ -215,43 +216,37 b' class dirstate:' | |||||
215 | ) |
|
216 | ) | |
216 | msg %= (change_type, self._change_type) |
|
217 | msg %= (change_type, self._change_type) | |
217 | raise error.ProgrammingError(msg) |
|
218 | raise error.ProgrammingError(msg) | |
|
219 | should_write = False | |||
218 | self._changing_level += 1 |
|
220 | self._changing_level += 1 | |
219 | try: |
|
221 | try: | |
220 | yield |
|
222 | yield | |
221 | except: # re-raises |
|
223 | except: # re-raises | |
222 | self.invalidate() |
|
224 | self.invalidate() # this will set `_invalidated_context` | |
223 | raise |
|
225 | raise | |
224 | finally: |
|
226 | finally: | |
225 | tr = repo.currenttransaction() |
|
227 | assert self._changing_level > 0 | |
226 |
|
|
228 | self._changing_level -= 1 | |
|
229 | # If the dirstate is being invalidated, call invalidate again. | |||
|
230 | # This will throw away anything added by a upper context and | |||
|
231 | # reset the `_invalidated_context` flag when relevant | |||
|
232 | if self._changing_level <= 0: | |||
|
233 | self._change_type = None | |||
|
234 | assert self._changing_level == 0 | |||
227 |
|
|
235 | if self._invalidated_context: | |
228 |
|
|
236 | # make sure we invalidate anything an upper context might | |
229 |
|
|
237 | # have changed. | |
230 |
|
|
238 | self.invalidate() | |
231 | self._changing_level -= 1 |
|
|||
232 | # The invalidation is complete once we exit the final context |
|
|||
233 | # manager |
|
|||
234 | if self._changing_level <= 0: |
|
|||
235 | self._change_type = None |
|
|||
236 | assert self._changing_level == 0 |
|
|||
237 | if self._invalidated_context: |
|
|||
238 | self._invalidated_context = False |
|
|||
239 |
|
|
239 | else: | |
240 | # When an exception occured, `_invalidated_context` |
|
240 | should_write = self._changing_level <= 0 | |
241 | # would have been set to True by the `invalidate` |
|
241 | tr = repo.currenttransaction() | |
242 | # call earlier. |
|
|||
243 | # |
|
|||
244 | # We don't have more straightforward code, because the |
|
|||
245 | # Exception catching (and the associated `invalidate` |
|
|||
246 | # calling) might have been called by a nested context |
|
|||
247 | # instead of the top level one. |
|
|||
248 | self.write(tr) |
|
|||
249 |
|
|
242 | if has_tr != (tr is not None): | |
250 |
|
|
243 | if has_tr: | |
251 |
|
|
244 | m = "transaction vanished while changing dirstate" | |
252 |
|
|
245 | else: | |
253 |
|
|
246 | m = "transaction appeared while changing dirstate" | |
254 |
|
|
247 | raise error.ProgrammingError(m) | |
|
248 | if should_write: | |||
|
249 | self.write(tr) | |||
255 |
|
250 | |||
256 | @contextlib.contextmanager |
|
251 | @contextlib.contextmanager | |
257 | def changing_parents(self, repo): |
|
252 | def changing_parents(self, repo): |
General Comments 0
You need to be logged in to leave comments.
Login now