Patchwork [01,of,18,V2] branchmap: read return None in case of failure

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 4, 2013, 1:04 a.m.
Message ID <584a4a3d20906768dbb3.1357261444@yamac.lan>
Download mbox | patch
Permalink /patch/370/
State Accepted
Commit 493778b5fe9f98088af708c948f5f5ee73d8fc61
Headers show

Comments

Pierre-Yves David - Jan. 4, 2013, 1:04 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1356201671 -3600
# Node ID 584a4a3d20906768dbb3fc57f77cbfc0a41bc75e
# Parent  2c1276825e938872ebc099c191eb202f0dbadfcc
branchmap: read return None in case of failure

This makes a clear distinction between having read a valid cache on disk or not.
This will help caches of various filtering level to collaborate.

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -20,11 +20,11 @@  def read(repo):
     try:
         f = repo.opener(_filename(repo))
         lines = f.read().split('\n')
         f.close()
     except (IOError, OSError):
-        return branchcache()
+        return None
 
     try:
         cachekey = lines.pop(0).split(" ", 2)
         last, lrev = cachekey[:2]
         last, lrev = bin(last), int(lrev)
@@ -51,11 +51,11 @@  def read(repo):
             msg = 'invalid branchheads cache'
             if repo.filtername is not None:
                 msg += ' (%s)' % repo.filtername
             msg += ': %s\n'
             repo.ui.warn(msg % inst)
-        partial = branchcache()
+        partial = None
     return partial
 
 
 
 def updatecache(repo):
@@ -63,10 +63,12 @@  def updatecache(repo):
     filtername = repo.filtername
     partial = repo._branchcaches.get(filtername)
 
     if partial is None or not partial.validfor(repo):
         partial = read(repo)
+        if partial is None:
+            partial = branchcache()
 
     catip = repo._cacheabletip()
     # if partial.tiprev == catip: cache is already up to date
     # if partial.tiprev >  catip: we have uncachable element in `partial` can't
     #                             write on disk