author | Pierre-Yves David <pierre-yves.david@fb.com> |
Mon, 14 Mar 2016 19:03:32 +0000 | |
changeset 1907 | 95874e8fc5f2 |
parent 1901 | 85390446f8c1 |
child 1927 | cf33ba7fbf4b |
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 |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
2 |
from mercurial import encoding |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
3 |
from mercurial import error |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
4 |
from mercurial import scmutil |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
5 |
from mercurial import util |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
6 |
from mercurial.node import hex, bin, nullid |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
7 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
8 |
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
|
9 |
"""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
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
return filename |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
14 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
15 |
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
|
16 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
17 |
def _phaseshash(repo, maxrev): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
18 |
revs = set() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
19 |
cl = repo.changelog |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
20 |
fr = cl.filteredrevs |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
21 |
nm = cl.nodemap |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
22 |
for roots in repo._phasecache.phaseroots[1:]: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
23 |
for n in roots: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
24 |
r = nm.get(n) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
25 |
if r not in fr and r < maxrev: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
26 |
revs.add(r) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
27 |
key = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
28 |
revs = sorted(revs) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
29 |
if revs: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
30 |
s = util.sha1() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
31 |
for rev in revs: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
32 |
s.update('%s;' % rev) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
33 |
key = s.digest() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
34 |
return key |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
35 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
36 |
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
|
37 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 |
# 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
|
42 |
branchmap.branchcache = oldbranchcache |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
43 |
super(topiccache, self).__init__(*args, **kwargs) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
44 |
if self.filteredhash is None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
45 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
46 |
self.phaseshash = nullid |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
47 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
48 |
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
|
49 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
50 |
def copy(self): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
51 |
"""return an deep copy of the branchcache object""" |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
52 |
new = topiccache(self, self.tipnode, self.tiprev, self.filteredhash, |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
53 |
self._closednodes) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
54 |
if self.filteredhash is None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
55 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
56 |
new.phaseshash = self.phaseshash |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
57 |
return new |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
58 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
59 |
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
|
60 |
'''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
|
61 |
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
|
62 |
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
|
63 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
67 |
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
|
68 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
72 |
def validfor(self, repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
73 |
"""Is the cache content valid regarding a repo |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
74 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
75 |
- False when cached tipnode is unknown or if we detect a strip. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
76 |
- True when cache is up to date or a subset of current repo.""" |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
77 |
# This is copy paste of mercurial.branchmap.branchcache.validfor in |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
78 |
# 69077c65919d With a small changes to the cache key handling to |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
79 |
# include phase information that impact the topic cache. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
80 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
81 |
# All code changes should be flagged on site. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
82 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
83 |
if (self.tipnode == repo.changelog.node(self.tiprev)): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
84 |
fh = scmutil.filteredhash(repo, self.tiprev) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
85 |
if fh is None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
86 |
fh = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
87 |
if ((self.filteredhash == fh) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
88 |
and (self.phaseshash == _phaseshash(repo, self.tiprev))): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
89 |
return True |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
90 |
return False |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
91 |
except IndexError: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
92 |
return False |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
93 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
94 |
def write(self, repo): |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
95 |
# This is copy paste of mercurial.branchmap.branchcache.write in |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
96 |
# 69077c65919d With a small changes to the cache key handling to |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
97 |
# include phase information that impact the topic cache. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
98 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
99 |
# All code changes should be flagged on site. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
100 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
101 |
f = repo.vfs(_filename(repo), "w", atomictemp=True) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
102 |
cachekey = [hex(self.tipnode), str(self.tiprev)] |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
103 |
# [CHANGE] we need a hash in all cases |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
104 |
assert self.filteredhash is not None |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
105 |
cachekey.append(hex(self.filteredhash)) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
106 |
cachekey.append(hex(self.phaseshash)) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
107 |
f.write(" ".join(cachekey) + '\n') |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
108 |
nodecount = 0 |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
109 |
for label, nodes in sorted(self.iteritems()): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
110 |
for node in nodes: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
111 |
nodecount += 1 |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
112 |
if node in self._closednodes: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
113 |
state = 'c' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
114 |
else: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
115 |
state = 'o' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
116 |
f.write("%s %s %s\n" % (hex(node), state, |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
117 |
encoding.fromlocal(label))) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
118 |
f.close() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
119 |
repo.ui.log('branchcache', |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
120 |
'wrote %s branch cache with %d labels and %d nodes\n', |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
121 |
repo.filtername, len(self), nodecount) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
122 |
except (IOError, OSError, error.Abort) as inst: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
123 |
repo.ui.debug("couldn't write branch cache: %s\n" % inst) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
124 |
# Abort may be raise by read only opener |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
125 |
pass |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
126 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
127 |
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
|
128 |
"""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
|
129 |
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
|
130 |
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
|
131 |
""" |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
132 |
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
|
133 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
topic = '' |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
repo.revbranchcache().branchinfo = branchinfo |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
145 |
super(topiccache, self).update(repo, revgen) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
146 |
if self.filteredhash is None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
147 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
148 |
self.phaseshash = _phaseshash(repo, self.tiprev) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
149 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
150 |
repo.revbranchcache().branchinfo = oldgetbranchinfo |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
151 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
152 |
def readtopicmap(repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
153 |
# This is copy paste of mercurial.branchmap.read in 69077c65919d |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
154 |
# With a small changes to the cache key handling to include phase |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
155 |
# information that impact the topic cache. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
156 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
157 |
# All code changes should be flagged on site. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
158 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
159 |
f = repo.vfs(_filename(repo)) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
160 |
lines = f.read().split('\n') |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
161 |
f.close() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
162 |
except (IOError, OSError): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
163 |
return None |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
164 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
165 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
166 |
cachekey = lines.pop(0).split(" ", 2) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
167 |
last, lrev = cachekey[:2] |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
168 |
last, lrev = bin(last), int(lrev) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
169 |
filteredhash = bin(cachekey[2]) # [CHANGE] unconditional filteredhash |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
170 |
partial = branchcache(tipnode=last, tiprev=lrev, |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
171 |
filteredhash=filteredhash) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
172 |
partial.phaseshash = bin(cachekey[3]) # [CHANGE] read phaseshash |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
173 |
if not partial.validfor(repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
174 |
# invalidate the cache |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
175 |
raise ValueError('tip differs') |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
176 |
cl = repo.changelog |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
177 |
for l in lines: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
178 |
if not l: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
179 |
continue |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
180 |
node, state, label = l.split(" ", 2) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
181 |
if state not in 'oc': |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
182 |
raise ValueError('invalid branch state') |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
183 |
label = encoding.tolocal(label.strip()) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
184 |
node = bin(node) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
185 |
if not cl.hasnode(node): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
186 |
raise ValueError('node %s does not exist' % hex(node)) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
187 |
partial.setdefault(label, []).append(node) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
188 |
if state == 'c': |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
189 |
partial._closednodes.add(node) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
190 |
except KeyboardInterrupt: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
191 |
raise |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
192 |
except Exception as inst: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
193 |
if repo.ui.debugflag: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
194 |
msg = 'invalid branchheads cache' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
195 |
if repo.filtername is not None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
196 |
msg += ' (%s)' % repo.filtername |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
197 |
msg += ': %s\n' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
198 |
repo.ui.debug(msg % inst) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
199 |
partial = None |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
200 |
return partial |