Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mercurial
hg-git
Commits
c4b7cb8ce3af
Commit
c4b7cb8c
authored
Oct 26, 2020
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
hggit/__init__.py
View file @
c4b7cb8c
...
...
@@ -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
)
...
...
hggit/git_handler.py
View file @
c4b7cb8c
...
...
@@ -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
...
...
hggit/util.py
View file @
c4b7cb8c
...
...
@@ -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
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment