314 if wlock is not None: |
314 if wlock is not None: |
315 wlock.release() |
315 wlock.release() |
316 |
316 |
317 def _writenames(self, repo): |
317 def _writenames(self, repo): |
318 """write the new branch names to revbranchcache""" |
318 """write the new branch names to revbranchcache""" |
319 if self._rbcnamescount != 0: |
319 f = None |
320 f = repo.cachevfs.open(_rbcnames, b'ab') |
320 try: |
321 if f.tell() == self._rbcsnameslen: |
321 if self._rbcnamescount != 0: |
322 f.write(b'\0') |
322 f = repo.cachevfs.open(_rbcnames, b'ab') |
323 else: |
323 if f.tell() == self._rbcsnameslen: |
|
324 f.write(b'\0') |
|
325 else: |
|
326 f.close() |
|
327 f = None |
|
328 repo.ui.debug(b"%s changed - rewriting it\n" % _rbcnames) |
|
329 self._rbcnamescount = 0 |
|
330 self._rbcrevslen = 0 |
|
331 if self._rbcnamescount == 0: |
|
332 # before rewriting names, make sure references are removed |
|
333 repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) |
|
334 f = repo.cachevfs.open(_rbcnames, b'wb') |
|
335 names = self._names[self._rbcnamescount :] |
|
336 from_local = encoding.fromlocal |
|
337 data = b'\0'.join(from_local(b) for b in names) |
|
338 f.write(data) |
|
339 self._rbcsnameslen = f.tell() |
|
340 finally: |
|
341 if f is not None: |
324 f.close() |
342 f.close() |
325 repo.ui.debug(b"%s changed - rewriting it\n" % _rbcnames) |
|
326 self._rbcnamescount = 0 |
|
327 self._rbcrevslen = 0 |
|
328 if self._rbcnamescount == 0: |
|
329 # before rewriting names, make sure references are removed |
|
330 repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) |
|
331 f = repo.cachevfs.open(_rbcnames, b'wb') |
|
332 f.write( |
|
333 b'\0'.join( |
|
334 encoding.fromlocal(b) |
|
335 for b in self._names[self._rbcnamescount :] |
|
336 ) |
|
337 ) |
|
338 self._rbcsnameslen = f.tell() |
|
339 f.close() |
|
340 self._rbcnamescount = len(self._names) |
343 self._rbcnamescount = len(self._names) |
341 |
344 |
342 def _writerevs(self, repo, start): |
345 def _writerevs(self, repo, start): |
343 """write the new revs to revbranchcache""" |
346 """write the new revs to revbranchcache""" |
344 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) |
347 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) |