Mercurial > public > mercurial-scm > hg-stable
diff mercurial/interfaces/repository.py @ 52739:0f2268783c11
clone: explicitly steal lock instead of assigning previous lock
The issue with reusing the lock from another repository is that various internal
state are no longer correct, the main example of that is the dirstate, captured
in the wlock to make sure it is written (when needed) on lock release. So
instead, we create a proper lock from the repository, but "stealing" the on-disk
lock from the previous object.
This is a bit weird, but less than the previous situation.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 30 Jan 2025 09:23:16 +0100 |
parents | f19a3f1437f3 |
children | 5c48fd4c0e68 |
line wrap: on
line diff
--- a/mercurial/interfaces/repository.py Fri Dec 20 16:11:19 2024 +0100 +++ b/mercurial/interfaces/repository.py Thu Jan 30 09:23:16 2025 +0100 @@ -2118,16 +2118,36 @@ pass @abc.abstractmethod - def lock(self, wait=True): - """Lock the repository store and return a lock instance.""" + def lock(self, wait=True, steal_from=None): + """Lock the repository store and return a lock instance. + + If another lock object is specified through the "steal_from" argument, + the new lock will reuse the on-disk lock of that "stolen" lock instead + of creating its own. The "stolen" lock is no longer usable for any + purpose and won't execute its release callback. + + That steal_from argument is used during local clone when reloading a + repository. If we could remove the need for this during copy clone, we + could remove this function. + """ @abc.abstractmethod def currentlock(self): """Return the lock if it's held or None.""" @abc.abstractmethod - def wlock(self, wait=True): - """Lock the non-store parts of the repository.""" + def wlock(self, wait=True, steal_from=None): + """Lock the non-store parts of the repository. + + If another lock object is specified through the "steal_from" argument, + the new lock will reuse the on-disk lock of that "stolen" lock instead + of creating its own. The "stolen" lock is no longer usable for any + purpose and won't execute its release callback. + + That steal_from argument is used during local clone when reloading a + repository. If we could remove the need for this during copy clone, we + could remove this function. + """ @abc.abstractmethod def currentwlock(self):