Skip to content

Commit e5e116d

Browse files
authored
Improve performance for negation rules
Thank you @ruancomelli for the PR!
1 parent b925eba commit e5e116d

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

gitignore_parser.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44

55
from os.path import dirname
66
from pathlib import Path
7-
from typing import Union
7+
from typing import Reversible, Union
88

9-
def handle_negation(file_path, rules):
10-
matched = False
11-
for rule in rules:
9+
def handle_negation(file_path, rules: Reversible["IgnoreRule"]):
10+
for rule in reversed(rules):
1211
if rule.match(file_path):
13-
if rule.negation:
14-
matched = False
15-
else:
16-
matched = True
17-
return matched
12+
return not rule.negation
13+
return False
1814

1915
def parse_gitignore(full_path, base_dir=None):
2016
if base_dir is None:

0 commit comments

Comments
 (0)