Commit fa6ffa1d by Abhijit Menon-Sen

Remove & and ! pattern prefixes as early as possible

Now everything under _match_one_pattern can ignore them. This also means
that we can use the cache to return the same results for 'foo' and '!foo'.
parent 704c3815
...@@ -229,10 +229,13 @@ class Inventory(object): ...@@ -229,10 +229,13 @@ class Inventory(object):
def _match_one_pattern(self, pattern): def _match_one_pattern(self, pattern):
""" """
Takes a single pattern (i.e., not "p1:p2") and returns a list of Takes a single pattern (i.e., not "p1:p2") and returns a list of
matching hosts names. Does not take negatives or intersections matching host names. Does not take negatives or intersections
into account. into account.
""" """
if pattern.startswith("&") or pattern.startswith("!"):
pattern = pattern[1:]
if pattern in self._pattern_cache: if pattern in self._pattern_cache:
return self._pattern_cache[pattern] return self._pattern_cache[pattern]
...@@ -308,9 +311,6 @@ class Inventory(object): ...@@ -308,9 +311,6 @@ class Inventory(object):
hosts = [] hosts = []
hostnames = set() hostnames = set()
# ignore any negative checks here, this is handled elsewhere
pattern = pattern.replace("!","").replace("&", "")
def __append_host_to_results(host): def __append_host_to_results(host):
if host.name not in hostnames: if host.name not in hostnames:
hostnames.add(host.name) hostnames.add(host.name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment