Patchwork [1,of,7] verify: move checklog() onto class

login
register
mail settings
Submitter Durham Goode
Date Jan. 6, 2016, 2:44 a.m.
Message ID <0886e38814dbc6f30510.1452048285@dev8486.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12548/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Durham Goode - Jan. 6, 2016, 2:44 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1452042494 28800
#      Tue Jan 05 17:08:14 2016 -0800
# Node ID 0886e38814dbc6f305102fa89203ee4d53b0874d
# Parent  b8405d739149cdd6d8d9bd5e3dd2ad8487b1f09a
verify: move checklog() onto class

This is part of an effort to make verify more modular so extensions can hook
into it.
Durham Goode - Jan. 6, 2016, 2:49 a.m.
On 1/5/16 6:44 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1452042494 28800
> #      Tue Jan 05 17:08:14 2016 -0800
> # Node ID 0886e38814dbc6f305102fa89203ee4d53b0874d
> # Parent  b8405d739149cdd6d8d9bd5e3dd2ad8487b1f09a
> verify: move checklog() onto class
>
> This is part of an effort to make verify more modular so extensions can hook
> into it.
>
This is the second (and final) series in my refactor of verify to be 
inside a class.  It makes verify more extensible for extensions to hook 
in to.

Patch

diff --git a/mercurial/verify.py b/mercurial/verify.py
--- a/mercurial/verify.py
+++ b/mercurial/verify.py
@@ -80,6 +80,23 @@  class verifier(object):
             inst = repr(inst)
         self.err(linkrev, "%s: %s" % (msg, inst), filename)
 
+    def checklog(self, obj, name, linkrev):
+        if not len(obj) and (self.havecl or self.havemf):
+            self.err(linkrev, _("empty or missing %s") % name)
+            return
+
+        d = obj.checksize()
+        if d[0]:
+            self.err(None, _("data length off by %d bytes") % d[0], name)
+        if d[1]:
+            self.err(None, _("index contains %d extra bytes") % d[1], name)
+
+        if obj.version != revlog.REVLOGV0:
+            if not self.revlogv1:
+                self.warn(_("warning: `%s' uses revlog format 1") % name)
+        elif self.revlogv1:
+            self.warn(_("warning: `%s' uses revlog format 0") % name)
+
     def verify(self):
         repo = self.repo
         mflinkrevs = {}
@@ -95,23 +112,6 @@  class verifier(object):
         if not repo.url().startswith('file:'):
             raise error.Abort(_("cannot verify bundle or remote repos"))
 
-        def checklog(obj, name, linkrev):
-            if not len(obj) and (havecl or havemf):
-                self.err(linkrev, _("empty or missing %s") % name)
-                return
-
-            d = obj.checksize()
-            if d[0]:
-                self.err(None, _("data length off by %d bytes") % d[0], name)
-            if d[1]:
-                self.err(None, _("index contains %d extra bytes") % d[1], name)
-
-            if obj.version != revlog.REVLOGV0:
-                if not revlogv1:
-                    self.warn(_("warning: `%s' uses revlog format 1") % name)
-            elif revlogv1:
-                self.warn(_("warning: `%s' uses revlog format 0") % name)
-
         def checkentry(obj, i, node, seen, linkrevs, f):
             lr = obj.linkrev(obj.rev(node))
             if lr < 0 or (havecl and lr not in linkrevs):
@@ -162,7 +162,7 @@  class verifier(object):
 
         ui.status(_("checking changesets\n"))
         seen = {}
-        checklog(cl, "changelog", 0)
+        self.checklog(cl, "changelog", 0)
         total = len(repo)
         for i in repo:
             ui.progress(_('checking'), i, total=total, unit=_('changesets'))
@@ -187,7 +187,7 @@  class verifier(object):
         if self.refersmf:
             # Do not check manifest if there are only changelog entries with
             # null manifests.
-            checklog(mf, "manifest", 0)
+            self.checklog(mf, "manifest", 0)
         total = len(mf)
         for i in mf:
             ui.progress(_('checking'), i, total=total, unit=_('manifests'))
@@ -283,7 +283,7 @@  class verifier(object):
                     self.warn(_(" warning: revlog '%s' not in fncache!") % ff)
                     self.fncachewarned = True
 
-            checklog(fl, f, lr)
+            self.checklog(fl, f, lr)
             seen = {}
             rp = None
             for i in fl: