mercurial/branchmap.py
changeset 18128 f0d56efaa35a
parent 18127 dcd43ac7572d
child 18129 3264d3ce53a0
equal deleted inserted replaced
18127:dcd43ac7572d 18128:f0d56efaa35a
    39     except Exception, inst:
    39     except Exception, inst:
    40         if repo.ui.debugflag:
    40         if repo.ui.debugflag:
    41             repo.ui.warn(str(inst), '\n')
    41             repo.ui.warn(str(inst), '\n')
    42         partial = branchcache()
    42         partial = branchcache()
    43     return partial
    43     return partial
    44 
       
    45 def write(repo, cache):
       
    46     try:
       
    47         f = repo.opener("cache/branchheads", "w", atomictemp=True)
       
    48         f.write("%s %s\n" % (hex(cache.tipnode), cache.tiprev))
       
    49         for label, nodes in cache.iteritems():
       
    50             for node in nodes:
       
    51                 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
       
    52         f.close()
       
    53     except (IOError, OSError):
       
    54         pass
       
    55 
    44 
    56 def update(repo, partial, ctxgen):
    45 def update(repo, partial, ctxgen):
    57     """Given a branchhead cache, partial, that may have extra nodes or be
    46     """Given a branchhead cache, partial, that may have extra nodes or be
    58     missing heads, and a generator of nodes that are at least a superset of
    47     missing heads, and a generator of nodes that are at least a superset of
    59     heads missing, this function updates partial to be correct.
    48     heads missing, this function updates partial to be correct.
   131     if partial.tiprev < catip:
   120     if partial.tiprev < catip:
   132         ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip))
   121         ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip))
   133         update(repo, partial, ctxgen)
   122         update(repo, partial, ctxgen)
   134         partial.tipnode = cl.node(catip)
   123         partial.tipnode = cl.node(catip)
   135         partial.tiprev = catip
   124         partial.tiprev = catip
   136         write(repo, partial)
   125         partial.write(repo)
   137     # If cacheable tip were lower than actual tip, we need to update the
   126     # If cacheable tip were lower than actual tip, we need to update the
   138     # cache up to tip. This update (from cacheable to actual tip) is not
   127     # cache up to tip. This update (from cacheable to actual tip) is not
   139     # written to disk since it's not cacheable.
   128     # written to disk since it's not cacheable.
   140     tiprev = len(repo) - 1
   129     tiprev = len(repo) - 1
   141     if partial.tiprev < tiprev:
   130     if partial.tiprev < tiprev:
   150 
   139 
   151     def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev):
   140     def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev):
   152         super(branchcache, self).__init__(entries)
   141         super(branchcache, self).__init__(entries)
   153         self.tipnode = tipnode
   142         self.tipnode = tipnode
   154         self.tiprev = tiprev
   143         self.tiprev = tiprev
       
   144 
       
   145     def write(self, repo):
       
   146         try:
       
   147             f = repo.opener("cache/branchheads", "w", atomictemp=True)
       
   148             f.write("%s %s\n" % (hex(self.tipnode), self.tiprev))
       
   149             for label, nodes in self.iteritems():
       
   150                 for node in nodes:
       
   151                     f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
       
   152             f.close()
       
   153         except (IOError, OSError):
       
   154             pass