[PATCH 2 of 2 STABLE-V2] repoview: fix corrupted hiddencache crash Mercurial (issue5042)

Laurent Charignon lcharignon at fb.com
Wed Jan 20 15:49:40 CST 2016


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1453326181 28800
#      Wed Jan 20 13:43:01 2016 -0800
# Branch stable
# Node ID 47533d67ab7839ada87f5236b26effc918e31a5a
# Parent  c04a5869099c46cd8480c65668ee7470f9cdf98b
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,13 @@
                 count = len(data) / 4
                 hidden = frozenset(struct.unpack('>%ii' % count, data))
         return hidden
+    except struct.error:
+        repo.ui.debug('corrupted hidden cache\n')
+        # No need to fix the content as it will get rewritten
+        return None
+    except (IOError, OSError):
+        repo.ui.debug('cannot read hidden cache\n')
+        return None
     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,23 @@
   $ hg amendtransient
   [1, 3]
 
+Check that corrupted hidden cache does not crash
+
+  $ printf "" > .hg/cache/hidden
+  $ hg log -r . -T '{node}' --debug
+  corrupted hidden cache
+  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
+  $ hg log -r . -T '{node}' --debug
+  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
+
+Check that wrong hidden cache permission does not crash
+
+  $ chmod 000 .hg/cache/hidden
+  $ hg log -r . -T '{node}' --debug
+  cannot read hidden cache
+  error writing hidden changesets cache
+  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
+
 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