Mercurial > hg
comparison mercurial/branchmap.py @ 31346:2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Portable from 2.6-3.6.
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 12 Mar 2017 03:32:21 -0400 |
parents | 22fbca1d11ed |
children | 279430eeefdb |
comparison
equal
deleted
inserted
replaced
31345:dd49a6c166f7 | 31346:2a18e9e6ca43 |
---|---|
355 | 355 |
356 def __init__(self, repo, readonly=True): | 356 def __init__(self, repo, readonly=True): |
357 assert repo.filtername is None | 357 assert repo.filtername is None |
358 self._repo = repo | 358 self._repo = repo |
359 self._names = [] # branch names in local encoding with static index | 359 self._names = [] # branch names in local encoding with static index |
360 self._rbcrevs = array('c') # structs of type _rbcrecfmt | 360 self._rbcrevs = bytearray() |
361 self._rbcsnameslen = 0 # length of names read at _rbcsnameslen | 361 self._rbcsnameslen = 0 # length of names read at _rbcsnameslen |
362 try: | 362 try: |
363 bndata = repo.vfs.read(_rbcnames) | 363 bndata = repo.vfs.read(_rbcnames) |
364 self._rbcsnameslen = len(bndata) # for verification before writing | 364 self._rbcsnameslen = len(bndata) # for verification before writing |
365 self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')] | 365 self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')] |
369 self.branchinfo = self._branchinfo | 369 self.branchinfo = self._branchinfo |
370 | 370 |
371 if self._names: | 371 if self._names: |
372 try: | 372 try: |
373 data = repo.vfs.read(_rbcrevs) | 373 data = repo.vfs.read(_rbcrevs) |
374 self._rbcrevs.fromstring(data) | 374 self._rbcrevs[:] = data |
375 except (IOError, OSError) as inst: | 375 except (IOError, OSError) as inst: |
376 repo.ui.debug("couldn't read revision branch cache: %s\n" % | 376 repo.ui.debug("couldn't read revision branch cache: %s\n" % |
377 inst) | 377 inst) |
378 # remember number of good records on disk | 378 # remember number of good records on disk |
379 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize, | 379 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize, |
388 self._rbcsnameslen = 0 | 388 self._rbcsnameslen = 0 |
389 del self._names[:] | 389 del self._names[:] |
390 self._rbcnamescount = 0 | 390 self._rbcnamescount = 0 |
391 self._namesreverse.clear() | 391 self._namesreverse.clear() |
392 self._rbcrevslen = len(self._repo.changelog) | 392 self._rbcrevslen = len(self._repo.changelog) |
393 self._rbcrevs = array('c') | 393 self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize) |
394 self._rbcrevs.fromstring('\0' * (self._rbcrevslen * _rbcrecsize)) | |
395 | 394 |
396 def branchinfo(self, rev): | 395 def branchinfo(self, rev): |
397 """Return branch name and close flag for rev, using and updating | 396 """Return branch name and close flag for rev, using and updating |
398 persistent cache.""" | 397 persistent cache.""" |
399 changelog = self._repo.changelog | 398 changelog = self._repo.changelog |
452 return b, close | 451 return b, close |
453 | 452 |
454 def _setcachedata(self, rev, node, branchidx): | 453 def _setcachedata(self, rev, node, branchidx): |
455 """Writes the node's branch data to the in-memory cache data.""" | 454 """Writes the node's branch data to the in-memory cache data.""" |
456 rbcrevidx = rev * _rbcrecsize | 455 rbcrevidx = rev * _rbcrecsize |
457 rec = array('c') | 456 rec = bytearray(pack(_rbcrecfmt, node, branchidx)) |
458 rec.fromstring(pack(_rbcrecfmt, node, branchidx)) | |
459 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: | 457 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: |
460 self._rbcrevs.extend('\0' * | 458 self._rbcrevs.extend('\0' * |
461 (len(self._repo.changelog) * _rbcrecsize - | 459 (len(self._repo.changelog) * _rbcrecsize - |
462 len(self._rbcrevs))) | 460 len(self._rbcrevs))) |
463 self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec | 461 self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec |