changeset 27453:8462d7f2c4fe

verify: clean up weird error/warning lists Nested functions in Python are not able to assign to variables in the outer scope without something like the list trick because assignments refer to the inner scope. So, we formerly used a list to give an object to assign into. Now that error and warning are object members, the [0] hack is no longer needed.
author Matt Mackall <mpm@selenic.com>
date Sun, 20 Dec 2015 16:33:44 -0600
parents 5df74b2f296d
children 3e3be524a712
files mercurial/verify.py
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/verify.py	Fri Dec 18 18:52:25 2015 +0000
+++ b/mercurial/verify.py	Sun Dec 20 16:33:44 2015 -0600
@@ -51,8 +51,8 @@
         self.repo = repo.unfiltered()
         self.ui = repo.ui
         self.badrevs = set()
-        self.errors = [0]
-        self.warnings = [0]
+        self.errors = 0
+        self.warnings = 0
         self.havecl = len(repo.changelog) > 0
         self.havemf = len(repo.manifest) > 0
         self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
@@ -62,7 +62,7 @@
 
     def warn(self, msg):
         self.ui.warn(msg + "\n")
-        self.warnings[0] += 1
+        self.warnings += 1
 
     def err(self, linkrev, msg, filename=None):
         if linkrev is not None:
@@ -73,7 +73,7 @@
         if filename:
             msg = "%s@%s" % (filename, msg)
         self.ui.warn(" " + msg + "\n")
-        self.errors[0] += 1
+        self.errors += 1
 
     def exc(self, linkrev, msg, inst, filename=None):
         if not str(inst):
@@ -87,8 +87,6 @@
         filenodes = {}
         revisions = 0
         badrevs = self.badrevs
-        errors = self.errors
-        warnings = self.warnings
         ui = repo.ui
         cl = repo.changelog
         mf = repo.manifest
@@ -352,13 +350,13 @@
 
         ui.status(_("%d files, %d changesets, %d total revisions\n") %
                        (len(files), len(cl), revisions))
-        if warnings[0]:
-            ui.warn(_("%d warnings encountered!\n") % warnings[0])
+        if self.warnings:
+            ui.warn(_("%d warnings encountered!\n") % self.warnings)
         if self.fncachewarned:
             ui.warn(_('hint: run "hg debugrebuildfncache" to recover from '
                       'corrupt fncache\n'))
-        if errors[0]:
-            ui.warn(_("%d integrity errors encountered!\n") % errors[0])
+        if self.errors:
+            ui.warn(_("%d integrity errors encountered!\n") % self.errors)
             if badrevs:
                 ui.warn(_("(first damaged changeset appears to be %d)\n")
                         % min(badrevs))