changeset 2647:b9cfb8bd0965

topic-change: cleanup the locking and transaction mechanism The previous code did not garanted we would release all lock (and was a bit more complicated than needed.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 21 Jun 2017 13:21:08 +0200
parents b5723184fc62
children d8b47d961c77
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 4 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Wed Jun 21 07:21:50 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Wed Jun 21 13:21:08 2017 +0200
@@ -306,9 +306,10 @@
 def _changetopics(ui, repo, revset, newtopic):
     rewrote = 0
     needevolve = False
-    l = repo.lock()
-    txn = repo.transaction('rewrite-topics')
+    l = txn = None
     try:
+        l = repo.lock()
+        txn = repo.transaction('rewrite-topics')
         p1 = None
         p2 = None
         successors = {}
@@ -358,14 +359,9 @@
             obsolete.createmarkers(repo, [(c, (repo[newnode],))])
             rewrote += 1
         txn.close()
-    except:
-        try:
-            txn.abort()
-        finally:
-            repo.invalidate()
-        raise
     finally:
         lock.release(txn, l)
+        repo.invalidate()
     ui.status('changed topic on %d changes\n' % rewrote)
     if needevolve:
         evolvetarget = 'topic(%s)' % newtopic if newtopic else 'not topic()'