Mercurial > evolve
comparison hgext3rd/topic/topicmap.py @ 6336:453861da6922
topic: use fully qualified branch name during exchange
For the entire duration of exchange process, we now use branch//namespace/topic
format for branchmap, head checking, etc.
Sometimes we still need to disable this feature (e.g. when pushing to a repo
that doesn't have topic extension enabled), but every other case should be
handled using the new fqbn format. This applies both to internal API, such as
having fqbn as branchmap keys and even making ctx.branch() return fqbn, and to
UI, such as users seeing fqbn in hg branches output and messages from hg push.
Things to note: now we're wrapping revbranchcache.branchinfo() during the
extension setup, instead of doing it only in one place in _headssummary().
We're also using override_context_branch context manager that makes
ctx.branch() return fqbn also in cases when we call the original
_headssummary().
There are still places in the UI where branch names are not in fqbn format,
because they don't take part in the exchange process.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sat, 12 Nov 2022 16:24:55 +0400 |
parents | f4ffe1e67a9b |
children | 3271ec128328 |
comparison
equal
deleted
inserted
replaced
6335:394c795d7ba4 | 6336:453861da6922 |
---|---|
176 args = (self._repo,) + args | 176 args = (self._repo,) + args |
177 new = self.__class__(*args) | 177 new = self.__class__(*args) |
178 new.phaseshash = self.phaseshash | 178 new.phaseshash = self.phaseshash |
179 return new | 179 return new |
180 | 180 |
181 def load(self, repo, lineiter): | |
182 """call branchmap.load(), and then transform branch names to be in the | |
183 new "//" format | |
184 """ | |
185 super(_topiccache, self).load(repo, lineiter) | |
186 entries = compat.bcentries(self) | |
187 | |
188 for branch in tuple(entries): | |
189 formatted = common.formatfqbn(branch=branch) | |
190 if branch != formatted: | |
191 entries[formatted] = entries.pop(branch) | |
192 | |
181 def validfor(self, repo): | 193 def validfor(self, repo): |
182 """Is the cache content valid regarding a repo | 194 """Is the cache content valid regarding a repo |
183 | 195 |
184 - False when cached tipnode is unknown or if we detect a strip. | 196 - False when cached tipnode is unknown or if we detect a strip. |
185 - True when cache is up to date or a subset of current repo.""" | 197 - True when cache is up to date or a subset of current repo.""" |
196 return valid | 208 return valid |
197 except IndexError: | 209 except IndexError: |
198 return False | 210 return False |
199 | 211 |
200 def write(self, repo): | 212 def write(self, repo): |
213 """write cache to disk if it's not topic-only, but first transform | |
214 cache keys from branches in "//" format into bare branch names | |
215 """ | |
201 # we expect mutable set to be small enough to be that computing it all | 216 # we expect mutable set to be small enough to be that computing it all |
202 # the time will be fast enough | 217 # the time will be fast enough |
203 if not istopicfilter(repo.filtername): | 218 if not istopicfilter(repo.filtername): |
204 super(_topiccache, self).write(repo) | 219 cache = self.copy() |
220 entries = compat.bcentries(cache) | |
221 | |
222 for formatted in tuple(entries): | |
223 branch, tns, topic = common.parsefqbn(formatted) | |
224 if branch != formatted: | |
225 entries[branch] = entries.pop(formatted) | |
226 | |
227 super(_topiccache, cache).write(repo) | |
205 | 228 |
206 def update(self, repo, revgen): | 229 def update(self, repo, revgen): |
207 """Given a branchhead cache, self, that may have extra nodes or be | 230 """Given a branchhead cache, self, that may have extra nodes or be |
208 missing heads, and a generator of nodes that are strictly a superset of | 231 missing heads, and a generator of nodes that are strictly a superset of |
209 heads missing, this function updates self to be correct. | 232 heads missing, this function updates self to be correct. |
210 """ | 233 """ |
211 if not istopicfilter(repo.filtername): | 234 if not istopicfilter(repo.filtername): |
212 return super(_topiccache, self).update(repo, revgen) | 235 return super(_topiccache, self).update(repo, revgen) |
213 unfi = repo.unfiltered() | 236 |
214 oldgetbranchinfo = unfi.revbranchcache().branchinfo | 237 # See topic.discovery._headssummary(), where repo.unfiltered gets |
215 | 238 # overridden to return .filtered('unfiltered-topic'). revbranchcache |
216 def branchinfo(r, changelog=None): | 239 # only can be created for unfiltered repo (filtername is None), so we |
217 info = oldgetbranchinfo(r) | 240 # do that here, and this revbranchcache will be cached inside repo. |
218 ctx = unfi[r] | 241 # When we get rid of *-topic filters, then this workaround can be |
219 branch = info[0] | 242 # removed too. |
220 if ctx.mutable(): | 243 repo.unfiltered().revbranchcache() |
221 branch = ctx.fqbn() | 244 |
222 return (branch, info[1]) | 245 super(_topiccache, self).update(repo, revgen) |
223 try: | 246 self.phaseshash = _phaseshash(repo, self.tiprev) |
224 unfi.revbranchcache().branchinfo = branchinfo | |
225 super(_topiccache, self).update(repo, revgen) | |
226 self.phaseshash = _phaseshash(repo, self.tiprev) | |
227 finally: | |
228 unfi.revbranchcache().branchinfo = oldgetbranchinfo |