src/topic/__init__.py
changeset 1853 8db7828751b7
parent 1852 3084687f7994
child 1854 67950fcf1c69
--- a/src/topic/__init__.py	Wed Jun 10 17:52:07 2015 -0500
+++ b/src/topic/__init__.py	Fri Jun 12 16:39:39 2015 -0500
@@ -21,6 +21,7 @@
 from mercurial import obsolete
 from mercurial import phases
 from mercurial import util
+from mercurial import merge
 
 from . import constants
 from . import revset as topicrevset
@@ -142,27 +143,31 @@
                           "\nHG: topic '%s'\nHG: branch" % t)
     return ret
 
-def updatewrap(orig, ui, repo, *args, **kwargs):
-    ret = orig(ui, repo, *args, **kwargs)
-    pctx = repo['.']
-    ot = repo.currenttopic
-    if pctx.phase() == phases.public and repo.vfs.exists('topic'):
-        repo.vfs.unlink('topic')
-    else:
-        # inherit the topic of the parent revision
-        t = pctx.extra().get(constants.extrakey, '')
-        if t and pctx.phase() > phases.public:
+def mergeupdatewrap(orig, repo, node, branchmerge, force, partial,
+                    ancestor=None, mergeancestor=False, labels=None):
+    wlock = repo.wlock()
+    try:
+        ret = orig(repo, node, branchmerge, force, partial, ancestor=ancestor,
+                   mergeancestor=mergeancestor, labels=labels)
+        if not partial and not branchmerge:
+            ot = repo.currenttopic
+            t = ''
+            pctx = repo[node]
+            if pctx.phase() > phases.public:
+                t = pctx.extra().get(constants.extrakey, '')
             with repo.vfs.open('topic', 'w') as f:
                 f.write(t)
-            if t != ot:
-                ui.status(_("switching to topic %s\n") % t)
-    return ret
+            if t and t != ot:
+                repo.ui.status(_("switching to topic %s\n") % t)
+        return ret
+    finally:
+        wlock.release()
 
 entry = extensions.wrapcommand(commands.table, 'commit', commitwrap)
 entry[1].append(('t', 'topic', '',
                  _("use specified topic"), _('TOPIC')))
 
-extensions.wrapcommand(commands.table, 'update', updatewrap)
 extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
+extensions.wrapfunction(merge, 'update', mergeupdatewrap)
 topicrevset.modsetup()
 cmdutil.summaryhooks.add('topic', summaryhook)