Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 35402:12055fb3ba30
debuglocks: allow setting a lock
author | Paul Morelle <paul.morelle@octobus.net> |
---|---|
date | Sun, 12 Nov 2017 15:34:46 +0100 |
parents | a43b2dd95e4f |
children | dffc35a5be9f |
comparison
equal
deleted
inserted
replaced
35401:a43b2dd95e4f | 35402:12055fb3ba30 |
---|---|
1273 debugnamecomplete(ui, repo, *args) | 1273 debugnamecomplete(ui, repo, *args) |
1274 | 1274 |
1275 @command('debuglocks', | 1275 @command('debuglocks', |
1276 [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), | 1276 [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), |
1277 ('W', 'force-wlock', None, | 1277 ('W', 'force-wlock', None, |
1278 _('free the working state lock (DANGEROUS)'))], | 1278 _('free the working state lock (DANGEROUS)')), |
1279 ('s', 'set-lock', None, _('set the store lock until stopped')), | |
1280 ('S', 'set-wlock', None, | |
1281 _('set the working state lock until stopped'))], | |
1279 _('[OPTION]...')) | 1282 _('[OPTION]...')) |
1280 def debuglocks(ui, repo, **opts): | 1283 def debuglocks(ui, repo, **opts): |
1281 """show or modify state of locks | 1284 """show or modify state of locks |
1282 | 1285 |
1283 By default, this command will show which locks are held. This | 1286 By default, this command will show which locks are held. This |
1291 detect and remove such stale locks automatically. | 1294 detect and remove such stale locks automatically. |
1292 | 1295 |
1293 However, detecting stale locks may not always be possible (for | 1296 However, detecting stale locks may not always be possible (for |
1294 instance, on a shared filesystem). Removing locks may also be | 1297 instance, on a shared filesystem). Removing locks may also be |
1295 blocked by filesystem permissions. | 1298 blocked by filesystem permissions. |
1299 | |
1300 Setting a lock will prevent other commands from changing the data. | |
1301 The command will wait until an interruption (SIGINT, SIGTERM, ...) occurs. | |
1302 The set locks are removed when the command exits. | |
1296 | 1303 |
1297 Returns 0 if no locks are held. | 1304 Returns 0 if no locks are held. |
1298 | 1305 |
1299 """ | 1306 """ |
1300 | 1307 |
1302 repo.svfs.unlink('lock') | 1309 repo.svfs.unlink('lock') |
1303 if opts.get(r'force_wlock'): | 1310 if opts.get(r'force_wlock'): |
1304 repo.vfs.unlink('wlock') | 1311 repo.vfs.unlink('wlock') |
1305 if opts.get(r'force_lock') or opts.get(r'force_wlock'): | 1312 if opts.get(r'force_lock') or opts.get(r'force_wlock'): |
1306 return 0 | 1313 return 0 |
1314 | |
1315 locks = [] | |
1316 try: | |
1317 if opts.get(r'set_wlock'): | |
1318 try: | |
1319 locks.append(repo.wlock(False)) | |
1320 except error.LockHeld: | |
1321 raise error.Abort(_('wlock is already held')) | |
1322 if opts.get(r'set_lock'): | |
1323 try: | |
1324 locks.append(repo.lock(False)) | |
1325 except error.LockHeld: | |
1326 raise error.Abort(_('lock is already held')) | |
1327 if len(locks): | |
1328 ui.promptchoice(_("ready to release the lock (y)? $$ &Yes")) | |
1329 return 0 | |
1330 finally: | |
1331 release(*locks) | |
1307 | 1332 |
1308 now = time.time() | 1333 now = time.time() |
1309 held = 0 | 1334 held = 0 |
1310 | 1335 |
1311 def report(vfs, name, method): | 1336 def report(vfs, name, method): |