--- a/hgext3rd/topic/topicmap.py Wed Mar 30 22:05:49 2016 -0700
+++ b/hgext3rd/topic/topicmap.py Wed Mar 30 22:25:17 2016 -0700
@@ -1,3 +1,5 @@
+import contextlib
+
from mercurial.node import hex, bin, nullid
from mercurial import (
branchmap,
@@ -35,6 +37,29 @@
key = s.digest()
return key
+@contextlib.contextmanager
+def usetopicmap(repo):
+ """use awful monkey patching to ensure topic map usage
+
+ During the extend of the context block, The topicmap should be used and
+ updated instead of the branchmap."""
+ oldbranchcache = branchmap.branchcache
+ oldfilename = branchmap._filename
+ oldread = branchmap.read
+ oldcaches = getattr(repo, '_branchcaches', {})
+ try:
+ branchmap.branchcache = topiccache
+ branchmap._filename = _filename
+ branchmap.read = readtopicmap
+ repo._branchcaches = getattr(repo, '_topiccaches', {})
+ yield
+ repo._topiccaches = repo._branchcaches
+ finally:
+ repo._branchcaches = oldcaches
+ branchmap.branchcache = oldbranchcache
+ branchmap._filename = oldfilename
+ branchmap.read = oldread
+
class topiccache(oldbranchcache):
def __init__(self, *args, **kwargs):