Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance comparison with pathspec #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions gitignorefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import re

import pathspec


def parse(path, base_path=None):
if base_path is None:
Expand Down Expand Up @@ -41,8 +43,9 @@ def __call__(self, path, is_dir=None):

parent_gitignore = parent.join(".gitignore")
if parent_gitignore.isfile():
matches = parse(str(parent_gitignore), base_path=parent)
add_to_children[parent] = (matches, plain_paths)
with open(str(parent_gitignore)) as f:
matches = pathspec.PathSpec.from_lines("gitwildmatch", f)
add_to_children[parent] = ((matches, parent), plain_paths)
plain_paths = []

else:
Expand Down Expand Up @@ -74,7 +77,7 @@ def __call__(self, path, is_dir=None):
for plain_path in plain_paths:
self.__gitignores[plain_path.parts] = self.__gitignores[parent.parts]

return any((m(path, is_dir=is_dir) for m in self.__gitignores[parent.parts]))
return any((m[0].match_file(path.relpath(m[1])) for m in self.__gitignores[parent.parts]))


class _Path:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pathspec