Mercurial > evolve
comparison src/topic/topicmap.py @ 1885:d49f75eab6a3
topic: take topic in account for all branch head computation
This changeset introduce a "topicmap" that is tracking not just the head of all
branches, but the heads of all branch+topic pair. Including the head of the part
of the branch without any topic. In practice this means that BRANCHNAME now
resolve to the tipmost part for the branch without topic and impact various
other logic like head checking during push and default destination for update and
merge (these aspect will need adjustment in later changesets).
The on-the-fly-temporary-monkey-patching process is pretty horrible, but allow
to move forward without waiting on having core patched.
We use 'branch:topic' as the branchmap key, this is a small and easy hack that
help use a lot for (future) support of heads discovery/checking and on disc
cache. I'm not sure it is worthwhile to improve this until an implementation
into core.
Note that this changeset change the branchmap in all cases, including during
exchange, see next changeset for improved behavior.
We also currently have the on-disk cache disabled because the core branchmap is
lacking phase information in its cache key. This will get done in a later
changesets
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sat, 12 Mar 2016 15:36:17 +0000 |
parents | |
children | e846b8f402d0 |
comparison
equal
deleted
inserted
replaced
1884:8a53f99d9061 | 1885:d49f75eab6a3 |
---|---|
1 from mercurial import branchmap | |
2 | |
3 def _filename(repo): | |
4 """name of a branchcache file for a given repo or repoview""" | |
5 filename = "cache/topicmap" | |
6 if repo.filtername: | |
7 filename = '%s-%s' % (filename, repo.filtername) | |
8 return filename | |
9 | |
10 oldbranchcache = branchmap.branchcache | |
11 | |
12 class topiccache(oldbranchcache): | |
13 | |
14 def __init__(self, *args, **kwargs): | |
15 otherbranchcache = branchmap.branchcache | |
16 try: | |
17 # super() call may fail otherwise | |
18 branchmap.branchcache = oldbranchcache | |
19 return super(topiccache, self).__init__(*args, **kwargs) | |
20 finally: | |
21 branchmap.branchcache = otherbranchcache | |
22 | |
23 def branchtip(self, branch, topic=''): | |
24 '''Return the tipmost open head on branch head, otherwise return the | |
25 tipmost closed head on branch. | |
26 Raise KeyError for unknown branch.''' | |
27 if topic: | |
28 branch = '%s:%s' % (branch, topic) | |
29 return super(topiccache, self).branchtip(branch) | |
30 | |
31 def branchheads(self, branch, closed=False, topic=''): | |
32 if topic: | |
33 branch = '%s:%s' % (branch, topic) | |
34 return super(topiccache, self).branchheads(branch, closed=closed) | |
35 | |
36 def write(self, repo): | |
37 # The cache key needs to take phase root in account because change to | |
38 # what is public affect topics. We can't write on disk until we have this. | |
39 return | |
40 | |
41 def update(self, repo, revgen): | |
42 """Given a branchhead cache, self, that may have extra nodes or be | |
43 missing heads, and a generator of nodes that are strictly a superset of | |
44 heads missing, this function updates self to be correct. | |
45 """ | |
46 oldgetbranchinfo = repo.revbranchcache().branchinfo | |
47 try: | |
48 def branchinfo(r): | |
49 info = oldgetbranchinfo(r) | |
50 topic = '' | |
51 ctx = repo[r] | |
52 if ctx.mutable(): | |
53 topic = ctx.topic() | |
54 branch = info[0] | |
55 if topic: | |
56 branch = '%s:%s' % (branch, topic) | |
57 return (branch, info[1]) | |
58 repo.revbranchcache().branchinfo = branchinfo | |
59 return super(topiccache, self).update(repo, revgen) | |
60 finally: | |
61 repo.revbranchcache().branchinfo = oldgetbranchinfo |