Skip to content

ignore: use use_dvcignore flag #4274

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

Merged
merged 1 commit into from
Jul 23, 2020
Merged
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
6 changes: 4 additions & 2 deletions dvc/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ def __init__(self, tree, root_dir):
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, [])
Comment on lines +134 to 139
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon this will go away once we start collecting dvcignore dynamically.


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
)
Expand Down
17 changes: 7 additions & 10 deletions dvc/tree/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ def dvcignore(self):
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"
Expand Down Expand Up @@ -160,7 +156,7 @@ def _walk(self, tree, topdown=True):
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:
Expand All @@ -178,9 +174,10 @@ def walk(self, top, topdown=True, onerror=None):
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):
Expand Down
17 changes: 7 additions & 10 deletions dvc/tree/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ def dvcignore(self):
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):
Expand Down Expand Up @@ -101,7 +97,7 @@ def iscopy(self, path_info):
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:
Expand All @@ -110,9 +106,10 @@ def walk(self, top, topdown=True, onerror=None):
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

Expand Down