##// END OF EJS Templates
commands: add debuglocks to report/clear lock state
Matt Mackall -
r22559:4e0b696a default
parent child Browse files
Show More
@@ -9,7 +9,7 b' from node import hex, bin, nullid, nullr'
9 from lock import release
9 from lock import release
10 from i18n import _
10 from i18n import _
11 import os, re, difflib, time, tempfile, errno, shlex
11 import os, re, difflib, time, tempfile, errno, shlex
12 import sys
12 import sys, socket
13 import hg, scmutil, util, revlog, copies, error, bookmarks
13 import hg, scmutil, util, revlog, copies, error, bookmarks
14 import patch, help, encoding, templatekw, discovery
14 import patch, help, encoding, templatekw, discovery
15 import archival, changegroup, cmdutil, hbisect
15 import archival, changegroup, cmdutil, hbisect
@@ -2338,6 +2338,78 b' def debuglabelcomplete(ui, repo, *args):'
2338 ui.write('\n'.join(sorted(completions)))
2338 ui.write('\n'.join(sorted(completions)))
2339 ui.write('\n')
2339 ui.write('\n')
2340
2340
2341 @command('debuglocks',
2342 [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')),
2343 ('W', 'force-wlock', None,
2344 _('free the working state lock (DANGEROUS)'))],
2345 _(''))
2346 def debuglocks(ui, repo, **opts):
2347 """show or modify state of locks
2348
2349 By default, this command will show which locks are held. This
2350 includes the user and process holding the lock, the amount of time
2351 the lock has been held, and the machine name where the process is
2352 running if it's not local.
2353
2354 Locks protect the integrity of Mercurial's data, so should be
2355 treated with care. System crashes or other interruptions may cause
2356 locks to not be properly released, though Mercurial will usually
2357 detect and remove such stale locks automatically.
2358
2359 However, detecting stale locks may not always be possible (for
2360 instance, on a shared filesystem). Removing locks may also be
2361 blocked by filesystem permissions.
2362
2363 Returns 0 if no locks are held.
2364
2365 """
2366
2367 if opts.get('force_lock'):
2368 repo.svfs.unlink('lock')
2369 if opts.get('force_wlock'):
2370 repo.vfs.unlink('wlock')
2371 if opts.get('force_lock') or opts.get('force_lock'):
2372 return 0
2373
2374 now = time.time()
2375 held = 0
2376
2377 def report(vfs, name, method):
2378 # this causes stale locks to get reaped for more accurate reporting
2379 try:
2380 l = method(False)
2381 except error.LockHeld:
2382 l = None
2383
2384 if l:
2385 l.release()
2386 else:
2387 try:
2388 stat = repo.svfs.lstat(name)
2389 age = now - stat.st_mtime
2390 user = util.username(stat.st_uid)
2391 locker = vfs.readlock(name)
2392 if ":" in locker:
2393 host, pid = locker.split(':')
2394 if host == socket.gethostname():
2395 locker = 'user %s, process %s' % (user, pid)
2396 else:
2397 locker = 'user %s, process %s, host %s' \
2398 % (user, pid, host)
2399 ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age))
2400 return 1
2401 except OSError, e:
2402 if e.errno != errno.ENOENT:
2403 raise
2404
2405 ui.write("%-6s free\n" % (name + ":"))
2406 return 0
2407
2408 held += report(repo.svfs, "lock", repo.lock)
2409 held += report(repo.vfs, "wlock", repo.wlock)
2410
2411 return held
2412
2341 @command('debugobsolete',
2413 @command('debugobsolete',
2342 [('', 'flags', 0, _('markers flag')),
2414 [('', 'flags', 0, _('markers flag')),
2343 ('', 'record-parents', False,
2415 ('', 'record-parents', False,
@@ -89,6 +89,7 b' Show debug commands if there are no othe'
89 debuginstall
89 debuginstall
90 debugknown
90 debugknown
91 debuglabelcomplete
91 debuglabelcomplete
92 debuglocks
92 debugobsolete
93 debugobsolete
93 debugpathcomplete
94 debugpathcomplete
94 debugpushkey
95 debugpushkey
@@ -245,6 +246,7 b' Show all commands + options'
245 debuginstall:
246 debuginstall:
246 debugknown:
247 debugknown:
247 debuglabelcomplete:
248 debuglabelcomplete:
249 debuglocks: force-lock, force-wlock
248 debugobsolete: flags, record-parents, rev, date, user
250 debugobsolete: flags, record-parents, rev, date, user
249 debugpathcomplete: full, normal, added, removed
251 debugpathcomplete: full, normal, added, removed
250 debugpushkey:
252 debugpushkey:
@@ -781,6 +781,7 b' Test list of internal help commands'
781 debugknown test whether node ids are known to a repo
781 debugknown test whether node ids are known to a repo
782 debuglabelcomplete
782 debuglabelcomplete
783 complete "labels" - tags, open branch names, bookmark names
783 complete "labels" - tags, open branch names, bookmark names
784 debuglocks show or modify state of locks
784 debugobsolete
785 debugobsolete
785 create arbitrary obsolete marker
786 create arbitrary obsolete marker
786 debugoptDEP (no help text available)
787 debugoptDEP (no help text available)
@@ -16,6 +16,7 b''
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
17
17
18 $ echo '[hooks]' >> 2/.hg/hgrc
18 $ echo '[hooks]' >> 2/.hg/hgrc
19 $ echo 'pretxnchangegroup.a = hg debuglocks; true' >> 2/.hg/hgrc
19 $ echo 'changegroup.push = hg push -qf ../1' >> 2/.hg/hgrc
20 $ echo 'changegroup.push = hg push -qf ../1' >> 2/.hg/hgrc
20
21
21 $ echo bar >> 3/foo
22 $ echo bar >> 3/foo
@@ -28,4 +29,6 b''
28 adding manifests
29 adding manifests
29 adding file changes
30 adding file changes
30 added 1 changesets with 1 changes to 1 files
31 added 1 changesets with 1 changes to 1 files
32 lock: user *, process * (*s) (glob)
33 wlock: free
31
34
General Comments 0
You need to be logged in to leave comments. Login now