Patchwork verify: add a hook that can let extensions manipulate file lists

login
register
mail settings
Submitter Augie Fackler
Date Nov. 4, 2015, 5:14 p.m.
Message ID <9610a8f1fa5b927a3230.1446657273@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/11291/
State Accepted
Headers show

Comments

Augie Fackler - Nov. 4, 2015, 5:14 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1446657258 18000
#      Wed Nov 04 12:14:18 2015 -0500
# Node ID 9610a8f1fa5b927a3230597d39132e7df7a261ca
# Parent  859f453e8b4e2b42b6b6552b79c5c5e7e2fc1cf7
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
Matt Mackall - Nov. 10, 2015, 10:27 p.m.
On Wed, 2015-11-04 at 12:14 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1446657258 18000
> #      Wed Nov 04 12:14:18 2015 -0500
> # Node ID 9610a8f1fa5b927a3230597d39132e7df7a261ca
> # Parent  859f453e8b4e2b42b6b6552b79c5c5e7e2fc1cf7
> verify: add a hook that can let extensions manipulate file lists

Queued for default, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/verify.py b/mercurial/verify.py
--- a/mercurial/verify.py
+++ b/mercurial/verify.py
@@ -35,6 +35,17 @@  def _normpath(f):
         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 @@  def _verify(repo):
                 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 @@  def _verify(repo):
                 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)