39 except OSError as ex: |
39 except OSError as ex: |
40 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): |
40 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): |
41 raise |
41 raise |
42 return result |
42 return result |
43 |
43 |
44 def trylock(ui, vfs, lockname, timeout, *args, **kwargs): |
44 def trylock(ui, vfs, lockname, timeout, warntimeout, *args, **kwargs): |
45 """return an acquired lock or raise an a LockHeld exception |
45 """return an acquired lock or raise an a LockHeld exception |
46 |
46 |
47 This function is responsible to issue warnings about the held lock while |
47 This function is responsible to issue warnings and or debug messages about |
48 trying to acquires it.""" |
48 the held lock while trying to acquires it.""" |
49 |
49 |
50 def printwarning(printer, locker): |
50 def printwarning(printer, locker): |
51 """issue the usual "waiting on lock" message through any channel""" |
51 """issue the usual "waiting on lock" message through any channel""" |
52 # show more details for new-style locks |
52 # show more details for new-style locks |
53 if ':' in locker: |
53 if ':' in locker: |
58 msg = _("waiting for lock on %s held by %r\n") % (l.desc, locker) |
58 msg = _("waiting for lock on %s held by %r\n") % (l.desc, locker) |
59 printer(msg) |
59 printer(msg) |
60 |
60 |
61 l = lock(vfs, lockname, 0, *args, dolock=False, **kwargs) |
61 l = lock(vfs, lockname, 0, *args, dolock=False, **kwargs) |
62 |
62 |
|
63 debugidx = 0 if (warntimeout and timeout) else -1 |
63 warningidx = 0 |
64 warningidx = 0 |
64 if not timeout: |
65 if not timeout: |
65 warningidx = -1 |
66 warningidx = -1 |
|
67 elif warntimeout: |
|
68 warningidx = warntimeout |
66 |
69 |
67 delay = 0 |
70 delay = 0 |
68 while True: |
71 while True: |
69 try: |
72 try: |
70 l._trylock() |
73 l._trylock() |
71 break |
74 break |
72 except error.LockHeld as inst: |
75 except error.LockHeld as inst: |
|
76 if delay == debugidx: |
|
77 printwarning(ui.debug, inst.locker) |
73 if delay == warningidx: |
78 if delay == warningidx: |
74 printwarning(ui.warn, inst.locker) |
79 printwarning(ui.warn, inst.locker) |
75 if timeout <= delay: |
80 if timeout <= delay: |
76 raise error.LockHeld(errno.ETIMEDOUT, inst.filename, |
81 raise error.LockHeld(errno.ETIMEDOUT, inst.filename, |
77 l.desc, inst.locker) |
82 l.desc, inst.locker) |
78 time.sleep(1) |
83 time.sleep(1) |
79 delay += 1 |
84 delay += 1 |
80 |
85 |
81 l.delay = delay |
86 l.delay = delay |
82 if l.delay: |
87 if l.delay: |
83 ui.warn(_("got lock after %s seconds\n") % l.delay) |
88 if 0 <= warningidx <= l.delay: |
|
89 ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
90 else: |
|
91 ui.debug("got lock after %s seconds\n" % l.delay) |
84 if l.acquirefn: |
92 if l.acquirefn: |
85 l.acquirefn() |
93 l.acquirefn() |
86 return l |
94 return l |
87 |
95 |
88 class lock(object): |
96 class lock(object): |