Mercurial > public > mercurial-scm > hg
comparison mercurial/branchmap.py @ 18130:1b05ffce47bd
branchmap: make update responsible to update the cache key
The update function have all necessary data to keep the branchcache key
up to date with its value.
This saves assignment to the cache key that each caller of update had to do by
hand.
The strip case is a bit more complicated to handles from inside the function but
I do not expect any impact.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Mon, 24 Dec 2012 02:22:04 +0100 |
parents | 3264d3ce53a0 |
children | f0eeb9b3444a |
comparison
equal
deleted
inserted
replaced
18129:3264d3ce53a0 | 18130:1b05ffce47bd |
---|---|
89 ancestors = set(cl.ancestors([latest], | 89 ancestors = set(cl.ancestors([latest], |
90 bheadrevs[0])) | 90 bheadrevs[0])) |
91 if ancestors: | 91 if ancestors: |
92 bheadrevs = [b for b in bheadrevs if b not in ancestors] | 92 bheadrevs = [b for b in bheadrevs if b not in ancestors] |
93 partial[branch] = [cl.node(rev) for rev in bheadrevs] | 93 partial[branch] = [cl.node(rev) for rev in bheadrevs] |
94 tiprev = max(bheadrevs) | |
95 if tiprev > partial.tiprev: | |
96 partial.tipnode = cl.node(tiprev) | |
97 partial.tiprev = tiprev | |
98 | |
94 | 99 |
95 # There may be branches that cease to exist when the last commit in the | 100 # There may be branches that cease to exist when the last commit in the |
96 # branch was stripped. This code filters them out. Note that the | 101 # branch was stripped. This code filters them out. Note that the |
97 # branch that ceased to exist may not be in newbranches because | 102 # branch that ceased to exist may not be in newbranches because |
98 # newbranches is the set of candidate heads, which when you strip the | 103 # newbranches is the set of candidate heads, which when you strip the |
99 # last commit in a branch will be the parent branch. | 104 # last commit in a branch will be the parent branch. |
105 droppednodes = [] | |
100 for branch in partial.keys(): | 106 for branch in partial.keys(): |
101 nodes = [head for head in partial[branch] | 107 nodes = [head for head in partial[branch] |
102 if cl.hasnode(head)] | 108 if cl.hasnode(head)] |
103 if not nodes: | 109 if not nodes: |
110 droppednodes.extend(nodes) | |
104 del partial[branch] | 111 del partial[branch] |
112 try: | |
113 node = cl.node(partial.tiprev) | |
114 except IndexError: | |
115 node = None | |
116 if ((partial.tipnode != node) | |
117 or (partial.tipnode in droppednodes)): | |
118 # cache key are not valid anymore | |
119 partial.tipnode = nullid | |
120 partial.tiprev = nullrev | |
121 for heads in partial.values(): | |
122 tiprev = max(cl.rev(node) for node in heads) | |
123 if tiprev > partial.tiprev: | |
124 partial.tipnode = cl.node(tiprev) | |
125 partial.tiprev = tiprev | |
126 | |
105 | 127 |
106 def updatecache(repo): | 128 def updatecache(repo): |
107 repo = repo.unfiltered() # Until we get a smarter cache management | 129 repo = repo.unfiltered() # Until we get a smarter cache management |
108 cl = repo.changelog | 130 cl = repo.changelog |
109 tip = cl.tip() | 131 tip = cl.tip() |
119 # if partial.tiprev > catip: we have uncachable element in `partial` can't | 141 # if partial.tiprev > catip: we have uncachable element in `partial` can't |
120 # write on disk | 142 # write on disk |
121 if partial.tiprev < catip: | 143 if partial.tiprev < catip: |
122 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip)) | 144 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip)) |
123 update(repo, partial, ctxgen) | 145 update(repo, partial, ctxgen) |
124 partial.tipnode = cl.node(catip) | |
125 partial.tiprev = catip | |
126 partial.write(repo) | 146 partial.write(repo) |
127 # If cacheable tip were lower than actual tip, we need to update the | 147 # If cacheable tip were lower than actual tip, we need to update the |
128 # cache up to tip. This update (from cacheable to actual tip) is not | 148 # cache up to tip. This update (from cacheable to actual tip) is not |
129 # written to disk since it's not cacheable. | 149 # written to disk since it's not cacheable. |
130 tiprev = len(repo) - 1 | 150 tiprev = len(repo) - 1 |
131 if partial.tiprev < tiprev: | 151 if partial.tiprev < tiprev: |
132 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev)) | 152 ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev)) |
133 update(repo, partial, ctxgen) | 153 update(repo, partial, ctxgen) |
134 partial.tipnode = cl.node(tiprev) | |
135 partial.tiprev = tiprev | |
136 repo._branchcache = partial | 154 repo._branchcache = partial |
137 | 155 |
138 class branchcache(dict): | 156 class branchcache(dict): |
139 """A dict like object that hold branches heads cache""" | 157 """A dict like object that hold branches heads cache""" |
140 | 158 |