changeset 26900:d1c741644d25

verify: add a hook that can let extensions manipulate file lists Without a hook of this nature, narrowhg[0] clones always result in 'hg verify' reporting terrible damage to the entire repository history. With this hook, we can ignore files that aren't supposed to be in the clone, and then get an accurate report of any damage present (or not) in the repo. 0: https://bitbucket.org/Google/narrowhg
author Augie Fackler <augie@google.com>
date Wed, 04 Nov 2015 12:14:18 -0500
parents 5f88e092f82c
children 0e3d093c468e
files mercurial/verify.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/verify.py	Tue Nov 10 17:16:59 2015 -0800
+++ b/mercurial/verify.py	Wed Nov 04 12:14:18 2015 -0500
@@ -35,6 +35,17 @@
         f = f.replace('//', '/')
     return f
 
+def _validpath(repo, path):
+    """Returns False if a path should NOT be treated as part of a repo.
+
+    For all in-core cases, this returns True, as we have no way for a
+    path to be mentioned in the history but not actually be
+    relevant. For narrow clones, this is important because many
+    filelogs will be missing, and changelog entries may mention
+    modified files that are outside the narrow scope.
+    """
+    return True
+
 def _verify(repo):
     repo = repo.unfiltered()
     mflinkrevs = {}
@@ -154,7 +165,8 @@
                 mflinkrevs.setdefault(changes[0], []).append(i)
                 refersmf = True
             for f in changes[3]:
-                filelinkrevs.setdefault(_normpath(f), []).append(i)
+                if _validpath(repo, f):
+                    filelinkrevs.setdefault(_normpath(f), []).append(i)
         except Exception as inst:
             refersmf = True
             exc(i, _("unpacking changeset %s") % short(n), inst)
@@ -181,7 +193,9 @@
                 if not f:
                     err(lr, _("file without name in manifest"))
                 elif f != "/dev/null": # ignore this in very old repos
-                    filenodes.setdefault(_normpath(f), {}).setdefault(fn, lr)
+                    if _validpath(repo, f):
+                        filenodes.setdefault(
+                            _normpath(f), {}).setdefault(fn, lr)
         except Exception as inst:
             exc(lr, _("reading manifest delta %s") % short(n), inst)
     ui.progress(_('checking'), None)