Mercurial > hg
changeset 26290:9664d32bd6cb
lock: factor code to read lock into a separate function
This is going to be needed for upcoming work with lock inheritance.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 16 Sep 2015 19:26:59 -0700 |
parents | c4b667a7a51d |
children | 1d33842c5b3e |
files | mercurial/lock.py |
diffstat | 1 files changed, 16 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/lock.py Thu Sep 17 15:38:00 2015 -0700 +++ b/mercurial/lock.py Wed Sep 16 19:26:59 2015 -0700 @@ -100,6 +100,19 @@ raise error.LockUnavailable(why.errno, why.strerror, why.filename, self.desc) + def _readlock(self): + """read lock and return its value + + Returns None if no lock exists, pid for old-style locks, and host:pid + for new-style locks. + """ + try: + return self.vfs.readlock(self.f) + except (OSError, IOError) as why: + if why.errno == errno.ENOENT: + return None + raise + def testlock(self): """return id of locker if lock is valid, else None. @@ -111,12 +124,9 @@ The lock file is only deleted when None is returned. """ - try: - locker = self.vfs.readlock(self.f) - except (OSError, IOError) as why: - if why.errno == errno.ENOENT: - return None - raise + locker = self._readlock() + if locker is None: + return None try: host, pid = locker.split(":", 1) except ValueError: