Patchwork [1,of,6] revset: narrow scope of the variable referred only in specific code path

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 17, 2014, 2:57 p.m.
Message ID <d601202366e79f2ede92.1389970623@juju>
Download mbox | patch
Permalink /patch/3370/
State Accepted
Commit 189fe1b3d16ae0035424cedce46a5b7b542644ba
Headers show

Comments

Katsunori FUJIWARA - Jan. 17, 2014, 2:57 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1389969732 -32400
#      Fri Jan 17 23:42:12 2014 +0900
# Node ID d601202366e79f2ede928d66b75055e01a105e29
# Parent  6545770bd37991b4ff0400479455a6e3ffa5976b
revset: narrow scope of the variable referred only in specific code path

This patch narrows scope of the variable "m" in the function for
revset predicate "contains()", because it is referred only in "else"
code path of "if not matchmod.patkind(pat)" examination.
Matt Mackall - Jan. 17, 2014, 11:05 p.m.
On Fri, 2014-01-17 at 23:57 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1389969732 -32400
> #      Fri Jan 17 23:42:12 2014 +0900
> # Node ID d601202366e79f2ede928d66b75055e01a105e29
> # Parent  6545770bd37991b4ff0400479455a6e3ffa5976b
> revset: narrow scope of the variable referred only in specific code path

This one is queued for default, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -528,13 +528,13 @@ 
     """
     # i18n: "contains" is a keyword
     pat = getstring(x, _("contains requires a pattern"))
-    m = None
     s = []
     if not matchmod.patkind(pat):
         for r in subset:
             if pat in repo[r]:
                 s.append(r)
     else:
+        m = None
         for r in subset:
             c = repo[r]
             if not m or matchmod.patkind(pat) == 'set':