Patchwork [2,of,7] revset: define "pat" variable unconditionally in subrepo()

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2016, 2:38 p.m.
Message ID <fe9925d9c774eec6d1cc.1456583896@mimosa>
Download mbox | patch
Permalink /patch/13431/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Yuya Nishihara - Feb. 27, 2016, 2:38 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455362025 -32400
#      Sat Feb 13 20:13:45 2016 +0900
# Node ID fe9925d9c774eec6d1ccaeddc05dc287b572ef6e
# Parent  4c869f64c013866cdf49278ffcff981e9074201d
revset: define "pat" variable unconditionally in subrepo()

It's a source of UnboundLocalError to define and use local variables
conditionally. As getstring() always returns a str, "pat" can be initialized
to None.
Pierre-Yves David - Feb. 27, 2016, 3:47 p.m.
On 02/27/2016 03:38 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1455362025 -32400
> #      Sat Feb 13 20:13:45 2016 +0900
> # Node ID fe9925d9c774eec6d1ccaeddc05dc287b572ef6e
> # Parent  4c869f64c013866cdf49278ffcff981e9074201d
> revset: define "pat" variable unconditionally in subrepo()

I've pushed patches 1,2 to the clowncopter. thanks

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1982,6 +1982,7 @@  def subrepo(repo, subset, x):
     """
     # i18n: "subrepo" is a keyword
     args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
+    pat = None
     if len(args) != 0:
         pat = getstring(args[0], _("subrepo requires a pattern"))
 
@@ -1997,7 +1998,7 @@  def subrepo(repo, subset, x):
         c = repo[x]
         s = repo.status(c.p1().node(), c.node(), match=m)
 
-        if len(args) == 0:
+        if pat is None:
             return s.added or s.modified or s.removed
 
         if s.added: