Skip to content

Commit

Permalink
diff: document diffables_from_output
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr. Outis committed Jan 26, 2020
1 parent 3db983f commit b251682
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,36 @@


def diffables_from_output(output):
if not output.is_dir_checksum:
return [Diffable(str(output), output.checksum)]

# Unpack directory and include its outputs in the result
return [Diffable(os.path.join(str(output), ""), output.checksum)] + [
Diffable(str(output.path_info / entry["relpath"]), entry["md5"])
for entry in output.dir_cache
]
"""
Transform an output into a list of Diffable objects so we can
compare them lately.
Unpack directories to include entries' Diffables.
To help distinguish between an a directory output and a file output,
the former one will come with a trailing slash in the filename:
directory: "data/"
file: "data"
You can also rely on the checksum to tell whether it was computed for
a file or a directory as a whole.
"""
if output.is_dir_checksum:
return [
Diffable(
filename=os.path.join(str(output), ""),
checksum=output.checksum,
)
] + [
Diffable(
filename=str(output.path_info / entry["relpath"]),
checksum=entry["md5"],
)
for entry in output.dir_cache
]

return [Diffable(filename=str(output), checksum=output.checksum)]


@locked
Expand Down

0 comments on commit b251682

Please sign in to comment.