Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/lock.py @ 1701:4ba8fe499df2
hgmerge: various cleanups
Details:
- put temporary file names into variables
- make all temporary file names end with random part
- cleanup FileMerge handling
- do not use hardlinks in FileMerge change test (breaks on FAT)
- try harder to keep file mtime unchanged in case of failed merge
author | Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl> |
---|---|
date | Mon, 06 Feb 2006 17:32:10 -0600 |
parents | 59b3639df0a9 |
children | e6e70450edb9 |
rev | line source |
---|---|
161 | 1 # lock.py - simple locking scheme for mercurial |
2 # | |
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 # | |
5 # This software may be used and distributed according to the terms | |
6 # of the GNU General Public License, incorporated herein by reference. | |
7 | |
8 import os, time | |
422
10c43444a38e
[PATCH] Enables lock work under the other 'OS'
mpm@selenic.com
parents:
161
diff
changeset
|
9 import util |
161 | 10 |
11 class LockHeld(Exception): | |
12 pass | |
13 | |
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1530
diff
changeset
|
14 class lock(object): |
1530
abfab59fce79
add a releasefn keyword to lock.lock
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1062
diff
changeset
|
15 def __init__(self, file, wait=1, releasefn=None): |
161 | 16 self.f = file |
17 self.held = 0 | |
18 self.wait = wait | |
1530
abfab59fce79
add a releasefn keyword to lock.lock
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1062
diff
changeset
|
19 self.releasefn = releasefn |
161 | 20 self.lock() |
21 | |
22 def __del__(self): | |
23 self.release() | |
24 | |
25 def lock(self): | |
26 while 1: | |
27 try: | |
28 self.trylock() | |
29 return 1 | |
30 except LockHeld, inst: | |
31 if self.wait: | |
32 time.sleep(1) | |
33 continue | |
34 raise inst | |
515 | 35 |
161 | 36 def trylock(self): |
37 pid = os.getpid() | |
38 try: | |
422
10c43444a38e
[PATCH] Enables lock work under the other 'OS'
mpm@selenic.com
parents:
161
diff
changeset
|
39 util.makelock(str(pid), self.f) |
161 | 40 self.held = 1 |
704
5ca319a641e1
Make makelock and readlock work on filesystems without symlink support.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
515
diff
changeset
|
41 except (OSError, IOError): |
422
10c43444a38e
[PATCH] Enables lock work under the other 'OS'
mpm@selenic.com
parents:
161
diff
changeset
|
42 raise LockHeld(util.readlock(self.f)) |
161 | 43 |
44 def release(self): | |
45 if self.held: | |
46 self.held = 0 | |
1530
abfab59fce79
add a releasefn keyword to lock.lock
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1062
diff
changeset
|
47 if self.releasefn: |
abfab59fce79
add a releasefn keyword to lock.lock
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1062
diff
changeset
|
48 self.releasefn() |
503
c6a2e41c8c60
Fix troubles with clone and exception handling
mpm@selenic.com
parents:
429
diff
changeset
|
49 try: |
c6a2e41c8c60
Fix troubles with clone and exception handling
mpm@selenic.com
parents:
429
diff
changeset
|
50 os.unlink(self.f) |
c6a2e41c8c60
Fix troubles with clone and exception handling
mpm@selenic.com
parents:
429
diff
changeset
|
51 except: pass |
161 | 52 |