mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
repo: change the returning value of repo.diff
repo.diff now returns list of dictionaries for each file/directory change
This commit is contained in:
+66
-1
@@ -1,5 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import humanize
|
||||
import inflect
|
||||
|
||||
|
||||
import dvc.logger as logger
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.command.base import CmdBase
|
||||
@@ -7,7 +11,68 @@ from dvc.utils.collections import compact
|
||||
|
||||
|
||||
class CmdDiff(CmdBase):
|
||||
def _show(self, msg):
|
||||
def _print_size(self, size):
|
||||
if size < 0:
|
||||
change = "decreased by {}"
|
||||
elif size > 0:
|
||||
change = "increased by {}"
|
||||
else:
|
||||
change = "not changed"
|
||||
natur_size = humanize.naturalsize(abs(size))
|
||||
return change.format(natur_size)
|
||||
|
||||
def _show(self, diff_dct):
|
||||
engine = inflect.engine()
|
||||
msg = "dvc diff from {} to {}".format(
|
||||
diff_dct["a_ref"], diff_dct["b_ref"]
|
||||
)
|
||||
if diff_dct.get("equal"):
|
||||
logger.info(msg)
|
||||
return
|
||||
for dct in diff_dct["diffs"]:
|
||||
msg += "\n\ndiff for '{}' \n".format(dct["target"])
|
||||
if dct.get("old_file"):
|
||||
msg += "-{} with md5 {}\n".format(
|
||||
dct["old_file"], dct["old_checksum"]
|
||||
)
|
||||
if dct.get("new_file"):
|
||||
msg += "+{} with md5 {}\n".format(
|
||||
dct["new_file"], dct["new_checksum"]
|
||||
)
|
||||
msg += "\n"
|
||||
if dct.get("is_dir"):
|
||||
msg += "{} {} not changed, ".format(
|
||||
dct["ident"], engine.plural("file", dct["ident"])
|
||||
)
|
||||
msg += "{} {} modified, ".format(
|
||||
dct["changes"], engine.plural("file", dct["changes"])
|
||||
)
|
||||
msg += "{} {} added, ".format(
|
||||
dct["new"], engine.plural("file", dct["new"])
|
||||
)
|
||||
msg += "{} {} deleted, ".format(
|
||||
dct["del"], engine.plural("file", dct["del"])
|
||||
)
|
||||
msg += "size was {}".format(self._print_size(dct["size_diff"]))
|
||||
else:
|
||||
if (
|
||||
dct.get("old_file")
|
||||
and dct.get("new_file")
|
||||
and dct["size_diff"] == 0
|
||||
):
|
||||
msg += "file size was not changed"
|
||||
elif dct.get("new_file"):
|
||||
msg += "added file with size {}".format(
|
||||
humanize.naturalsize(dct["size_diff"])
|
||||
)
|
||||
elif dct.get("old_file"):
|
||||
msg += "deleted file with size {}".format(
|
||||
humanize.naturalsize(abs(dct["size_diff"]))
|
||||
)
|
||||
else:
|
||||
msg += "file was modified, file size {}".format(
|
||||
self._print_size(dct["size_diff"])
|
||||
)
|
||||
logger.info(msg)
|
||||
|
||||
def run(self):
|
||||
|
||||
Reference in New Issue
Block a user