comparison mercurial/branchmap.py @ 41797:68bbcc70e274

branchcache: move loading of branch names and nodes into it's own function This will help me in implementing lazy loading of the branchcache in upcoming patches. Differential Revision: https://phab.mercurial-scm.org/D6023
author Pulkit Goyal <pulkit@yandex-team.ru>
date Mon, 25 Feb 2019 16:49:01 +0300
parents aaad36b88298
children 8ad46ac6728e
comparison
equal deleted inserted replaced
41792:2d835c42ab41 41797:68bbcc70e274
177 filteredhash = bin(cachekey[2]) 177 filteredhash = bin(cachekey[2])
178 bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash) 178 bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash)
179 if not bcache.validfor(repo): 179 if not bcache.validfor(repo):
180 # invalidate the cache 180 # invalidate the cache
181 raise ValueError(r'tip differs') 181 raise ValueError(r'tip differs')
182 cl = repo.changelog 182 bcache.load(repo, f)
183 for line in lineiter:
184 line = line.rstrip('\n')
185 if not line:
186 continue
187 node, state, label = line.split(" ", 2)
188 if state not in 'oc':
189 raise ValueError(r'invalid branch state')
190 label = encoding.tolocal(label.strip())
191 node = bin(node)
192 if not cl.hasnode(node):
193 raise ValueError(
194 r'node %s does not exist' % pycompat.sysstr(hex(node)))
195 bcache.setdefault(label, []).append(node)
196 if state == 'c':
197 bcache._closednodes.add(node)
198
199 except (IOError, OSError): 183 except (IOError, OSError):
200 return None 184 return None
201 185
202 except Exception as inst: 186 except Exception as inst:
203 if repo.ui.debugflag: 187 if repo.ui.debugflag:
211 finally: 195 finally:
212 if f: 196 if f:
213 f.close() 197 f.close()
214 198
215 return bcache 199 return bcache
200
201 def load(self, repo, f):
202 """ fully loads the branchcache by reading from the file f """
203 cl = repo.changelog
204 lineiter = iter(f)
205 for line in lineiter:
206 line = line.rstrip('\n')
207 if not line:
208 continue
209 node, state, label = line.split(" ", 2)
210 if state not in 'oc':
211 raise ValueError(r'invalid branch state')
212 label = encoding.tolocal(label.strip())
213 node = bin(node)
214 if not cl.hasnode(node):
215 raise ValueError(
216 r'node %s does not exist' % pycompat.sysstr(hex(node)))
217 self.setdefault(label, []).append(node)
218 if state == 'c':
219 self._closednodes.add(node)
216 220
217 @staticmethod 221 @staticmethod
218 def _filename(repo): 222 def _filename(repo):
219 """name of a branchcache file for a given repo or repoview""" 223 """name of a branchcache file for a given repo or repoview"""
220 filename = "branch2" 224 filename = "branch2"