9 |
9 |
10 This is sort of similar to a bookmark, but it applies to a whole |
10 This is sort of similar to a bookmark, but it applies to a whole |
11 series instead of a single revision. |
11 series instead of a single revision. |
12 """ |
12 """ |
13 import functools |
13 import functools |
|
14 import contextlib |
14 |
15 |
15 from mercurial.i18n import _ |
16 from mercurial.i18n import _ |
16 from mercurial import branchmap |
17 from mercurial import branchmap |
17 from mercurial import bundle2 |
18 from mercurial import bundle2 |
18 from mercurial import cmdutil |
19 from mercurial import cmdutil |
60 return [] |
61 return [] |
61 |
62 |
62 def uisetup(ui): |
63 def uisetup(ui): |
63 destination.setupdest() |
64 destination.setupdest() |
64 |
65 |
|
66 @contextlib.contextmanager |
|
67 def usetopicmap(repo): |
|
68 """use awful monkey patching to update the topic cache""" |
|
69 oldbranchcache = branchmap.branchcache |
|
70 oldfilename = branchmap._filename |
|
71 oldcaches = getattr(repo, '_branchcaches', {}) |
|
72 try: |
|
73 branchmap.branchcache = topicmap.topiccache |
|
74 branchmap._filename = topicmap._filename |
|
75 repo._branchcaches = getattr(repo, '_topiccaches', {}) |
|
76 yield |
|
77 repo._topiccaches = repo._branchcaches |
|
78 finally: |
|
79 repo._branchcaches = oldcaches |
|
80 branchmap.branchcache = oldbranchcache |
|
81 branchmap._filename = oldfilename |
|
82 |
65 def reposetup(ui, repo): |
83 def reposetup(ui, repo): |
66 orig = repo.__class__ |
84 orig = repo.__class__ |
67 if not isinstance(repo, localrepo.localrepository): |
85 if not isinstance(repo, localrepo.localrepository): |
68 return # this can be a peer in the ssh case (puzzling) |
86 return # this can be a peer in the ssh case (puzzling) |
69 class topicrepo(repo.__class__): |
87 class topicrepo(repo.__class__): |
103 return self.vfs.tryread('topic') |
121 return self.vfs.tryread('topic') |
104 |
122 |
105 def branchmap(self, topic=True): |
123 def branchmap(self, topic=True): |
106 if not topic: |
124 if not topic: |
107 super(topicrepo, self).branchmap() |
125 super(topicrepo, self).branchmap() |
108 oldbranchcache = branchmap.branchcache |
126 with usetopicmap(self): |
109 oldfilename = branchmap._filename |
|
110 oldcaches = getattr(self, '_branchcaches', {}) |
|
111 try: |
|
112 branchmap.branchcache = topicmap.topiccache |
|
113 branchmap._filename = topicmap._filename |
|
114 self._branchcaches = getattr(self, '_topiccaches', {}) |
|
115 branchmap.updatecache(self) |
127 branchmap.updatecache(self) |
116 self._topiccaches = self._branchcaches |
128 return self._topiccaches[self.filtername] |
117 return self._topiccaches[self.filtername] |
|
118 finally: |
|
119 self._branchcaches = oldcaches |
|
120 branchmap.branchcache = oldbranchcache |
|
121 branchmap._filename = oldfilename |
|
122 |
129 |
123 def invalidatecaches(self): |
130 def invalidatecaches(self): |
124 super(topicrepo, self).invalidatecaches() |
131 super(topicrepo, self).invalidatecaches() |
125 if '_topiccaches' in vars(self.unfiltered()): |
132 if '_topiccaches' in vars(self.unfiltered()): |
126 self.unfiltered()._topiccaches.clear() |
133 self.unfiltered()._topiccaches.clear() |