Patchwork verify: clean up weird error/warning lists

login
register
mail settings
Submitter Matt Mackall
Date Dec. 20, 2015, 11:04 p.m.
Message ID <687b00ef22dd75f9539b.1450652695@ruin.waste.org>
Download mbox | patch
Permalink /patch/12189/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Matt Mackall - Dec. 20, 2015, 11:04 p.m.
# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 1450650824 21600
#      Sun Dec 20 16:33:44 2015 -0600
# Node ID 687b00ef22dd75f9539b13e2a6441135d4d34836
# Parent  f4f2179077cbec6908e9f7afc72a947e769185ba
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.
Yuya Nishihara - Dec. 21, 2015, 2:32 p.m.
On Sun, 20 Dec 2015 17:04:55 -0600, Matt Mackall wrote:
> # HG changeset patch
> # User Matt Mackall <mpm@selenic.com>
> # Date 1450650824 21600
> #      Sun Dec 20 16:33:44 2015 -0600
> # Node ID 687b00ef22dd75f9539b13e2a6441135d4d34836
> # Parent  f4f2179077cbec6908e9f7afc72a947e769185ba
> 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.

> -        if warnings[0]:
> -            ui.warn(_("%d warnings encountered!\n") % warnings[0])
> +        if self.warnings:
> +            ui.warn(_("%d warnings encountered!\n") % 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") % errors)

Good catch. Fixed these undefined references and pushed to the clowncopter,
thanks. Hopes this won't heavily conflict with Durham's upcoming series.

Patch

diff -r f4f2179077cb -r 687b00ef22dd mercurial/verify.py
--- a/mercurial/verify.py	Fri Dec 18 16:42:39 2015 -0800
+++ 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 isinstance(inst, KeyboardInterrupt):
@@ -90,8 +90,6 @@ 
         filenodes = {}
         revisions = 0
         badrevs = self.badrevs
-        errors = self.errors
-        warnings = self.warnings
         ui = repo.ui
         cl = repo.changelog
         mf = repo.manifest
@@ -355,13 +353,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") % 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") % errors)
             if badrevs:
                 ui.warn(_("(first damaged changeset appears to be %d)\n")
                         % min(badrevs))