Patchwork D6722: fncache: make debugrebuildfncache not fail on broken fncache

login
register
mail settings
Submitter phabricator
Date Aug. 12, 2019, 9:23 p.m.
Message ID <86885015eae37b1c142d82b81ae77e6b@localhost.localdomain>
Download mbox | patch
Permalink /patch/41252/
State Not Applicable
Headers show

Comments

phabricator - Aug. 12, 2019, 9:23 p.m.
Closed by commit rHGf59f8a5e9096: fncache: make debugrebuildfncache not fail on broken fncache (authored by valentin.gatienbaron).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6722?vs=16175&id=16177

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6722/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6722

AFFECTED FILES
  mercurial/repair.py
  mercurial/store.py
  tests/test-fncache.t

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers, pulkit
Cc: pulkit, mjpieters, mercurial-devel

Patch

diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -435,16 +435,18 @@ 
   data/.bar.i
   data/foo.i
 
-debugrebuildfncache fails to recover from truncated line in fncache
+debugrebuildfncache recovers from truncated line in fncache
 
   $ printf a > .hg/store/fncache
   $ hg debugrebuildfncache
-  abort: fncache does not ends with a newline
-  (use 'hg debugrebuildfncache' to rebuild the fncache)
-  [255]
+  fncache does not ends with a newline
+  adding data/.bar.i
+  adding data/foo.i
+  2 items added, 0 removed from fncache
 
   $ cat .hg/store/fncache | sort
-  a
+  data/.bar.i
+  data/foo.i
 
   $ cd ..
 
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -458,7 +458,15 @@ 
         # set of new additions to fncache
         self.addls = set()
 
-    def _load(self):
+    def ensureloaded(self, warn=None):
+        '''read the fncache file if not already read.
+
+        If the file on disk is corrupted, raise. If warn is provided,
+        warn and keep going instead.'''
+        if self.entries is None:
+            self._load(warn)
+
+    def _load(self, warn=None):
         '''fill the entries from the fncache file'''
         self._dirty = False
         try:
@@ -482,20 +490,27 @@ 
                 pass
 
         if chunk:
-            raise error.Abort(_("fncache does not ends with a newline"),
-                              hint=_("use 'hg debugrebuildfncache' to rebuild"
-                                     " the fncache"))
-        self._checkentries(fp)
+            msg = _("fncache does not ends with a newline")
+            if warn:
+                warn(msg + '\n')
+            else:
+                raise error.Abort(msg,
+                                  hint=_("use 'hg debugrebuildfncache' to "
+                                         "rebuild the fncache"))
+        self._checkentries(fp, warn)
         fp.close()
 
-    def _checkentries(self, fp):
+    def _checkentries(self, fp, warn):
         """ make sure there is no empty string in entries """
         if '' in self.entries:
             fp.seek(0)
             for n, line in enumerate(util.iterfile(fp)):
                 if not line.rstrip('\n'):
                     t = _('invalid entry in fncache, line %d') % (n + 1)
-                    raise error.Abort(t)
+                    if warn:
+                        warn(t + '\n')
+                    else:
+                        raise error.Abort(t)
 
     def write(self, tr):
         if self._dirty:
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -392,9 +392,7 @@ 
 
     with repo.lock():
         fnc = repo.store.fncache
-        # Trigger load of fncache.
-        if 'irrelevant' in fnc:
-            pass
+        fnc.ensureloaded(warn=ui.warn)
 
         oldentries = set(fnc.entries)
         newentries = set()