[PATCH 1 of 2 evolve-ext] evolve: remove meaningless transaction nesting
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Thu Jan 28 11:42:47 UTC 2016
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1453497481 -32400
# Sat Jan 23 06:18:01 2016 +0900
# Node ID d5ac28ad9f41585be4bc35466910f2733267c332
# Parent 983f2e4dbe5d4d97d6ca82f6679913d75c1f2577
# Available At https://foozy@bitbucket.org/foozy/hgext-evolve
# hg pull https://foozy@bitbucket.org/foozy/hgext-evolve -r d5ac28ad9f41
evolve: remove meaningless transaction nesting
Before this patch, functions below nest transaction scope, even though
they are invoked only inside a transaction scope created at _solveone().
- _solvebumped()
- _solvedivergent()
- relocate() via _solveunstable() or _solvebumped()
Transaction nesting is useful for localizing "success" (e.g. one scope
per commit inside wider scope for multiple committing).
But such nesting is redundant for _solveone(), because there is no
code path, which causes failure after successfully closing inner
transaction(s).
In addition to it, this nesting makes it complicated to close current
transaction successfully with exception raising inside inner scope,
like "hg shelve" at detection of conflicts. "tr.close()" is required
at each outer scopes for such case.
To remove meaningless transaction nesting, this patch replaces
repo.transaction() in functions above by repo.currenttransaction().
This reuses transaction created at _solveone().
This patch also adds 'assert tr' after getting current running
transaction, to avoid invocation of functions above without
transaction.
diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -946,7 +946,8 @@ def relocate(repo, orig, dest, pctx=None
repo.ui.note(_('The stale commit message reference to %s could '
'not be updated\n') % sha1)
- tr = repo.transaction('relocate')
+ tr = repo.currenttransaction()
+ assert tr
try:
try:
if repo['.'].rev() != dest.rev():
@@ -986,9 +987,8 @@ def relocate(repo, orig, dest, pctx=None
raise
oldbookmarks = repo.nodebookmarks(nodesrc)
_finalizerelocate(repo, orig, dest, nodenew, tr)
- tr.close()
finally:
- tr.release()
+ pass # TODO: remove this redundant try/finally block
return nodenew
def _bookmarksupdater(repo, oldid, tr):
@@ -1858,7 +1858,8 @@ def _solvebumped(ui, repo, bumped, dryru
newid = tmpctx = None
tmpctx = bumped
# Basic check for common parent. Far too complicated and fragile
- tr = repo.transaction('bumped-stabilize')
+ tr = repo.currenttransaction()
+ assert tr
bmupdate = _bookmarksupdater(repo, bumped.node(), tr)
try:
if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
@@ -1924,10 +1925,9 @@ def _solvebumped(ui, repo, bumped, dryru
obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))],
flag=obsolete.bumpedfix)
bmupdate(newid)
- tr.close()
repo.ui.status(_('committed as %s\n') % node.short(newid))
finally:
- tr.release()
+ pass # TODO: remove this redundant try/finally block
# reroute the working copy parent to the new changeset
repo.dirstate.beginparentchange()
repo.dirstate.setparents(newid, node.nullid)
@@ -2036,7 +2036,8 @@ def _solvedivergent(ui, repo, divergent,
""")
if progresscb: progresscb()
emtpycommitallowed = repo.ui.backupconfig('ui', 'allowemptycommit')
- tr = repo.transaction('stabilize-divergent')
+ tr = repo.currenttransaction()
+ assert tr
try:
repo.ui.setconfig('ui', 'allowemptycommit', True)
repo.dirstate.beginparentchange()
@@ -2051,10 +2052,8 @@ def _solvedivergent(ui, repo, divergent,
new = repo['.']
obsolete.createmarkers(repo, [(other, (new,))])
phases.retractboundary(repo, tr, other.phase(), [new.node()])
- tr.close()
finally:
repo.ui.restoreconfig(emtpycommitallowed)
- tr.release()
def divergentdata(ctx):
"""return base, other part of a conflict
More information about the Mercurial-devel
mailing list