From 59deef162dac0bdcd03269489dd5f02a518c2c8d Mon Sep 17 00:00:00 2001 From: Sigurd Spieckermann Date: Fri, 3 May 2024 10:37:00 +0200 Subject: [PATCH] lfs: optimize Unix filename pattern path filtering --- src/scmrepo/git/lfs/fetch.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/scmrepo/git/lfs/fetch.py b/src/scmrepo/git/lfs/fetch.py index bc21a987..b16a39aa 100644 --- a/src/scmrepo/git/lfs/fetch.py +++ b/src/scmrepo/git/lfs/fetch.py @@ -143,16 +143,13 @@ def _collect_objects( def _filter_paths( paths: Iterable[str], include: Optional[list[str]], exclude: Optional[list[str]] ) -> Iterator[str]: - filtered = set() if include: - for pattern in include: - filtered.update(fnmatch.filter(paths, pattern)) - else: - filtered.update(paths) + include_match = re.compile(r"|".join(map(fnmatch.translate, include))).match + paths = (path for path in paths if include_match(path) is not None) if exclude: - for pattern in exclude: - filtered.difference_update(fnmatch.filter(paths, pattern)) - yield from filtered + exclude_match = re.compile(r"|".join(map(fnmatch.translate, exclude))).match + paths = (path for path in paths if exclude_match(path) is None) + yield from paths if __name__ == "__main__":