Skip to content

Commit

Permalink
Improve performance for negation rules
Browse files Browse the repository at this point in the history
Thank you @ruancomelli for the PR!
  • Loading branch information
ruancomelli committed Aug 3, 2023
1 parent b925eba commit e5e116d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions gitignore_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

from os.path import dirname
from pathlib import Path
from typing import Union
from typing import Reversible, Union

def handle_negation(file_path, rules):
matched = False
for rule in rules:
def handle_negation(file_path, rules: Reversible["IgnoreRule"]):
for rule in reversed(rules):
if rule.match(file_path):
if rule.negation:
matched = False
else:
matched = True
return matched
return not rule.negation
return False

def parse_gitignore(full_path, base_dir=None):
if base_dir is None:
Expand Down

0 comments on commit e5e116d

Please sign in to comment.