diff --git a/hgext3rd/fbamend/fold.py b/hgext3rd/fbamend/fold.py --- a/hgext3rd/fbamend/fold.py +++ b/hgext3rd/fbamend/fold.py @@ -15,7 +15,6 @@ commands, error, hg, - lock as lockmod, phases, registrar, scmutil, @@ -108,50 +107,38 @@ ui.write_err(_('single revision specified, nothing to fold\n')) return 1 - wlock = lock = None - try: - wlock = repo.wlock() - lock = repo.lock() - + with repo.wlock(), repo.lock(), repo.transaction('fold') as tr: root, head = _foldcheck(repo, revs) - tr = repo.transaction('fold') - try: - commitopts = opts.copy() - allctx = [repo[r] for r in revs] - targetphase = max(c.phase() for c in allctx) + commitopts = opts.copy() + allctx = [repo[r] for r in revs] + targetphase = max(c.phase() for c in allctx) - if commitopts.get('message') or commitopts.get('logfile'): - commitopts['edit'] = False - else: - msgs = ["HG: This is a fold of %d changesets." % len(allctx)] - msgs += ["HG: Commit message of changeset %s.\n\n%s\n" % - (c.rev(), c.description()) for c in allctx] - commitopts['message'] = "\n".join(msgs) - commitopts['edit'] = True + if commitopts.get('message') or commitopts.get('logfile'): + commitopts['edit'] = False + else: + msgs = ["HG: This is a fold of %d changesets." % len(allctx)] + msgs += ["HG: Commit message of changeset %s.\n\n%s\n" % + (c.rev(), c.description()) for c in allctx] + commitopts['message'] = "\n".join(msgs) + commitopts['edit'] = True - newid, unusedvariable = common.rewrite(repo, root, allctx, head, - [root.p1().node(), - root.p2().node()], - commitopts=commitopts) - phases.retractboundary(repo, tr, targetphase, [newid]) - - replacements = {ctx.node(): (newid,) for ctx in allctx} - scmutil.cleanupnodes(repo, replacements, 'fold') + newid, unusedvariable = common.rewrite(repo, root, allctx, head, + [root.p1().node(), + root.p2().node()], + commitopts=commitopts) + phases.retractboundary(repo, tr, targetphase, [newid]) - ui.status(_('%i changesets folded\n') % len(revs)) - if repo['.'].rev() in revs: - hg.update(repo, newid) + replacements = {ctx.node(): (newid,) for ctx in allctx} + scmutil.cleanupnodes(repo, replacements, 'fold') - if torebase: - folded = repo.revs('allsuccessors(%ld)', revs).last() - common.restackonce(ui, repo, folded) + ui.status(_('%i changesets folded\n') % len(revs)) + if repo['.'].rev() in revs: + hg.update(repo, newid) - tr.close() - finally: - tr.release() - finally: - lockmod.release(lock, wlock) + if torebase: + folded = repo.revs('allsuccessors(%ld)', revs).last() + common.restackonce(ui, repo, folded) def _foldcheck(repo, revs): roots = repo.revs('roots(%ld)', revs)