Mercurial > hg
comparison mercurial/configitems.py @ 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 | 8c9b08a0c48c |
comparison
equal
deleted
inserted
replaced
34874:e3fbf8e3fef2 | 34875:4f0d4bc63b8a |
---|---|
72 return baseitem | 72 return baseitem |
73 | 73 |
74 # search for a matching generic item | 74 # search for a matching generic item |
75 generics = sorted(self._generics, key=(lambda x: (x.priority, x.name))) | 75 generics = sorted(self._generics, key=(lambda x: (x.priority, x.name))) |
76 for item in generics: | 76 for item in generics: |
77 # we use 'match' instead of 'search' to make the matching simpler | |
78 # for people unfamiliar with regular expression. Having the match | |
79 # rooted to the start of the string will produce less surprising | |
80 # result for user writing simple regex for sub-attribute. | |
81 # | |
82 # For example using "color\..*" match produces an unsurprising | |
83 # result, while using search could suddenly match apparently | |
84 # unrelated configuration that happens to contains "color." | |
85 # anywhere. This is a tradeoff where we favor requiring ".*" on | |
86 # some match to avoid the need to prefix most pattern with "^". | |
87 # The "^" seems more error prone. | |
77 if item._re.match(key): | 88 if item._re.match(key): |
78 return item | 89 return item |
79 | 90 |
80 return None | 91 return None |
81 | 92 |