changeset 2402:b33bc2f37e89

obscache: have the obsstore fix empty file cachekey Before this change, the missing file and empty file returned different value.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 02 May 2017 16:10:14 +0200
parents a786240c95bd
children 0d2e0e8e76f6
files hgext3rd/evolve/obscache.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obscache.py
+++ b/hgext3rd/evolve/obscache.py
@@ -56,6 +56,10 @@
 
             If the index specified is higher than the current obsstore file
             length, cachekey will be set to None."""
+            # default value
+            obsstoresize = 0
+            keydata = ''
+            # try to get actual data from the obsstore
             try:
                 with self.svfs('obsstore') as obsfile:
                     obsfile.seek(0, 2)
@@ -65,13 +69,14 @@
                     elif obsstoresize < index:
                         return obsstoresize, None
                     actualsize = min(index, self._obskeysize)
-                    obsfile.seek(index - actualsize, 0)
-                    keydata = obsfile.read(actualsize)
-                return obsstoresize, hashlib.sha1(keydata).digest()
+                    if actualsize:
+                        obsfile.seek(index - actualsize, 0)
+                        keydata = obsfile.read(actualsize)
             except (OSError, IOError) as e:
                 if e.errno != errno.ENOENT:
                     raise
-                return 0, node.nullid
+            key = hashlib.sha1(keydata).digest()
+            return obsstoresize, key
 
     obsstore.__class__ = cachekeyobsstore