Patchwork [5,of,8,V2] match: don't use mutable default argument value

login
register
mail settings
Submitter Gregory Szorc
Date March 13, 2017, 4:57 a.m.
Message ID <f72bef9154d773c05fa8.1489381057@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19272/
State Accepted
Headers show

Comments

Gregory Szorc - March 13, 2017, 4:57 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1489380783 25200
#      Sun Mar 12 21:53:03 2017 -0700
# Node ID f72bef9154d773c05fa8b2ae30d7db55861fa639
# Parent  14122c7b97163496df5ac6b98f7c2459259673b9
match: don't use mutable default argument value

There shouldn't be a big perf hit creating a new object because
this function is complicated and does things that dwarf the cost
of creating a new PyObject.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -85,7 +85,7 @@  def _kindpatsalwaysmatch(kindpats):
     return True
 
 class match(object):
-    def __init__(self, root, cwd, patterns, include=[], exclude=[],
+    def __init__(self, root, cwd, patterns, include=None, exclude=None,
                  default='glob', exact=False, auditor=None, ctx=None,
                  listsubrepos=False, warn=None, badfn=None):
         """build an object to match a set of file patterns
@@ -117,6 +117,8 @@  class match(object):
                               the same directory
         '<something>' - a pattern of the specified default type
         """
+        include = include or []
+        exclude = exclude or []
 
         self._root = root
         self._cwd = cwd