author | Pierre-Yves David <pierre-yves.david@fb.com> |
Wed, 30 Mar 2016 03:45:29 -0700 | |
changeset 1937 | 60b7de2b3dd1 |
parent 1928 | be0bc9dcb930 |
child 1949 | 79c08d17a3d7 |
permissions | -rw-r--r-- |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
1 |
from mercurial.node import hex, bin, nullid |
1937
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
2 |
from mercurial import ( |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
3 |
branchmap, |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
4 |
encoding, |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
5 |
error, |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
6 |
scmutil, |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
7 |
util, |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
8 |
) |
1885
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 |
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
|
11 |
"""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
|
12 |
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
|
13 |
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
|
14 |
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
|
15 |
return filename |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
16 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
17 |
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
|
18 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
19 |
def _phaseshash(repo, maxrev): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
20 |
revs = set() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
21 |
cl = repo.changelog |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
22 |
fr = cl.filteredrevs |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
23 |
nm = cl.nodemap |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
24 |
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
|
25 |
for n in roots: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
26 |
r = nm.get(n) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
27 |
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
|
28 |
revs.add(r) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
29 |
key = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
30 |
revs = sorted(revs) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
31 |
if revs: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
32 |
s = util.sha1() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
33 |
for rev in revs: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
34 |
s.update('%s;' % rev) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
35 |
key = s.digest() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
36 |
return key |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
37 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
38 |
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
|
39 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
40 |
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
|
41 |
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
|
42 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
43 |
# 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
|
44 |
branchmap.branchcache = oldbranchcache |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
48 |
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
|
49 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
50 |
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
|
51 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
52 |
def copy(self): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
53 |
"""return an deep copy of the branchcache object""" |
1928 | 54 |
new = topiccache(self, self.tipnode, self.tiprev, self.filteredhash, |
55 |
self._closednodes) |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
56 |
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
|
57 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
58 |
new.phaseshash = self.phaseshash |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
59 |
return new |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
60 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
61 |
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
|
62 |
'''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
|
63 |
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
|
64 |
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
|
65 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
69 |
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
|
70 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
|
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
74 |
def validfor(self, repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
75 |
"""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
|
76 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
77 |
- 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
|
78 |
- 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
|
79 |
# 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
|
80 |
# 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
|
81 |
# 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
|
82 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
83 |
# 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
|
84 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
if fh is None: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
88 |
fh = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
89 |
if ((self.filteredhash == fh) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
90 |
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
|
91 |
return True |
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 |
except IndexError: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
94 |
return False |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
95 |
|
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
96 |
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
|
97 |
# 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
|
98 |
# 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
|
99 |
# 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
|
100 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
101 |
# 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
|
102 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
# [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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
nodecount = 0 |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
111 |
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
|
112 |
for node in nodes: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
113 |
nodecount += 1 |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
114 |
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
|
115 |
state = 'c' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
116 |
else: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
117 |
state = 'o' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
118 |
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
|
119 |
encoding.fromlocal(label))) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
120 |
f.close() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
121 |
repo.ui.log('branchcache', |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
122 |
'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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
# 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
|
127 |
pass |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
128 |
|
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
129 |
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
|
130 |
"""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
|
131 |
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
|
132 |
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
|
133 |
""" |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
134 |
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
|
135 |
try: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
topic = '' |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
if topic: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
self.filteredhash = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
150 |
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
|
151 |
finally: |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
152 |
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
|
153 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
154 |
def readtopicmap(repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
155 |
# 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
|
156 |
# 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
|
157 |
# 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
|
158 |
# |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
159 |
# 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
|
160 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
161 |
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
|
162 |
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
|
163 |
f.close() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
164 |
except (IOError, OSError): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
165 |
return None |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
166 |
|
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
167 |
try: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
168 |
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
|
169 |
last, lrev = cachekey[:2] |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
170 |
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
|
171 |
filteredhash = bin(cachekey[2]) # [CHANGE] unconditional filteredhash |
1927
cf33ba7fbf4b
topiccache: directly instantiate a topiccache object when reading
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
172 |
partial = topiccache(tipnode=last, tiprev=lrev, |
1928 | 173 |
filteredhash=filteredhash) |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
# invalidate the cache |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
177 |
raise ValueError('tip differs') |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
178 |
cl = repo.changelog |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
179 |
for l in lines: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
180 |
if not l: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
181 |
continue |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
node = bin(node) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
if state == 'c': |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
191 |
partial._closednodes.add(node) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
192 |
except KeyboardInterrupt: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
193 |
raise |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
194 |
except Exception as inst: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
195 |
if repo.ui.debugflag: |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
196 |
msg = 'invalid branchheads cache' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
197 |
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
|
198 |
msg += ' (%s)' % repo.filtername |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
199 |
msg += ': %s\n' |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
200 |
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
|
201 |
partial = None |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
202 |
return partial |