changeset 1856:7d7f5f9e2f8c

rewrite: use a lock and transaction as spotted by devel warnings
author Augie Fackler <augie@google.com>
date Thu, 18 Jun 2015 15:46:26 -0400
parents f241a00e93a7
children a506ed8ab8da
files src/topic/__init__.py
diffstat 1 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/topic/__init__.py	Fri Jun 12 16:49:46 2015 -0500
+++ b/src/topic/__init__.py	Thu Jun 18 15:46:26 2015 -0400
@@ -17,11 +17,12 @@
 from mercurial import commands
 from mercurial import context
 from mercurial import extensions
+from mercurial import lock
+from mercurial import merge
 from mercurial import namespaces
 from mercurial import obsolete
 from mercurial import phases
 from mercurial import util
-from mercurial import merge
 
 from . import constants
 from . import revset as topicrevset
@@ -82,29 +83,41 @@
             raise util.Abort("can't change topic of a public change")
         rewrote = 0
         needevolve = False
-        for c in repo.set('%r', change):
-            def filectxfn(repo, ctx, path):
-                try:
-                    return c[path]
-                except error.ManifestLookupError:
-                    return None
-            fixedextra = dict(c.extra())
-            newtopic = None if clear else topic
-            if fixedextra.get(constants.extrakey, None) == topic:
-                continue
-            if clear and constants.extrakey in fixedextra:
-                del fixedextra[constants.extrakey]
-            else:
-                fixedextra[constants.extrakey] = topic
-            c.parents()
-            mc = context.memctx(
-                repo, (c.p1().node(), c.p2().node()), c.description(),
-                c.files(), filectxfn,
-                user=c.user(), date=c.date(), extra=fixedextra)
-            newnode = repo.commitctx(mc)
-            needevolve = needevolve or (len(c.children()) > 0)
-            obsolete.createmarkers(repo, [(c, (repo[newnode],))])
-            rewrote += 1
+        l = repo.lock()
+        txn = repo.transaction('rewrite-topics')
+        try:
+           for c in repo.set('%r', change):
+               def filectxfn(repo, ctx, path):
+                   try:
+                       return c[path]
+                   except error.ManifestLookupError:
+                       return None
+               fixedextra = dict(c.extra())
+               newtopic = None if clear else topic
+               if fixedextra.get(constants.extrakey, None) == topic:
+                   continue
+               if clear and constants.extrakey in fixedextra:
+                   del fixedextra[constants.extrakey]
+               else:
+                   fixedextra[constants.extrakey] = topic
+               c.parents()
+               mc = context.memctx(
+                   repo, (c.p1().node(), c.p2().node()), c.description(),
+                   c.files(), filectxfn,
+                   user=c.user(), date=c.date(), extra=fixedextra)
+               newnode = repo.commitctx(mc)
+               needevolve = needevolve or (len(c.children()) > 0)
+               obsolete.createmarkers(repo, [(c, (repo[newnode],))])
+               rewrote += 1
+           txn.close()
+        except:
+            try:
+                txn.abort()
+            finally:
+                repo.invalidate()
+            raise
+        finally:
+            lock.release(txn, l)
         ui.status('changed topic on %d changes\n' % rewrote)
         if needevolve:
             evolvetarget = 'topic(%s)' % topic if topic else 'not topic()'