mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
ignore: use use_dvcignore flag (#4274)
This commit is contained in:
+4
-2
@@ -131,14 +131,16 @@ class DvcIgnoreFilter:
|
||||
self.ignores_trie_tree[root_dir] = DvcIgnorePatterns(
|
||||
default_ignore_patterns, root_dir
|
||||
)
|
||||
for root, dirs, _ in self.tree.walk(self.root_dir):
|
||||
for root, dirs, _ in self.tree.walk(
|
||||
self.root_dir, use_dvcignore=False
|
||||
):
|
||||
self._update(root)
|
||||
self._update_sub_repo(root, dirs)
|
||||
dirs[:], _ = self(root, dirs, [])
|
||||
|
||||
def _update(self, dirname):
|
||||
ignore_file_path = os.path.join(dirname, DvcIgnore.DVCIGNORE_FILE)
|
||||
if self.tree.exists(ignore_file_path):
|
||||
if self.tree.exists(ignore_file_path, use_dvcignore=False):
|
||||
new_pattern = DvcIgnorePatterns.from_files(
|
||||
ignore_file_path, self.tree
|
||||
)
|
||||
|
||||
+7
-10
@@ -46,12 +46,8 @@ class GitTree(BaseTree): # pylint:disable=abstract-method
|
||||
from dvc.ignore import DvcIgnoreFilter, DvcIgnoreFilterNoop
|
||||
|
||||
root = self.dvcignore_root or self.tree_root
|
||||
if not self.use_dvcignore:
|
||||
return DvcIgnoreFilterNoop(self, root)
|
||||
self.use_dvcignore = False
|
||||
ret = DvcIgnoreFilter(self, root)
|
||||
self.use_dvcignore = True
|
||||
return ret
|
||||
cls = DvcIgnoreFilter if self.use_dvcignore else DvcIgnoreFilterNoop
|
||||
return cls(self, root)
|
||||
|
||||
def open(
|
||||
self, path, mode="r", encoding="utf-8"
|
||||
@@ -160,7 +156,7 @@ class GitTree(BaseTree): # pylint:disable=abstract-method
|
||||
if not topdown:
|
||||
yield os.path.normpath(tree.abspath), dirs, nondirs
|
||||
|
||||
def walk(self, top, topdown=True, onerror=None):
|
||||
def walk(self, top, topdown=True, onerror=None, use_dvcignore=True):
|
||||
"""Directory tree generator.
|
||||
|
||||
See `os.walk` for the docs. Differences:
|
||||
@@ -178,9 +174,10 @@ class GitTree(BaseTree): # pylint:disable=abstract-method
|
||||
return
|
||||
|
||||
for root, dirs, files in self._walk(tree, topdown=topdown):
|
||||
dirs[:], files[:] = self.dvcignore(
|
||||
os.path.abspath(root), dirs, files
|
||||
)
|
||||
if use_dvcignore:
|
||||
dirs[:], files[:] = self.dvcignore(
|
||||
os.path.abspath(root), dirs, files
|
||||
)
|
||||
yield root, dirs, files
|
||||
|
||||
def isexec(self, path):
|
||||
|
||||
+7
-10
@@ -58,12 +58,8 @@ class LocalTree(BaseTree):
|
||||
from dvc.ignore import DvcIgnoreFilter, DvcIgnoreFilterNoop
|
||||
|
||||
root = self.dvcignore_root or self.tree_root
|
||||
if not self.use_dvcignore:
|
||||
return DvcIgnoreFilterNoop(self, root)
|
||||
self.use_dvcignore = False
|
||||
ret = DvcIgnoreFilter(self, root)
|
||||
self.use_dvcignore = True
|
||||
return ret
|
||||
cls = DvcIgnoreFilter if self.use_dvcignore else DvcIgnoreFilterNoop
|
||||
return cls(self, root)
|
||||
|
||||
@staticmethod
|
||||
def open(path_info, mode="r", encoding=None):
|
||||
@@ -101,7 +97,7 @@ class LocalTree(BaseTree):
|
||||
System.is_symlink(path_info) or System.is_hardlink(path_info)
|
||||
)
|
||||
|
||||
def walk(self, top, topdown=True, onerror=None):
|
||||
def walk(self, top, topdown=True, onerror=None, use_dvcignore=True):
|
||||
"""Directory tree generator.
|
||||
|
||||
See `os.walk` for the docs. Differences:
|
||||
@@ -110,9 +106,10 @@ class LocalTree(BaseTree):
|
||||
for root, dirs, files in os.walk(
|
||||
top, topdown=topdown, onerror=onerror
|
||||
):
|
||||
dirs[:], files[:] = self.dvcignore(
|
||||
os.path.abspath(root), dirs, files
|
||||
)
|
||||
if use_dvcignore:
|
||||
dirs[:], files[:] = self.dvcignore(
|
||||
os.path.abspath(root), dirs, files
|
||||
)
|
||||
|
||||
yield os.path.normpath(root), dirs, files
|
||||
|
||||
|
||||
Reference in New Issue
Block a user