|
6 | 6 | from pathspec.patterns import GitWildMatchPattern
|
7 | 7 |
|
8 | 8 | from dvc.scm.tree import BaseTree
|
9 |
| -from dvc.utils import relpath |
10 | 9 |
|
11 | 10 | logger = logging.getLogger(__name__)
|
12 | 11 |
|
@@ -35,12 +34,19 @@ def __call__(self, root, dirs, files):
|
35 | 34 | return dirs, files
|
36 | 35 |
|
37 | 36 | def matches(self, dirname, basename):
|
38 |
| - abs_path = os.path.join(dirname, basename) |
39 |
| - rel_path = relpath(abs_path, self.dirname) |
40 |
| - |
41 |
| - if os.pardir + os.sep in rel_path: |
| 37 | + # NOTE: `relpath` is too slow, so we have to assume that both |
| 38 | + # `dirname` and `self.dirname` are relative or absolute together. |
| 39 | + prefix = self.dirname + os.sep |
| 40 | + if dirname == self.dirname: |
| 41 | + path = basename |
| 42 | + elif dirname.startswith(prefix): |
| 43 | + rel = dirname[len(prefix) :] |
| 44 | + # NOTE: `os.path.join` is ~x5.5 slower |
| 45 | + path = f"{rel}{os.sep}{basename}" |
| 46 | + else: |
42 | 47 | return False
|
43 |
| - return self.ignore_spec.match_file(rel_path) |
| 48 | + |
| 49 | + return self.ignore_spec.match_file(path) |
44 | 50 |
|
45 | 51 | def __hash__(self):
|
46 | 52 | return hash(self.ignore_file_path)
|
@@ -135,7 +141,9 @@ def isexec(self, path):
|
135 | 141 |
|
136 | 142 | def walk(self, top, topdown=True):
|
137 | 143 | for root, dirs, files in self.tree.walk(top, topdown):
|
138 |
| - dirs[:], files[:] = self.dvcignore(root, dirs, files) |
| 144 | + dirs[:], files[:] = self.dvcignore( |
| 145 | + os.path.abspath(root), dirs, files |
| 146 | + ) |
139 | 147 |
|
140 | 148 | yield root, dirs, files
|
141 | 149 |
|
|
0 commit comments