-
Notifications
You must be signed in to change notification settings - Fork 1.3k
dvcignore: api to unhide subrepos directory #4324
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,12 @@ | |
|
|
||
| from pathspec.patterns import GitWildMatchPattern | ||
| from pathspec.util import normalize_file | ||
| from pygtrie import StringTrie | ||
|
|
||
| from dvc.path_info import PathInfo | ||
| from dvc.pathspec_math import PatternInfo, merge_patterns | ||
| from dvc.system import System | ||
| from dvc.utils import relpath | ||
| from dvc.utils.collections import PathStringTrie | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -156,7 +156,7 @@ class DvcIgnoreFilterNoop: | |
| def __init__(self, tree, root_dir): | ||
| pass | ||
|
|
||
| def __call__(self, root, dirs, files): | ||
| def __call__(self, root, dirs, files, **kwargs): | ||
| return dirs, files | ||
|
|
||
| def is_ignored_dir(self, _): | ||
|
|
@@ -183,10 +183,11 @@ def __init__(self, tree, root_dir): | |
|
|
||
| self.tree = tree | ||
| self.root_dir = root_dir | ||
| self.ignores_trie_tree = StringTrie(separator=os.sep) | ||
| self.ignores_trie_tree = PathStringTrie() | ||
| self.ignores_trie_tree[root_dir] = DvcIgnorePatterns( | ||
| default_ignore_patterns, root_dir | ||
| ) | ||
| self._ignored_subrepos = PathStringTrie() | ||
| self._update(self.root_dir) | ||
|
|
||
| def _update(self, dirname): | ||
|
|
@@ -222,7 +223,10 @@ def _update(self, dirname): | |
| def _update_sub_repo(self, root, dirs): | ||
| for d in dirs: | ||
| if self._is_dvc_repo(root, d): | ||
| new_pattern = DvcIgnorePatterns(["/{}/".format(d)], root) | ||
| self._ignored_subrepos[root] = self._ignored_subrepos.get( | ||
| root, set() | ||
| ) | {d} | ||
| new_pattern = DvcIgnorePatterns([f"/{d}/"], root) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that fstrings are better than format() , but there wasn't really a reason to change it in this PR π
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to change that before when I was experimenting with it. And, f-string is easy to read and understand (here, speed does not matter but could have been another reason), and therefore, I kept it. |
||
| old_pattern = self.ignores_trie_tree.longest_prefix(root).value | ||
| if old_pattern: | ||
| self.ignores_trie_tree[root] = DvcIgnorePatterns( | ||
|
|
@@ -236,12 +240,13 @@ def _update_sub_repo(self, root, dirs): | |
| else: | ||
| self.ignores_trie_tree[root] = new_pattern | ||
|
|
||
| def __call__(self, root, dirs, files): | ||
| def __call__(self, root, dirs, files, ignore_subrepos=True): | ||
| ignore_pattern = self._get_trie_pattern(root) | ||
| if ignore_pattern: | ||
| return ignore_pattern(root, dirs, files) | ||
| else: | ||
| return dirs, files | ||
| dirs, files = ignore_pattern(root, dirs, files) | ||
| if not ignore_subrepos: | ||
| dirs.extend(self._ignored_subrepos.get(root, [])) | ||
| return dirs, files | ||
|
|
||
| def _get_trie_pattern(self, dirname): | ||
| ignore_pattern = self.ignores_trie_tree.get(dirname) | ||
|
|
@@ -277,8 +282,14 @@ def _is_ignored(self, path, is_dir=False): | |
| else: | ||
| return False | ||
|
|
||
| def is_ignored_dir(self, path): | ||
| def _is_subrepo(self, path): | ||
| dirname, basename = os.path.split(os.path.normpath(path)) | ||
| return basename in self._ignored_subrepos.get(dirname, set()) | ||
|
|
||
| def is_ignored_dir(self, path, ignore_subrepos=True): | ||
| path = os.path.abspath(path) | ||
| if not ignore_subrepos: | ||
| return not self._is_subrepo(path) | ||
| if path == self.root_dir: | ||
| return False | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.