repair: use context manager for lock management
If repo.lock() raised inside of the try block, 'tr' would have been None in the
finally block where it tries to release(). Modernize the syntax instead of just
winching the lock out of the try block.
I found several other instances of acquiring the lock inside of the 'try', but
those finally blocks handle None references. I also started switching some
trivial try/finally blocks to context managers, but didn't get them all because
indenting over 3x for lock, wlock and transaction would have spilled over 80
characters. That got me wondering if there should be a repo.rwlock(), to handle
locking and unlocking in the proper order.
It also looks like py27 supports supports multiple context managers for a single
'with' statement. Should I hold off on the rest until py26 is dropped?
#!/usr/bin/env python
#
# An example hgweb CGI script, edit as necessary
# See also https://mercurial-scm.org/wiki/PublishingRepositories
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/path/to/repo/or/config"
# Uncomment and adjust if Mercurial is not installed system-wide
# (consult "installed modules" path from 'hg debuginstall'):
#import sys; sys.path.insert(0, "/path/to/python/lib")
# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb; cgitb.enable()
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb(config)
wsgicgi.launch(application)