Commit c4b7cb8c authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

transactions and locks: use `with` rather than `try`/`finally`

parent 2610cc1bfdf3
Pipeline #15795 passed with stages
in 7 minutes and 55 seconds
......@@ -287,7 +287,6 @@
gitsha, hgsha = line.strip().split(b' ', 1)
if hgsha in repo:
new_map.append(b'%s %s\n' % (gitsha, hgsha))
wlock = repo.wlock()
try:
with repo.wlock():
f = gh.vfs(gh.map_file, b'wb')
f.writelines(new_map)
......@@ -292,7 +291,5 @@
f = gh.vfs(gh.map_file, b'wb')
f.writelines(new_map)
finally:
wlock.release()
ui.status(_(b'git commit map cleaned\n'))
......@@ -478,7 +475,5 @@
pullop.trmanager = exchange.transactionmanager(repo, b'pull',
remote.url())
wlock = repo.wlock()
lock = repo.lock()
try:
with repo.wlock(), repo.lock(), pullop.trmanager:
pullop.cgresult = repo.githandler.fetch(remote.path, heads)
......@@ -484,3 +479,2 @@
pullop.cgresult = repo.githandler.fetch(remote.path, heads)
pullop.trmanager.close()
return pullop
......@@ -486,8 +480,4 @@
return pullop
finally:
pullop.trmanager.release()
lock.release()
wlock.release()
else:
return orig(repo, remote, heads, force, bookmarks=bookmarks, **kwargs)
......
......@@ -215,10 +215,9 @@
self._map_hg_real = map_hg_real
def save_map(self, map_file):
wlock = self.repo.wlock()
try:
with self.repo.wlock():
map_hg = self._map_hg
with self.vfs(map_file, b'wb+', atomictemp=True) as buf:
bwrite = buf.write
for hgsha, gitsha in compat.iteritems(map_hg):
bwrite(b"%s %s\n" % (gitsha, hgsha))
......@@ -220,10 +219,8 @@
map_hg = self._map_hg
with self.vfs(map_file, b'wb+', atomictemp=True) as buf:
bwrite = buf.write
for hgsha, gitsha in compat.iteritems(map_hg):
bwrite(b"%s %s\n" % (gitsha, hgsha))
finally:
wlock.release()
def load_tags(self):
self.tags = {}
......@@ -333,8 +330,6 @@
blist.append(rnode)
if blist:
lock = self.repo.lock()
try:
tr = self.repo.transaction(b"phase")
with self.repo.lock(), self.repo.transaction(b"phase") as tr:
phases.advanceboundary(self.repo, tr, phases.public,
blist)
......@@ -339,10 +334,5 @@
phases.advanceboundary(self.repo, tr, phases.public,
blist)
tr.close()
finally:
if tr is not None:
tr.release()
lock.release()
if imported == 0:
return 0
......
......@@ -12,10 +12,7 @@
from dulwich import errors
from mercurial.i18n import _
from mercurial import (
error,
lock as lockmod,
)
from mercurial import error
from . import compat
......@@ -109,16 +106,8 @@
def updatebookmarks(repo, changes, name=b'git_handler'):
"""abstract writing bookmarks for backwards compatibility"""
bms = repo._bookmarks
tr = lock = wlock = None
try:
wlock = repo.wlock()
lock = repo.lock()
tr = repo.transaction(name)
bms.applychanges(repo, tr, changes)
tr.close()
finally:
lockmod.release(tr, lock, wlock)
with repo.wlock(), repo.lock(), repo.transaction(name) as tr:
repo._bookmarks.applychanges(repo, tr, changes)
def checksafessh(host):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment