[PATCH] debuglocks: allow setting a lock

Yuya Nishihara yuya at tcha.org
Thu Nov 9 07:54:53 EST 2017


On Wed, 08 Nov 2017 21:16:55 +0100, Paul Morelle wrote:
> # HG changeset patch
> # User Paul Morelle <paul.morelle at octobus.net>
> # Date 1510071568 -3600
> #      Tue Nov 07 17:19:28 2017 +0100
> # Node ID 5300b33397d0651eb2457502204969585d492cc5
> # Parent  602c168c0207c443ac61f7a7c727b31cfb0b86ad
> # EXP-Topic debugsetlocks
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5300b33397d0
> debuglocks: allow setting a lock

>  def debuglocks(ui, repo, **opts):
>      """show or modify state of locks
> @@ -1192,6 +1195,10 @@
>      instance, on a shared filesystem). Removing locks may also be
>      blocked by filesystem permissions.
>  
> +    Setting a lock will prevent other commands from changing the data.
> +    The command will wait until an interruption (SIGINT, SIGTERM, ...) occurs.
> +    The set lock(s) is (are) removed when the command exits.

Nit: I think we generally use plural form instead of singular/plural pairs.

> +    locks = []
> +    if opts.get(r'set_wlock'):
> +        try:
> +            locks.append(repo.wlock(False))
> +        except error.LockHeld:
> +            raise error.Abort(_('wlock is already held'))
> +    if opts.get(r'set_lock'):
> +        try:
> +            locks.append(repo.lock(False))
> +        except error.LockHeld:
> +            raise error.Abort(_('lock is already held'))

This should be wrapped by try-finally. Otherwise locks wouldn't be released
depending on when Ctrl-C is triggered.

> +    if len(locks):
> +        try:
> +            while True:
> +                time.sleep(60)
> +        except:

Naked except: block is discouraged.

> +            for lock in locks:
> +                lock.release()
> +            raise

Perhaps this should be moved to finally block. And you can use
lockmod.release() helper.


More information about the Mercurial-devel mailing list