##// END OF EJS Templates
Some cleanups in commands.annotate()....
Some cleanups in commands.annotate(). -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Some cleanups in commands.annotate(). manifest hash: 9581ad3bb9ebc418e4772158c505e34b92496e92 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFC2K+nW7P1GVgWeRoRAr3VAKCGvKbhmG4yweZTgmxIgaZlmz16HQCdFupq BKcWfEn17Y1l6IDbGS0rDyI= =/fR/ -----END PGP SIGNATURE-----

File last commit:

r705:57486910 merge default
r714:29fcd195 default
Show More
lock.py
49 lines | 1.1 KiB | text/x-python | PythonLexer
# lock.py - simple locking scheme for mercurial
#
# Copyright 2005 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
import os, time
import util
class LockHeld(Exception):
pass
class lock:
def __init__(self, file, wait = 1):
self.f = file
self.held = 0
self.wait = wait
self.lock()
def __del__(self):
self.release()
def lock(self):
while 1:
try:
self.trylock()
return 1
except LockHeld, inst:
if self.wait:
time.sleep(1)
continue
raise inst
def trylock(self):
pid = os.getpid()
try:
util.makelock(str(pid), self.f)
self.held = 1
except (OSError, IOError):
raise LockHeld(util.readlock(self.f))
def release(self):
if self.held:
self.held = 0
try:
os.unlink(self.f)
except: pass