--- a/hgext3rd/topic/__init__.py Thu Sep 14 20:33:03 2017 +0200
+++ b/hgext3rd/topic/__init__.py Wed Sep 13 15:13:51 2017 +0200
@@ -58,6 +58,7 @@
from mercurial.i18n import _
from mercurial import (
bookmarks,
+ changelog,
cmdutil,
commands,
context,
@@ -307,6 +308,26 @@
repo.names.addnamespace(namespaces.namespace(
'topics', 'topic', namemap=_namemap, nodemap=_nodemap,
listnames=lambda repo: repo.topics))
+ # Wrap workingctx extra to return the topic name
+ extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
+ # Wrap changelog.add to drop empty topic
+ extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
+
+def wrapinit(orig, self, repo, *args, **kwargs):
+ orig(self, repo, *args, **kwargs)
+ if repo.currenttopic:
+ self._extra[constants.extrakey] = repo.currenttopic
+ else:
+ # Empty key will be dropped from extra by another hack at the changegroup level
+ self._extra[constants.extrakey] = ''
+
+def wrapadd(orig, cl, manifest, files, desc, transaction, p1, p2, user,
+ date=None, extra=None):
+ if constants.extrakey in extra and not extra[constants.extrakey]:
+ extra = extra.copy()
+ del extra[constants.extrakey]
+ return orig(cl, manifest, files, desc, transaction, p1, p2, user,
+ date=date, extra=extra)
# revset predicates are automatically registered at loading via this symbol
revsetpredicate = topicrevset.revsetpredicate