[PATCH 4 of 7 bm-refactor V3] commands: replace locking code with a context manager

Sean Farley sean at farley.io
Fri Jun 23 15:04:48 EDT 2017


Martin von Zweigbergk <martinvonz at google.com> writes:

> On Fri, Jun 23, 2017 at 11:33 AM, Sean Farley <sean at farley.io> wrote:
>> # HG changeset patch
>> # User Sean Farley <sean at farley.io>
>> # Date 1497998203 25200
>> #      Tue Jun 20 15:36:43 2017 -0700
>> # Branch bm-refactor
>> # Node ID 5431515879d0efdf36825c094d66b9345f635e95
>> # Parent  cf4fcf960a580afc9650ae73b5ab4d2c10e8a594
>> commands: replace locking code with a context manager
>>
>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> index 86f811e..085dcfb 100644
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -965,40 +965,28 @@ def bookmark(ui, repo, *names, **opts):
>>          raise error.Abort(_("--rev is incompatible with --rename"))
>>      if not names and (delete or rev):
>>          raise error.Abort(_("bookmark name required"))
>>
>>      if delete or rename or names or inactive:
>> -        wlock = lock = tr = None
>> -        try:
>> -            wlock = repo.wlock()
>> -            lock = repo.lock()
>> -            marks = repo._bookmarks
>> +        with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
>>              if delete:
>> -                tr = repo.transaction('bookmark')
>>                  bookmarks.delete(repo, tr, names)
>>              elif rename:
>> -                tr = repo.transaction('bookmark')
>>                  if not names:
>>                      raise error.Abort(_("new bookmark name required"))
>>                  elif len(names) > 1:
>>                      raise error.Abort(_("only one new bookmark name allowed"))
>>                  bookmarks.rename(repo, tr, rename, names[0], force, inactive)
>>              elif names:
>> -                tr = repo.transaction('bookmark')
>>                  bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
>>              elif inactive:
>
> We now create a transaction in this case too, which we didn't before.
> I can't see any harm in that, though. I still wanted to mention it
> since maybe that's the reason the transaction was not created earlier
> before.

That's a good spot. Maybe I / you could add it to the commit message?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170623/01dbf18e/attachment.sig>


More information about the Mercurial-devel mailing list