Skip to content

Commit

Permalink
diff: use relpaths
Browse files Browse the repository at this point in the history
Regression from path_info removal.

Also fixes #7147
  • Loading branch information
efiop committed Dec 15, 2021
1 parent e24de3a commit 30d6839
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 3 additions & 6 deletions dvc/fs/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ def overlaps(self, left, right):
# pylint: disable=arguments-out-of-order
return self.isin_or_eq(left, right) or self.isin(right, left)

def relpath(self, path, base):
assert len(path) > len(base)
assert path.startswith(base)
normpath = path.rstrip(self.flavour.sep)
normbase = base.rstrip(self.flavour.sep)
return normpath[len(normbase) + 1 :]
def relpath(self, path, start):
assert start
return self.flavour.relpath(path, start=start)

def relparts(self, path, base):
return self.parts(self.relpath(path, base))
Expand Down
9 changes: 8 additions & 1 deletion dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,20 @@ def _to_path(output):


def _dir_output_paths(fs, fs_path, obj, targets=None):
if fs.scheme == "local":
# NOTE: workaround for filesystems that are based on full local paths
# (e.g. gitfs, dvcfs, repofs). Proper solution is to use upcoming
# fsspec's prefixfs to use relpaths as fs_paths.
base = fs.path.relpath(fs_path, os.getcwd())
else:
base = fs_path
for key, _, oid in obj:
fname = fs.path.join(fs_path, *key)
if targets is None or any(
fs.path.isin_or_eq(fname, target) for target in targets
):
# pylint: disable=no-member
yield fs.path.join(fs.path.name(fs_path), *key), oid.value
yield fs.path.join(base, *key), oid.value


def _filter_missing(repo_fs, paths):
Expand Down
22 changes: 22 additions & 0 deletions tests/func/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def test_added(tmp_dir, scm, dvc):
}


def test_added_deep(tmp_dir, scm, dvc):
tmp_dir.gen({"datas": {"data": {"file": "text"}}})
dvc.add(os.path.join("datas", "data"))

assert dvc.diff() == {
"added": [
{
"path": os.path.join("datas", "data" + os.sep),
"hash": "0dab3fae569586d4c33272e5011605bf.dir",
},
{
"path": os.path.join("datas", "data", "file"),
"hash": "1cb251ec0d568de6a929b520c4aed8d1",
},
],
"deleted": [],
"modified": [],
"not in cache": [],
"renamed": [],
}


def test_no_cache_entry(tmp_dir, scm, dvc):
tmp_dir.dvc_gen("file", "first", commit="add a file")

Expand Down

0 comments on commit 30d6839

Please sign in to comment.