7 |
7 |
8 from node import hex, bin, nullid, nullrev, short |
8 from node import hex, bin, nullid, nullrev, short |
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 |
16 import sshserver, hgweb, commandserver |
16 import sshserver, hgweb, commandserver |
17 import extensions |
17 import extensions |
2336 for a in args: |
2336 for a in args: |
2337 completions.update(l for l in labels if l.startswith(a)) |
2337 completions.update(l for l in labels if l.startswith(a)) |
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, |
2344 _('record parent information for the precursor')), |
2416 _('record parent information for the precursor')), |
2345 ('r', 'rev', [], _('display markers relevant to REV')), |
2417 ('r', 'rev', [], _('display markers relevant to REV')), |