comparison hgext3rd/topic/topicmap.py @ 1949:79c08d17a3d7

topicmap: move the 'usetopicmap' context manager into the topicmap module There is no good reason to not have it gathered with the rest.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 30 Mar 2016 22:25:17 -0700
parents 60b7de2b3dd1
children 99c1a26abf3f
comparison
equal deleted inserted replaced
1948:54810b543bf4 1949:79c08d17a3d7
1 import contextlib
2
1 from mercurial.node import hex, bin, nullid 3 from mercurial.node import hex, bin, nullid
2 from mercurial import ( 4 from mercurial import (
3 branchmap, 5 branchmap,
4 encoding, 6 encoding,
5 error, 7 error,
32 s = util.sha1() 34 s = util.sha1()
33 for rev in revs: 35 for rev in revs:
34 s.update('%s;' % rev) 36 s.update('%s;' % rev)
35 key = s.digest() 37 key = s.digest()
36 return key 38 return key
39
40 @contextlib.contextmanager
41 def usetopicmap(repo):
42 """use awful monkey patching to ensure topic map usage
43
44 During the extend of the context block, The topicmap should be used and
45 updated instead of the branchmap."""
46 oldbranchcache = branchmap.branchcache
47 oldfilename = branchmap._filename
48 oldread = branchmap.read
49 oldcaches = getattr(repo, '_branchcaches', {})
50 try:
51 branchmap.branchcache = topiccache
52 branchmap._filename = _filename
53 branchmap.read = readtopicmap
54 repo._branchcaches = getattr(repo, '_topiccaches', {})
55 yield
56 repo._topiccaches = repo._branchcaches
57 finally:
58 repo._branchcaches = oldcaches
59 branchmap.branchcache = oldbranchcache
60 branchmap._filename = oldfilename
61 branchmap.read = oldread
37 62
38 class topiccache(oldbranchcache): 63 class topiccache(oldbranchcache):
39 64
40 def __init__(self, *args, **kwargs): 65 def __init__(self, *args, **kwargs):
41 otherbranchcache = branchmap.branchcache 66 otherbranchcache = branchmap.branchcache