Nataneljpwd commented on code in PR #56509:
URL: https://github.com/apache/airflow/pull/56509#discussion_r2423340338
##########
airflow-core/src/airflow/utils/file.py:
##########
@@ -102,24 +102,21 @@ def compile(pattern: str, base_dir: Path,
definition_file: Path) -> _IgnoreRule
relative_to = definition_file.parent
ignore_pattern = GitWildMatchPattern(pattern)
- return _GlobIgnoreRule(ignore_pattern, relative_to)
+ return _GlobIgnoreRule(wild_match_pattern=ignore_pattern,
relative_to=relative_to)
@staticmethod
def match(path: Path, rules: list[_IgnoreRule]) -> bool:
- """Match a list of ignore rules against the supplied path."""
+ """Match a list of ignore rules against the supplied path, accounting
for exclusion rules and ordering."""
matched = False
- for r in rules:
- if not isinstance(r, _GlobIgnoreRule):
- raise ValueError(f"_GlobIgnoreRule cannot match rules of type:
{type(r)}")
- rule: _GlobIgnoreRule = r # explicit typing to make mypy play
nicely
+ for rule in rules:
+ if not isinstance(rule, _GlobIgnoreRule):
+ raise ValueError(f"_GlobIgnoreRule cannot match rules of type:
{type(rule)}")
rel_path = str(path.relative_to(rule.relative_to) if
rule.relative_to else path.name)
- matched = rule.wild_match_pattern.match_file(rel_path) is not None
-
- if matched:
- if not rule.wild_match_pattern.include:
- return False
-
- return matched
+ if (
+ rule.wild_match_pattern.include is not None
+ and rule.wild_match_pattern.match_file(rel_path) is not None
+ ):
+ matched = rule.wild_match_pattern.include
return matched
Review Comment:
I am not sure that the reversed would work, as per the pathspec:
> An optional prefix "!" which negates the pattern; **any matching file
excluded by a previous pattern will become included again. It is not possible
to re-include a file if a parent directory of that file is excluded**. Git
doesn’t list excluded directories for performance reasons, so any patterns on
contained files have no effect, no matter where they are defined. Put a
backslash ("\") in front of the first "!" for patterns that begin with a
literal "!", for example, "\!important!.txt".
That means that if a directory was ignored first, but will be included, I am
pretty sure it works by git pathspec now, I will take a closer look and examine
it again, the behaviour is complex but I looked at git's implantation and it
seems to match
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]