[PATCH STABLE] repoview: fix corrupted hiddencache crash Mercurial (issue5042)

Laurent Charignon lcharignon at fb.com
Wed Jan 20 18:09:27 UTC 2016


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1453313317 28800
#      Wed Jan 20 10:08:37 2016 -0800
# Branch stable
# Node ID 688f61fa0e0a8cc9139a533cb3fe6cb411b1dc8f
# Parent  3203dfe341f962e33256d6475fc3585563db78ad
repoview: fix corrupted hiddencache crash Mercurial (issue5042)

Before this patch if the hiddencache existed but was empty, it would crash
mercurial. This patch adds exception handling when reading the hiddencache to
avoid the issue.
When encountering a corrupted cache file we print a devel warning. There would
be no point in issuing a normal warning as the user wouldn't be able to do
anything about the situation.

The warning looks like:

devel-warn: corrupted hidden cache, removing it at: /path/to/repoview.py

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -150,6 +150,12 @@
                 count = len(data) / 4
                 hidden = frozenset(struct.unpack('>%ii' % count, data))
         return hidden
+    except struct.error:
+        repo.ui.develwarn('corrupted hidden cache, removing it')
+        if fh:
+            fh.close()
+        repo.vfs.unlink(cachefile)
+        return hidden
     finally:
         if fh:
             fh.close()
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -951,6 +951,11 @@
   $ hg amendtransient
   [1, 3]
 
+Check that corrupted hidden cache does not crash hg
+  $ printf "" > .hg/cache/hidden
+  $ hg status
+  devel-warn: corrupted hidden cache, removing it at: * (glob)
+
 Test cache consistency for the visible filter
 1) We want to make sure that the cached filtered revs are invalidated when
 bookmarks change


More information about the Mercurial-devel mailing list