contrib/perf.py
changeset 51008 2f1967ffefb1
parent 50993 12c308c55e53
child 51009 ffb393dd5999
equal deleted inserted replaced
51007:ccddd2f54013 51008:2f1967ffefb1
  3742             except NotImplementedError:
  3742             except NotImplementedError:
  3743                 pass
  3743                 pass
  3744 
  3744 
  3745     revs = list(rl.revs(startrev, len(rl) - 1))
  3745     revs = list(rl.revs(startrev, len(rl) - 1))
  3746 
  3746 
  3747     def rlfh(rl):
  3747     @contextlib.contextmanager
  3748         if rl._inline:
  3748     def reading(rl):
       
  3749         if getattr(rl, 'reading', None) is not None:
       
  3750             with rl.reading():
       
  3751                 yield None
       
  3752         elif rl._inline:
  3749             indexfile = getattr(rl, '_indexfile', None)
  3753             indexfile = getattr(rl, '_indexfile', None)
  3750             if indexfile is None:
  3754             if indexfile is None:
  3751                 # compatibility with <= hg-5.8
  3755                 # compatibility with <= hg-5.8
  3752                 indexfile = getattr(rl, 'indexfile')
  3756                 indexfile = getattr(rl, 'indexfile')
  3753             return getsvfs(repo)(indexfile)
  3757             yield getsvfs(repo)(indexfile)
  3754         else:
  3758         else:
  3755             datafile = getattr(rl, 'datafile', getattr(rl, 'datafile'))
  3759             datafile = getattr(rl, 'datafile', getattr(rl, 'datafile'))
  3756             return getsvfs(repo)(datafile)
  3760             yield getsvfs(repo)(datafile)
  3757 
  3761 
  3758     def doread():
  3762     def doread():
  3759         rl.clearcaches()
  3763         rl.clearcaches()
  3760         for rev in revs:
  3764         for rev in revs:
  3761             segmentforrevs(rev, rev)
  3765             segmentforrevs(rev, rev)
  3762 
  3766 
  3763     def doreadcachedfh():
  3767     def doreadcachedfh():
  3764         rl.clearcaches()
  3768         rl.clearcaches()
  3765         fh = rlfh(rl)
  3769         with reading(rl) as fh:
  3766         for rev in revs:
  3770             if fh is not None:
  3767             segmentforrevs(rev, rev, df=fh)
  3771                 for rev in revs:
       
  3772                     segmentforrevs(rev, rev, df=fh)
       
  3773             else:
       
  3774                 for rev in revs:
       
  3775                     segmentforrevs(rev, rev)
  3768 
  3776 
  3769     def doreadbatch():
  3777     def doreadbatch():
  3770         rl.clearcaches()
  3778         rl.clearcaches()
  3771         segmentforrevs(revs[0], revs[-1])
  3779         segmentforrevs(revs[0], revs[-1])
  3772 
  3780 
  3773     def doreadbatchcachedfh():
  3781     def doreadbatchcachedfh():
  3774         rl.clearcaches()
  3782         rl.clearcaches()
  3775         fh = rlfh(rl)
  3783         with reading(rl) as fh:
  3776         segmentforrevs(revs[0], revs[-1], df=fh)
  3784             if fh is not None:
       
  3785                 segmentforrevs(revs[0], revs[-1], df=fh)
       
  3786             else:
       
  3787                 segmentforrevs(revs[0], revs[-1])
  3777 
  3788 
  3778     def dochunk():
  3789     def dochunk():
  3779         rl.clearcaches()
  3790         rl.clearcaches()
  3780         fh = rlfh(rl)
  3791         with reading(rl) as fh:
  3781         for rev in revs:
  3792             if fh is not None:
  3782             rl._chunk(rev, df=fh)
  3793                 for rev in revs:
       
  3794                     rl._chunk(rev, df=fh)
       
  3795             else:
       
  3796                 for rev in revs:
       
  3797                     rl._chunk(rev)
  3783 
  3798 
  3784     chunks = [None]
  3799     chunks = [None]
  3785 
  3800 
  3786     def dochunkbatch():
  3801     def dochunkbatch():
  3787         rl.clearcaches()
  3802         rl.clearcaches()
  3788         fh = rlfh(rl)
  3803         with reading(rl) as fh:
  3789         # Save chunks as a side-effect.
  3804             if fh is not None:
  3790         chunks[0] = rl._chunks(revs, df=fh)
  3805                 # Save chunks as a side-effect.
       
  3806                 chunks[0] = rl._chunks(revs, df=fh)
       
  3807             else:
       
  3808                 # Save chunks as a side-effect.
       
  3809                 chunks[0] = rl._chunks(revs)
  3791 
  3810 
  3792     def docompress(compressor):
  3811     def docompress(compressor):
  3793         rl.clearcaches()
  3812         rl.clearcaches()
  3794 
  3813 
  3795         try:
  3814         try: