author | Pierre-Yves David <pierre-yves.david@fb.com> |
Sat, 12 Mar 2016 15:36:17 +0000 | |
changeset 1885 | d49f75eab6a3 |
child 1890 | e846b8f402d0 |
permissions | -rw-r--r-- |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
1 |
from mercurial import branchmap |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
2 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
3 |
def _filename(repo): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
4 |
"""name of a branchcache file for a given repo or repoview""" |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
5 |
filename = "cache/topicmap" |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
6 |
if repo.filtername: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
7 |
filename = '%s-%s' % (filename, repo.filtername) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
8 |
return filename |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
9 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
10 |
oldbranchcache = branchmap.branchcache |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
11 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
12 |
class topiccache(oldbranchcache): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
13 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
14 |
def __init__(self, *args, **kwargs): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
15 |
otherbranchcache = branchmap.branchcache |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
16 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
17 |
# super() call may fail otherwise |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
18 |
branchmap.branchcache = oldbranchcache |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
19 |
return super(topiccache, self).__init__(*args, **kwargs) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
20 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
21 |
branchmap.branchcache = otherbranchcache |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
22 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
23 |
def branchtip(self, branch, topic=''): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
24 |
'''Return the tipmost open head on branch head, otherwise return the |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
25 |
tipmost closed head on branch. |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
26 |
Raise KeyError for unknown branch.''' |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
27 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
28 |
branch = '%s:%s' % (branch, topic) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
29 |
return super(topiccache, self).branchtip(branch) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
30 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
31 |
def branchheads(self, branch, closed=False, topic=''): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
32 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
33 |
branch = '%s:%s' % (branch, topic) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
34 |
return super(topiccache, self).branchheads(branch, closed=closed) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
35 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
36 |
def write(self, repo): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
37 |
# The cache key needs to take phase root in account because change to |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
38 |
# what is public affect topics. We can't write on disk until we have this. |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
39 |
return |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
40 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 |
def update(self, repo, revgen): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
42 |
"""Given a branchhead cache, self, that may have extra nodes or be |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
43 |
missing heads, and a generator of nodes that are strictly a superset of |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
44 |
heads missing, this function updates self to be correct. |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
45 |
""" |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
46 |
oldgetbranchinfo = repo.revbranchcache().branchinfo |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
47 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
48 |
def branchinfo(r): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
49 |
info = oldgetbranchinfo(r) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
50 |
topic = '' |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
51 |
ctx = repo[r] |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
52 |
if ctx.mutable(): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
53 |
topic = ctx.topic() |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
54 |
branch = info[0] |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
55 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
56 |
branch = '%s:%s' % (branch, topic) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
57 |
return (branch, info[1]) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
58 |
repo.revbranchcache().branchinfo = branchinfo |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
59 |
return super(topiccache, self).update(repo, revgen) |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
60 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
61 |
repo.revbranchcache().branchinfo = oldgetbranchinfo |