1
1
import logging
2
2
import os
3
+ import re
4
+ from itertools import groupby
3
5
4
6
from funcy import cached_property
5
- from pathspec import PathSpec
6
7
from pathspec .patterns import GitWildMatchPattern
8
+ from pathspec .util import normalize_file
7
9
8
10
from dvc .path_info import PathInfo
9
11
from dvc .scm .tree import BaseTree
12
+ from dvc .system import System
10
13
from dvc .utils import relpath
11
14
12
15
logger = logging .getLogger (__name__ )
@@ -27,7 +30,16 @@ def __init__(self, ignore_file_path, tree):
27
30
self .dirname = os .path .normpath (os .path .dirname (ignore_file_path ))
28
31
29
32
with tree .open (ignore_file_path , encoding = "utf-8" ) as fobj :
30
- self .ignore_spec = PathSpec .from_lines (GitWildMatchPattern , fobj )
33
+ path_spec_lines = fobj .readlines ()
34
+ regex_pattern_list = map (
35
+ GitWildMatchPattern .pattern_to_regex , path_spec_lines
36
+ )
37
+ self .ignore_spec = [
38
+ (ignore , re .compile ("|" .join (item [0 ] for item in group )))
39
+ for ignore , group in groupby (
40
+ regex_pattern_list , lambda x : x [1 ]
41
+ )
42
+ ]
31
43
32
44
def __call__ (self , root , dirs , files ):
33
45
files = [f for f in files if not self .matches (root , f )]
@@ -48,7 +60,16 @@ def matches(self, dirname, basename):
48
60
else :
49
61
return False
50
62
51
- return self .ignore_spec .match_file (path )
63
+ if not System .is_unix ():
64
+ path = normalize_file (path )
65
+ return self .ignore (path )
66
+
67
+ def ignore (self , path ):
68
+ result = False
69
+ for ignore , pattern in self .ignore_spec :
70
+ if pattern .match (path ):
71
+ result = ignore
72
+ return result
52
73
53
74
def __hash__ (self ):
54
75
return hash (self .ignore_file_path )
0 commit comments