mercurial/branching/rev_cache.py
changeset 51903 bd7359c18d69
parent 51902 0f26ee69cf36
child 51904 16efed18ae4e
equal deleted inserted replaced
51902:0f26ee69cf36 51903:bd7359c18d69
    31 # The "V2" version use the same format as the "V1" but garantee it won't be
    31 # The "V2" version use the same format as the "V1" but garantee it won't be
    32 # truncated, preventing SIGBUS when it is mmap-ed
    32 # truncated, preventing SIGBUS when it is mmap-ed
    33 _rbcversion = b'-v2'
    33 _rbcversion = b'-v2'
    34 _rbcnames = b'rbc-names' + _rbcversion
    34 _rbcnames = b'rbc-names' + _rbcversion
    35 _rbcrevs = b'rbc-revs' + _rbcversion
    35 _rbcrevs = b'rbc-revs' + _rbcversion
       
    36 _rbc_legacy_version = b'-v1'
       
    37 _rbc_legacy_names = b'rbc-names' + _rbc_legacy_version
       
    38 _rbc_legacy_revs = b'rbc-revs' + _rbc_legacy_version
    36 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open]
    39 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open]
    37 _rbcrecfmt = b'>4sI'
    40 _rbcrecfmt = b'>4sI'
    38 _rbcrecsize = calcsize(_rbcrecfmt)
    41 _rbcrecsize = calcsize(_rbcrecfmt)
    39 _rbcmininc = 64 * _rbcrecsize
    42 _rbcmininc = 64 * _rbcrecsize
    40 _rbcnodelen = 4
    43 _rbcnodelen = 4
   141         assert repo.filtername is None
   144         assert repo.filtername is None
   142         self._repo = repo
   145         self._repo = repo
   143         self._names = []  # branch names in local encoding with static index
   146         self._names = []  # branch names in local encoding with static index
   144         self._rbcrevs = rbcrevs(bytearray())
   147         self._rbcrevs = rbcrevs(bytearray())
   145         self._rbcsnameslen = 0  # length of names read at _rbcsnameslen
   148         self._rbcsnameslen = 0  # length of names read at _rbcsnameslen
       
   149         v1_fallback = False
   146         try:
   150         try:
   147             bndata = repo.cachevfs.read(_rbcnames)
   151             try:
       
   152                 bndata = repo.cachevfs.read(_rbcnames)
       
   153             except (IOError, OSError):
       
   154                 # If we don't have "v2" data, we might have "v1" data worth
       
   155                 # using.
       
   156                 #
       
   157                 # consider stop doing this many version after hg-6.9 release
       
   158                 bndata = repo.cachevfs.read(_rbc_legacy_names)
       
   159                 v1_fallback = True
   148             self._rbcsnameslen = len(bndata)  # for verification before writing
   160             self._rbcsnameslen = len(bndata)  # for verification before writing
   149             if bndata:
   161             if bndata:
   150                 self._names = [
   162                 self._names = [
   151                     encoding.tolocal(bn) for bn in bndata.split(b'\0')
   163                     encoding.tolocal(bn) for bn in bndata.split(b'\0')
   152                 ]
   164                 ]
   156                 self.branchinfo = self._branchinfo
   168                 self.branchinfo = self._branchinfo
   157 
   169 
   158         if self._names:
   170         if self._names:
   159             try:
   171             try:
   160                 usemmap = repo.ui.configbool(b'storage', b'revbranchcache.mmap')
   172                 usemmap = repo.ui.configbool(b'storage', b'revbranchcache.mmap')
   161                 with repo.cachevfs(_rbcrevs) as fp:
   173                 if not v1_fallback:
   162                     if usemmap and repo.cachevfs.is_mmap_safe(_rbcrevs):
   174                     with repo.cachevfs(_rbcrevs) as fp:
   163                         data = util.buffer(util.mmapread(fp))
   175                         if usemmap and repo.cachevfs.is_mmap_safe(_rbcrevs):
   164                     else:
   176                             data = util.buffer(util.mmapread(fp))
       
   177                         else:
       
   178                             data = fp.read()
       
   179                 else:
       
   180                     # If we don't have "v2" data, we might have "v1" data worth
       
   181                     # using.
       
   182                     #
       
   183                     # Consider stop doing this many version after hg-6.9
       
   184                     # release.
       
   185                     with repo.cachevfs(_rbc_legacy_revs) as fp:
   165                         data = fp.read()
   186                         data = fp.read()
   166                 self._rbcrevs = rbcrevs(data)
   187                 self._rbcrevs = rbcrevs(data)
   167             except (IOError, OSError) as inst:
   188             except (IOError, OSError) as inst:
   168                 repo.ui.debug(
   189                 repo.ui.debug(
   169                     b"couldn't read revision branch cache: %s\n"
   190                     b"couldn't read revision branch cache: %s\n"