Mercurial > hg
comparison mercurial/branchmap.py @ 29745:3b184adfb5be
branchmap: simplify error handlind when writing rev branch cache
Now that we have a general try except, we can move the error handling from the
individual writes in it.
Code will be reindented in the next changeset to help this on readability.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 05 Aug 2016 15:00:53 +0200 |
parents | 0d588332ad2c |
children | 3dbc95f3eb31 |
comparison
equal
deleted
inserted
replaced
29744:0d588332ad2c | 29745:3b184adfb5be |
---|---|
469 | 469 |
470 def write(self, tr=None): | 470 def write(self, tr=None): |
471 """Save branch cache if it is dirty.""" | 471 """Save branch cache if it is dirty.""" |
472 repo = self._repo | 472 repo = self._repo |
473 wlock = None | 473 wlock = None |
474 step = '' | |
474 try: | 475 try: |
475 if self._rbcnamescount < len(self._names): | 476 if self._rbcnamescount < len(self._names): |
477 step = ' names' | |
476 wlock = repo.wlock(wait=False) | 478 wlock = repo.wlock(wait=False) |
477 try: | 479 if True: |
478 if self._rbcnamescount != 0: | 480 if self._rbcnamescount != 0: |
479 f = repo.vfs.open(_rbcnames, 'ab') | 481 f = repo.vfs.open(_rbcnames, 'ab') |
480 if f.tell() == self._rbcsnameslen: | 482 if f.tell() == self._rbcsnameslen: |
481 f.write('\0') | 483 f.write('\0') |
482 else: | 484 else: |
493 f.write('\0'.join(encoding.fromlocal(b) | 495 f.write('\0'.join(encoding.fromlocal(b) |
494 for b in self._names[self._rbcnamescount:] | 496 for b in self._names[self._rbcnamescount:] |
495 )) | 497 )) |
496 self._rbcsnameslen = f.tell() | 498 self._rbcsnameslen = f.tell() |
497 f.close() | 499 f.close() |
498 except (IOError, OSError, error.Abort) as inst: | |
499 repo.ui.debug("couldn't write revision branch cache names: " | |
500 "%s\n" % inst) | |
501 return | |
502 self._rbcnamescount = len(self._names) | 500 self._rbcnamescount = len(self._names) |
503 | 501 |
504 start = self._rbcrevslen * _rbcrecsize | 502 start = self._rbcrevslen * _rbcrecsize |
505 if start != len(self._rbcrevs): | 503 if start != len(self._rbcrevs): |
504 step = '' | |
506 if wlock is None: | 505 if wlock is None: |
507 wlock = repo.wlock(wait=False) | 506 wlock = repo.wlock(wait=False) |
508 revs = min(len(repo.changelog), | 507 revs = min(len(repo.changelog), |
509 len(self._rbcrevs) // _rbcrecsize) | 508 len(self._rbcrevs) // _rbcrecsize) |
510 try: | 509 if True: |
511 f = repo.vfs.open(_rbcrevs, 'ab') | 510 f = repo.vfs.open(_rbcrevs, 'ab') |
512 if f.tell() != start: | 511 if f.tell() != start: |
513 repo.ui.debug("truncating %s to %s\n" | 512 repo.ui.debug("truncating %s to %s\n" |
514 % (_rbcrevs, start)) | 513 % (_rbcrevs, start)) |
515 f.seek(start) | 514 f.seek(start) |
518 f.seek(start) | 517 f.seek(start) |
519 f.truncate() | 518 f.truncate() |
520 end = revs * _rbcrecsize | 519 end = revs * _rbcrecsize |
521 f.write(self._rbcrevs[start:end]) | 520 f.write(self._rbcrevs[start:end]) |
522 f.close() | 521 f.close() |
523 except (IOError, OSError, error.Abort) as inst: | |
524 repo.ui.debug("couldn't write revision branch cache: %s\n" % | |
525 inst) | |
526 return | |
527 self._rbcrevslen = revs | 522 self._rbcrevslen = revs |
528 except error.LockError as inst: | 523 except (IOError, OSError, error.Abort, error.LockError) as inst: |
529 repo.ui.debug("couldn't write revision branch cache: %s\n" % inst) | 524 repo.ui.debug("couldn't write revision branch cache%s: %s\n" |
525 % (step, inst)) | |
530 finally: | 526 finally: |
531 if wlock is not None: | 527 if wlock is not None: |
532 wlock.release() | 528 wlock.release() |