mercurial/branchmap.py
changeset 41797 68bbcc70e274
parent 41759 aaad36b88298
child 41808 8ad46ac6728e
equal deleted inserted replaced
41792:2d835c42ab41 41797:68bbcc70e274
   177                 filteredhash = bin(cachekey[2])
   177                 filteredhash = bin(cachekey[2])
   178             bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash)
   178             bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash)
   179             if not bcache.validfor(repo):
   179             if not bcache.validfor(repo):
   180                 # invalidate the cache
   180                 # invalidate the cache
   181                 raise ValueError(r'tip differs')
   181                 raise ValueError(r'tip differs')
   182             cl = repo.changelog
   182             bcache.load(repo, f)
   183             for line in lineiter:
       
   184                 line = line.rstrip('\n')
       
   185                 if not line:
       
   186                     continue
       
   187                 node, state, label = line.split(" ", 2)
       
   188                 if state not in 'oc':
       
   189                     raise ValueError(r'invalid branch state')
       
   190                 label = encoding.tolocal(label.strip())
       
   191                 node = bin(node)
       
   192                 if not cl.hasnode(node):
       
   193                     raise ValueError(
       
   194                         r'node %s does not exist' % pycompat.sysstr(hex(node)))
       
   195                 bcache.setdefault(label, []).append(node)
       
   196                 if state == 'c':
       
   197                     bcache._closednodes.add(node)
       
   198 
       
   199         except (IOError, OSError):
   183         except (IOError, OSError):
   200             return None
   184             return None
   201 
   185 
   202         except Exception as inst:
   186         except Exception as inst:
   203             if repo.ui.debugflag:
   187             if repo.ui.debugflag:
   211         finally:
   195         finally:
   212             if f:
   196             if f:
   213                 f.close()
   197                 f.close()
   214 
   198 
   215         return bcache
   199         return bcache
       
   200 
       
   201     def load(self, repo, f):
       
   202         """ fully loads the branchcache by reading from the file f """
       
   203         cl = repo.changelog
       
   204         lineiter = iter(f)
       
   205         for line in lineiter:
       
   206             line = line.rstrip('\n')
       
   207             if not line:
       
   208                 continue
       
   209             node, state, label = line.split(" ", 2)
       
   210             if state not in 'oc':
       
   211                 raise ValueError(r'invalid branch state')
       
   212             label = encoding.tolocal(label.strip())
       
   213             node = bin(node)
       
   214             if not cl.hasnode(node):
       
   215                 raise ValueError(
       
   216                     r'node %s does not exist' % pycompat.sysstr(hex(node)))
       
   217             self.setdefault(label, []).append(node)
       
   218             if state == 'c':
       
   219                 self._closednodes.add(node)
   216 
   220 
   217     @staticmethod
   221     @staticmethod
   218     def _filename(repo):
   222     def _filename(repo):
   219         """name of a branchcache file for a given repo or repoview"""
   223         """name of a branchcache file for a given repo or repoview"""
   220         filename = "branch2"
   224         filename = "branch2"