-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dvc: get rid of CleanTree #4221
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import os | ||
import stat | ||
|
||
from funcy import cached_property | ||
|
||
from dvc.exceptions import DvcException | ||
from dvc.scm.tree import BaseTree | ||
from dvc.utils import relpath | ||
|
@@ -22,7 +24,7 @@ def _item_basename(item): | |
class GitTree(BaseTree): # pylint:disable=abstract-method | ||
"""Proxies the repo file access methods to Git objects""" | ||
|
||
def __init__(self, git, rev): | ||
def __init__(self, git, rev, use_dvcignore=False, dvcignore_root=None): | ||
"""Create GitTree instance | ||
|
||
Args: | ||
|
@@ -31,11 +33,25 @@ def __init__(self, git, rev): | |
""" | ||
self.git = git | ||
self.rev = rev | ||
self.use_dvcignore = use_dvcignore | ||
self.dvcignore_root = dvcignore_root | ||
|
||
@property | ||
def tree_root(self): | ||
return self.git.working_dir | ||
|
||
@cached_property | ||
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 | ||
|
||
def open(self, path, mode="r", encoding="utf-8"): | ||
assert mode in {"r", "rb"} | ||
|
||
|
@@ -58,20 +74,29 @@ def open(self, path, mode="r", encoding="utf-8"): | |
return io.StringIO(data.decode(encoding)) | ||
|
||
def exists(self, path): | ||
return self._git_object_by_path(path) is not None | ||
if self._git_object_by_path(path) is None: | ||
return False | ||
|
||
return not self.dvcignore.is_ignored_file( | ||
path | ||
) and not self.dvcignore.is_ignored_dir(path) | ||
Comment on lines
+77
to
+82
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. just mimicing old CleanTree. Could reconsider whether or not we really need to deny direct access here. E.g. you could force |
||
|
||
def isdir(self, path): | ||
obj = self._git_object_by_path(path) | ||
if obj is None: | ||
return False | ||
return obj.mode == GIT_MODE_DIR | ||
if obj.mode != GIT_MODE_DIR: | ||
return False | ||
return not self.dvcignore.is_ignored_dir(path) | ||
|
||
def isfile(self, path): | ||
obj = self._git_object_by_path(path) | ||
if obj is None: | ||
return False | ||
# according to git-fast-import(1) file mode could be 644 or 755 | ||
return obj.mode & GIT_MODE_FILE == GIT_MODE_FILE | ||
if obj.mode & GIT_MODE_FILE != GIT_MODE_FILE: | ||
return False | ||
return not self.dvcignore.is_ignored_file(path) | ||
|
||
@staticmethod | ||
def _is_tree_and_contains(obj, path): | ||
|
@@ -145,7 +170,11 @@ def walk(self, top, topdown=True, onerror=None): | |
onerror(NotADirectoryError(top)) | ||
return | ||
|
||
yield from self._walk(tree, topdown=topdown) | ||
for root, dirs, files in self._walk(tree, topdown=topdown): | ||
dirs[:], files[:] = self.dvcignore( | ||
os.path.abspath(root), dirs, files | ||
) | ||
yield root, dirs, files | ||
|
||
def isexec(self, path): | ||
if not self.exists(path): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding recursion. Could wrap this hack in
try: finally
but will be replaced in the following patch anyway.