hgext/evolve.py
branchstable
changeset 410 598ff1df3b92
parent 365 9f6a77ec66cb
child 414 299af91b8b6e
child 419 03672e955bc8
--- a/hgext/evolve.py	Tue Jul 31 15:23:01 2012 +0200
+++ b/hgext/evolve.py	Mon Jul 30 22:45:06 2012 +0200
@@ -413,57 +413,63 @@
     try:
         wlock = repo.wlock()
         try:
-            if old.phase() == phases.public:
-                raise util.Abort(_("can not rewrite immutable changeset %s")
-                                 % old)
-            oldphase = old.phase()
-            # commit current changes as update
-            # code copied from commands.commit to avoid noisy messages
-            ciopts = dict(opts)
-            ciopts.pop('message', None)
-            ciopts.pop('logfile', None)
-            ciopts['message'] = opts.get('note') or ('amends %s' % old.hex())
-            e = cmdutil.commiteditor
-            def commitfunc(ui, repo, message, match, opts):
-                return repo.commit(message, opts.get('user'), opts.get('date'),
-                                   match, editor=e)
-            revcount = len(repo)
-            tempid = cmdutil.commit(ui, repo, commitfunc, pats, ciopts)
-            if len(repo) == revcount:
-                # No revision created
-                tempid = None
+            tr = repo.transaction('amend')
+            try:
+                if old.phase() == phases.public:
+                    raise util.Abort(_("can not rewrite immutable changeset %s")
+                                     % old)
+                oldphase = old.phase()
+                # commit current changes as update
+                # code copied from commands.commit to avoid noisy messages
+                ciopts = dict(opts)
+                ciopts.pop('message', None)
+                ciopts.pop('logfile', None)
+                ciopts['message'] = opts.get('note') or ('amends %s' % old.hex())
+                e = cmdutil.commiteditor
+                def commitfunc(ui, repo, message, match, opts):
+                    return repo.commit(message, opts.get('user'), opts.get('date'),
+                                       match, editor=e)
+                revcount = len(repo)
+                tempid = cmdutil.commit(ui, repo, commitfunc, pats, ciopts)
+                if len(repo) == revcount:
+                    # No revision created
+                    tempid = None
 
-            # find all changesets to be considered updates
-            head = repo['.']
-            updatenodes = set(repo.changelog.nodesbetween(
-                    roots=[old.node()], heads=[head.node()])[0])
-            updatenodes.remove(old.node())
-            okoptions = ['message', 'logfile', 'edit', 'user']
-            if not updatenodes:
-                for o in okoptions:
-                    if opts.get(o):
-                        break
-                else:
-                    raise error.Abort(_('no updates found'))
-            updates = [repo[n] for n in updatenodes]
+                # find all changesets to be considered updates
+                head = repo['.']
+                updatenodes = set(repo.changelog.nodesbetween(
+                        roots=[old.node()], heads=[head.node()])[0])
+                updatenodes.remove(old.node())
+                okoptions = ['message', 'logfile', 'edit', 'user']
+                if not updatenodes:
+                    for o in okoptions:
+                        if opts.get(o):
+                            break
+                    else:
+                        raise error.Abort(_('no updates found'))
+                updates = [repo[n] for n in updatenodes]
 
-            # perform amend
-            if opts.get('edit'):
-                opts['force_editor'] = True
-            newid, created = rewrite(repo, old, updates, head,
-                                     [old.p1().node(), old.p2().node()], opts)
-            if created:
-                # reroute the working copy parent to the new changeset
-                phases.retractboundary(repo, oldphase, [newid])
-                repo.dirstate.setparents(newid, node.nullid)
-            else:
-                # rewrite() recreated an existing revision, discard
-                # the intermediate revision if any. No need to update
-                # phases or parents.
-                if tempid is not None:
-                    repo.addobsolete(node.nullid, tempid)
-                # XXX: need another message in collapse case.
-                raise error.Abort(_('no updates found'))
+                # perform amend
+                if opts.get('edit'):
+                    opts['force_editor'] = True
+                newid, created = rewrite(repo, old, updates, head,
+                                         [old.p1().node(), old.p2().node()], opts)
+                if created:
+                    # reroute the working copy parent to the new changeset
+                    phases.retractboundary(repo, oldphase, [newid])
+                    repo.dirstate.setparents(newid, node.nullid)
+                else:
+                    # rewrite() recreated an existing revision, discard
+                    # the intermediate revision if any. No need to update
+                    # phases or parents.
+                    if tempid is not None:
+                        repo.addobsolete(node.nullid, tempid)
+                    # XXX: need another message in collapse case.
+                    tr.close()
+                    raise error.Abort(_('no updates found'))
+                tr.close()
+            finally:
+                tr.release()
         finally:
             wlock.release()
     finally: