comparison mercurial/dirstate.py @ 51069:a63e1f7987a7

dirstate: document the `changing_*` context manager The methods that requires them have documentation, but the context themselves had none. This is now fixed.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 12 Oct 2023 09:04:12 +0200
parents 18c8c18993f0
children 88ef80210d67
comparison
equal deleted inserted replaced
51068:41c73325af52 51069:a63e1f7987a7
341 if should_write: 341 if should_write:
342 self.write(tr) 342 self.write(tr)
343 343
344 @contextlib.contextmanager 344 @contextlib.contextmanager
345 def changing_parents(self, repo): 345 def changing_parents(self, repo):
346 """Wrap a dirstate change related to a change of working copy parents
347
348 This context scopes a series of dirstate modifications that match an
349 update of the working copy parents (typically `hg update`, `hg merge`
350 etc).
351
352 The dirstate's methods that perform this kind of modifications require
353 this context to be present before being called.
354 Such methods are decorated with `@requires_changing_parents`.
355
356 The new dirstate contents will be written to disk when the top-most
357 `changing_parents` context exits successfully. If an exception is
358 raised during a `changing_parents` context of any level, all changes
359 are invalidated. If this context is open within an open transaction,
360 the dirstate writing is delayed until that transaction is successfully
361 committed (and the dirstate is invalidated on transaction abort).
362
363 The `changing_parents` operation is mutually exclusive with the
364 `changing_files` one.
365 """
346 with self._changing(repo, CHANGE_TYPE_PARENTS) as c: 366 with self._changing(repo, CHANGE_TYPE_PARENTS) as c:
347 yield c 367 yield c
348 368
349 @contextlib.contextmanager 369 @contextlib.contextmanager
350 def changing_files(self, repo): 370 def changing_files(self, repo):
371 """Wrap a dirstate change related to the set of tracked files
372
373 This context scopes a series of dirstate modifications that change the
374 set of tracked files. (typically `hg add`, `hg remove` etc) or some
375 dirstate stored information (like `hg rename --after`) but preserve
376 the working copy parents.
377
378 The dirstate's methods that perform this kind of modifications require
379 this context to be present before being called.
380 Such methods are decorated with `@requires_changing_files`.
381
382 The new dirstate contents will be written to disk when the top-most
383 `changing_files` context exits successfully. If an exception is raised
384 during a `changing_files` context of any level, all changes are
385 invalidated. If this context is open within an open transaction, the
386 dirstate writing is delayed until that transaction is successfully
387 committed (and the dirstate is invalidated on transaction abort).
388
389 The `changing_files` operation is mutually exclusive with the
390 `changing_parents` one.
391 """
351 with self._changing(repo, CHANGE_TYPE_FILES) as c: 392 with self._changing(repo, CHANGE_TYPE_FILES) as c:
352 yield c 393 yield c
353 394
354 # here to help migration to the new code 395 # here to help migration to the new code
355 def parentchange(self): 396 def parentchange(self):