topic: make sure we have the 'wlock' when setting topic
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 11 Aug 2016 22:50:58 +0200
changeset 1971 ec4924ea8bc6
parent 1970 076baad148d9
child 1972 04ce84b7b9d1
topic: make sure we have the 'wlock' when setting topic We where writing the '.hg/topic' file without a lot. That was bad.
hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py	Wed Jul 13 16:19:41 2016 +0200
+++ b/hgext3rd/topic/__init__.py	Thu Aug 11 22:50:58 2016 +0200
@@ -259,8 +259,9 @@
             repo.vfs.unlink('topic')
         return
     if topic:
-        with repo.vfs.open('topic', 'w') as f:
-            f.write(topic)
+        with repo.wlock():
+            with repo.vfs.open('topic', 'w') as f:
+                f.write(topic)
         return
     current = repo.currenttopic
     for t in sorted(repo.topics):
@@ -275,11 +276,12 @@
     ui.write(_("topic:  %s\n") % t)
 
 def commitwrap(orig, ui, repo, *args, **opts):
-    if opts.get('topic'):
-        t = opts['topic']
-        with repo.vfs.open('topic', 'w') as f:
-            f.write(t)
-    return orig(ui, repo, *args, **opts)
+    with repo.wlock():
+        if opts.get('topic'):
+            t = opts['topic']
+            with repo.vfs.open('topic', 'w') as f:
+                f.write(t)
+        return orig(ui, repo, *args, **opts)
 
 def committextwrap(orig, repo, ctx, subs, extramsg):
     ret = orig(repo, ctx, subs, extramsg)