erepo: get rid of get_checksum (#5145)

This commit is contained in:
Ruslan Kuprieiev
2020-12-22 15:07:32 +02:00
committed by GitHub
parent 76cc70a86b
commit a6151eaf9e
4 changed files with 25 additions and 15 deletions
+4 -1
View File
@@ -1,5 +1,7 @@
from voluptuous import Required
from dvc.path_info import PathInfo
from .local import LocalDependency
@@ -48,7 +50,8 @@ class RepoDependency(LocalDependency):
# we want stream but not fetch, so DVC out directories are
# walked, but dir contents is not fetched
with self._make_repo(locked=locked, fetch=False, stream=True) as repo:
return repo.get_checksum(self.def_path)
path_info = PathInfo(repo.root_dir) / self.def_path
return repo.repo_tree.get_hash(path_info, follow_subrepos=False)
def workspace_status(self):
current = self._get_hash(locked=True)
-9
View File
@@ -218,15 +218,6 @@ class ExternalRepo(Repo):
kw["fetch"] = True
return RepoTree(repo, **kw)
def get_checksum(self, path):
path_info = PathInfo(self.root_dir) / path
with reraise(FileNotFoundError, PathMissingError(path, self.url)):
metadata = self.repo_tree.metadata(path_info)
# skip subrepos to check for
tree = self._get_tree_for(metadata.repo)
return tree.get_hash(path_info)
@staticmethod
def _fix_local_remote(orig_repo, src_repo, remote_name):
# If a remote URL is relative to the source repo,
+18 -4
View File
@@ -309,7 +309,13 @@ class RepoTree(BaseTree): # pylint:disable=abstract-method
yield from self._walk(repo_walk, None, dvcfiles=dvcfiles)
def walk(
self, top, topdown=True, onerror=None, dvcfiles=False, **kwargs
self,
top,
topdown=True,
onerror=None,
dvcfiles=False,
follow_subrepos=None,
**kwargs
): # pylint: disable=arguments-differ
"""Walk and merge both DVC and repo trees.
@@ -336,13 +342,17 @@ class RepoTree(BaseTree): # pylint:disable=abstract-method
onerror(NotADirectoryError(top))
return
ignore_subrepos = not self._traverse_subrepos
if follow_subrepos is not None:
ignore_subrepos = not follow_subrepos
tree, dvc_tree = self._get_tree_pair(top)
repo_exists = tree.exists(top)
repo_walk = tree.walk(
top,
topdown=topdown,
onerror=onerror,
ignore_subrepos=not self._traverse_subrepos,
ignore_subrepos=ignore_subrepos,
)
if not dvc_tree or (repo_exists and dvc_tree.isdvc(top)):
@@ -363,10 +373,14 @@ class RepoTree(BaseTree): # pylint:disable=abstract-method
for fname in files:
yield PathInfo(root) / fname
def get_dir_hash(self, path_info, **kwargs):
def get_dir_hash(
self, path_info, follow_subrepos=None, **kwargs
): # pylint: disable=arguments-differ
tree, dvc_tree = self._get_tree_pair(path_info)
if tree.exists(path_info):
return super().get_dir_hash(path_info, **kwargs)
return super().get_dir_hash(
path_info, follow_subrepos=follow_subrepos, **kwargs
)
if not dvc_tree:
raise FileNotFoundError
return dvc_tree.get_dir_hash(path_info, **kwargs)
+3 -1
View File
@@ -194,7 +194,9 @@ def test_subrepos_are_ignored(tmp_dir, erepo_dir):
expected_hash = HashInfo("md5", "e1d9e8eae5374860ae025ec84cfd85c7.dir")
assert (
repo.get_checksum(os.path.join(repo.root_dir, "dir"))
repo.repo_tree.get_hash(
os.path.join(repo.root_dir, "dir"), follow_subrepos=False
)
== expected_hash
)