From patchwork Thu Mar 16 11:28:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [8,of,8] context: explicitly tests for None From: Pierre-Yves David X-Patchwork-Id: 19389 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 16 Mar 2017 04:28:12 -0700 # HG changeset patch # User Pierre-Yves David # Date 1489617204 25200 # Wed Mar 15 15:33:24 2017 -0700 # Node ID d912b21f4721d399fd327b6bb7179de7e2a614b6 # Parent 414372f08c44186c8dad9dea46d617ab61412503 # EXP-Topic mutable-default # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ # hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r d912b21f4721 context: explicitly tests for None Changeset 9e57033fec0c removed the mutable default value, but did not explicitly tested for None. Such implicit testing can introduce semantic and performance issue. We move to an explicit testing for None as recommended by PEP8: https://www.python.org/dev/peps/pep-0008/#programming-recommendations diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -300,8 +300,10 @@ class basectx(object): def match(self, pats=None, include=None, exclude=None, default='glob', listsubrepos=False, badfn=None): + if pats is None: + pats = [] r = self._repo - return matchmod.match(r.root, r.getcwd(), pats or [], + return matchmod.match(r.root, r.getcwd(), pats, include, exclude, default, auditor=r.nofsauditor, ctx=self, listsubrepos=listsubrepos, badfn=badfn) @@ -1517,16 +1519,18 @@ class workingctx(committablectx): def match(self, pats=None, include=None, exclude=None, default='glob', listsubrepos=False, badfn=None): + if pats is None: + pats = [] r = self._repo # Only a case insensitive filesystem needs magic to translate user input # to actual case in the filesystem. if not util.fscasesensitive(r.root): - return matchmod.icasefsmatcher(r.root, r.getcwd(), pats or [], + return matchmod.icasefsmatcher(r.root, r.getcwd(), pats, include, exclude, default, r.auditor, self, listsubrepos=listsubrepos, badfn=badfn) - return matchmod.match(r.root, r.getcwd(), pats or [], + return matchmod.match(r.root, r.getcwd(), pats, include, exclude, default, auditor=r.auditor, ctx=self, listsubrepos=listsubrepos, badfn=badfn)