verify: move err() to be a class function
authorDurham Goode <durham@fb.com>
Fri, 18 Dec 2015 16:42:39 -0800
changeset 27447 d1b91c10ce70
parent 27446 6b2c1a1871a6
child 27448 f4f2179077cb
verify: move err() to be a class function This is part of an effort to make it easier for extensions to hook into verify.
mercurial/verify.py
--- a/mercurial/verify.py	Fri Dec 18 16:42:39 2015 -0800
+++ b/mercurial/verify.py	Fri Dec 18 16:42:39 2015 -0800
@@ -64,6 +64,17 @@
         self.ui.warn(msg + "\n")
         self.warnings[0] += 1
 
+    def err(self, linkrev, msg, filename=None):
+        if linkrev is not None:
+            self.badrevs.add(linkrev)
+        else:
+            linkrev = '?'
+        msg = "%s: %s" % (linkrev, msg)
+        if filename:
+            msg = "%s@%s" % (filename, msg)
+        self.ui.warn(" " + msg + "\n")
+        self.errors[0] += 1
+
     def verify(self):
         repo = self.repo
         mflinkrevs = {}
@@ -81,16 +92,6 @@
         if not repo.url().startswith('file:'):
             raise error.Abort(_("cannot verify bundle or remote repos"))
 
-        def err(linkrev, msg, filename=None):
-            if linkrev is not None:
-                badrevs.add(linkrev)
-            else:
-                linkrev = '?'
-            msg = "%s: %s" % (linkrev, msg)
-            if filename:
-                msg = "%s@%s" % (filename, msg)
-            ui.warn(" " + msg + "\n")
-            errors[0] += 1
 
         def exc(linkrev, msg, inst, filename=None):
             if isinstance(inst, KeyboardInterrupt):
@@ -98,19 +99,19 @@
                 raise
             if not str(inst):
                 inst = repr(inst)
-            err(linkrev, "%s: %s" % (msg, inst), filename)
+            self.err(linkrev, "%s: %s" % (msg, inst), filename)
 
 
         def checklog(obj, name, linkrev):
             if not len(obj) and (havecl or havemf):
-                err(linkrev, _("empty or missing %s") % name)
+                self.err(linkrev, _("empty or missing %s") % name)
                 return
 
             d = obj.checksize()
             if d[0]:
-                err(None, _("data length off by %d bytes") % d[0], name)
+                self.err(None, _("data length off by %d bytes") % d[0], name)
             if d[1]:
-                err(None, _("index contains %d extra bytes") % d[1], name)
+                self.err(None, _("index contains %d extra bytes") % d[1], name)
 
             if obj.version != revlog.REVLOGV0:
                 if not revlogv1:
@@ -125,7 +126,7 @@
                     msg = _("rev %d points to nonexistent changeset %d")
                 else:
                     msg = _("rev %d points to unexpected changeset %d")
-                err(None, msg % (i, lr), f)
+                self.err(None, msg % (i, lr), f)
                 if linkrevs:
                     if f and len(linkrevs) > 1:
                         try:
@@ -141,16 +142,17 @@
             try:
                 p1, p2 = obj.parents(node)
                 if p1 not in seen and p1 != nullid:
-                    err(lr, _("unknown parent 1 %s of %s") %
-                        (short(p1), short(node)), f)
+                    self.err(lr, _("unknown parent 1 %s of %s") %
+                             (short(p1), short(node)), f)
                 if p2 not in seen and p2 != nullid:
-                    err(lr, _("unknown parent 2 %s of %s") %
-                        (short(p2), short(node)), f)
+                    self.err(lr, _("unknown parent 2 %s of %s") %
+                             (short(p2), short(node)), f)
             except Exception as inst:
                 exc(lr, _("checking parents of %s") % short(node), inst, f)
 
             if node in seen:
-                err(lr, _("duplicate revision %d (%d)") % (i, seen[node]), f)
+                self.err(lr, _("duplicate revision %d (%d)") %
+                         (i, seen[node]), f)
             seen[node] = i
             return lr
 
@@ -201,12 +203,12 @@
             if n in mflinkrevs:
                 del mflinkrevs[n]
             else:
-                err(lr, _("%s not in changesets") % short(n), "manifest")
+                self.err(lr, _("%s not in changesets") % short(n), "manifest")
 
             try:
                 for f, fn in mf.readdelta(n).iteritems():
                     if not f:
-                        err(lr, _("file without name in manifest"))
+                        self.err(lr, _("file without name in manifest"))
                     elif f != "/dev/null": # ignore this in very old repos
                         if _validpath(repo, f):
                             filenodes.setdefault(
@@ -226,7 +228,8 @@
                 if m == nullid:
                     continue
                 ui.progress(_('crosschecking'), count, total=total)
-                err(c, _("changeset refers to unknown manifest %s") % short(m))
+                self.err(c, _("changeset refers to unknown manifest %s") %
+                         short(m))
             mflinkrevs = None # del is bad here due to scope issues
 
             for f in sorted(filelinkrevs):
@@ -234,7 +237,7 @@
                 ui.progress(_('crosschecking'), count, total=total)
                 if f not in filenodes:
                     lr = filelinkrevs[f][0]
-                    err(lr, _("in changeset but not in manifest"), f)
+                    self.err(lr, _("in changeset but not in manifest"), f)
 
         if havecl:
             for f in sorted(filenodes):
@@ -246,7 +249,7 @@
                         lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]])
                     except Exception:
                         lr = None
-                    err(lr, _("in manifest but not in changeset"), f)
+                    self.err(lr, _("in manifest but not in changeset"), f)
 
         ui.progress(_('crosschecking'), None)
 
@@ -255,7 +258,7 @@
         storefiles = set()
         for f, f2, size in repo.store.datafiles():
             if not f:
-                err(None, _("cannot decode filename '%s'") % f2)
+                self.err(None, _("cannot decode filename '%s'") % f2)
             elif size > 0 or not revlogv1:
                 storefiles.add(_normpath(f))
 
@@ -277,7 +280,7 @@
             try:
                 fl = repo.file(f)
             except error.RevlogError as e:
-                err(lr, _("broken revlog! (%s)") % e, f)
+                self.err(lr, _("broken revlog! (%s)") % e, f)
                 continue
 
             for ff in fl.files():
@@ -296,7 +299,7 @@
                 lr = checkentry(fl, i, n, seen, linkrevs, f)
                 if f in filenodes:
                     if havemf and n not in filenodes[f]:
-                        err(lr, _("%s not in manifests") % (short(n)), f)
+                        self.err(lr, _("%s not in manifests") % (short(n)), f)
                     else:
                         del filenodes[f][n]
 
@@ -306,12 +309,12 @@
                     rp = fl.renamed(n)
                     if l != fl.size(i):
                         if len(fl.revision(n)) != fl.size(i):
-                            err(lr, _("unpacked size is %s, %s expected") %
-                                (l, fl.size(i)), f)
+                            self.err(lr, _("unpacked size is %s, %s expected") %
+                                     (l, fl.size(i)), f)
                 except error.CensoredNodeError:
                     # experimental config: censor.policy
                     if ui.config("censor", "policy", "abort") == "abort":
-                        err(lr, _("censored file data"), f)
+                        self.err(lr, _("censored file data"), f)
                 except Exception as inst:
                     exc(lr, _("unpacking %s") % short(n), inst, f)
 
@@ -330,8 +333,8 @@
                                             " in parents of %s") % (f, ctx))
                         fl2 = repo.file(rp[0])
                         if not len(fl2):
-                            err(lr, _("empty or missing copy source revlog "
-                                      "%s:%s") % (rp[0], short(rp[1])), f)
+                            self.err(lr, _("empty or missing copy source "
+                                     "revlog %s:%s") % (rp[0], short(rp[1])), f)
                         elif rp[1] == nullid:
                             ui.note(_("warning: %s@%s: copy source"
                                       " revision is nullid %s:%s\n")
@@ -345,7 +348,8 @@
             if f in filenodes:
                 fns = [(lr, n) for n, lr in filenodes[f].iteritems()]
                 for lr, node in sorted(fns):
-                    err(lr, _("%s in manifests not found") % short(node), f)
+                    self.err(lr, _("%s in manifests not found") % short(node),
+                             f)
         ui.progress(_('checking'), None)
 
         for f in storefiles: