changeset 34875:4f0d4bc63b8a

configitems: document the choice of using 'match' instead of 'search'
author Boris Feld <boris.feld@octobus.net>
date Wed, 18 Oct 2017 12:36:23 +0200
parents e3fbf8e3fef2
children eb1b964b354b
files mercurial/configitems.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.py	Wed Oct 18 12:26:08 2017 +0200
+++ b/mercurial/configitems.py	Wed Oct 18 12:36:23 2017 +0200
@@ -74,6 +74,17 @@
         # search for a matching generic item
         generics = sorted(self._generics, key=(lambda x: (x.priority, x.name)))
         for item in generics:
+            # we use 'match' instead of 'search' to make the matching simpler
+            # for people unfamiliar with regular expression. Having the match
+            # rooted to the start of the string will produce less surprising
+            # result for user writing simple regex for sub-attribute.
+            #
+            # For example using "color\..*" match produces an unsurprising
+            # result, while using search could suddenly match apparently
+            # unrelated configuration that happens to contains "color."
+            # anywhere. This is a tradeoff where we favor requiring ".*" on
+            # some match to avoid the need to prefix most pattern with "^".
+            # The "^" seems more error prone.
             if item._re.match(key):
                 return item