Mercurial > public > mercurial-scm > hg
comparison mercurial/branchmap.py @ 42007:b5511845f9d5
branchcache: have a hasnode function to validate nodes
Upcoming patches will delay node validation until it's required. So we need to a
way in branchcache class to check whether a node exists or node.
Other options were making repo or changelog an attribute of branchcache object.
But the branchcache depends on filters so I decided to pass a function object.
Differential Revision: https://phab.mercurial-scm.org/D6157
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Tue, 19 Mar 2019 16:26:52 +0300 |
parents | 111de135fc76 |
children | f0fa0fc4900a |
comparison
equal
deleted
inserted
replaced
42006:111de135fc76 | 42007:b5511845f9d5 |
---|---|
148 This field can be used to avoid changelog reads when determining if a | 148 This field can be used to avoid changelog reads when determining if a |
149 branch head closes a branch or not. | 149 branch head closes a branch or not. |
150 """ | 150 """ |
151 | 151 |
152 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev, | 152 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev, |
153 filteredhash=None, closednodes=None): | 153 filteredhash=None, closednodes=None, hasnode=None): |
154 """ hasnode is a function which can be used to verify whether changelog | |
155 has a given node or not. If it's not provided, we assume that every node | |
156 we have exists in changelog """ | |
154 self.tipnode = tipnode | 157 self.tipnode = tipnode |
155 self.tiprev = tiprev | 158 self.tiprev = tiprev |
156 self.filteredhash = filteredhash | 159 self.filteredhash = filteredhash |
157 # closednodes is a set of nodes that close their branch. If the branch | 160 # closednodes is a set of nodes that close their branch. If the branch |
158 # cache has been updated, it may contain nodes that are no longer | 161 # cache has been updated, it may contain nodes that are no longer |
164 self._entries = dict(entries) | 167 self._entries = dict(entries) |
165 # whether closed nodes are verified or not | 168 # whether closed nodes are verified or not |
166 self._closedverified = False | 169 self._closedverified = False |
167 # branches for which nodes are verified | 170 # branches for which nodes are verified |
168 self._verifiedbranches = set() | 171 self._verifiedbranches = set() |
172 self._hasnode = hasnode | |
173 if self._hasnode is None: | |
174 self._hasnode = lambda x: True | |
169 | 175 |
170 def __iter__(self): | 176 def __iter__(self): |
171 return iter(self._entries) | 177 return iter(self._entries) |
172 | 178 |
173 def __setitem__(self, key, value): | 179 def __setitem__(self, key, value): |
191 lineiter = iter(f) | 197 lineiter = iter(f) |
192 cachekey = next(lineiter).rstrip('\n').split(" ", 2) | 198 cachekey = next(lineiter).rstrip('\n').split(" ", 2) |
193 last, lrev = cachekey[:2] | 199 last, lrev = cachekey[:2] |
194 last, lrev = bin(last), int(lrev) | 200 last, lrev = bin(last), int(lrev) |
195 filteredhash = None | 201 filteredhash = None |
202 hasnode = repo.changelog.hasnode | |
196 if len(cachekey) > 2: | 203 if len(cachekey) > 2: |
197 filteredhash = bin(cachekey[2]) | 204 filteredhash = bin(cachekey[2]) |
198 bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash) | 205 bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash, |
206 hasnode=hasnode) | |
199 if not bcache.validfor(repo): | 207 if not bcache.validfor(repo): |
200 # invalidate the cache | 208 # invalidate the cache |
201 raise ValueError(r'tip differs') | 209 raise ValueError(r'tip differs') |
202 bcache.load(repo, lineiter) | 210 bcache.load(repo, lineiter) |
203 except (IOError, OSError): | 211 except (IOError, OSError): |