MCPcopy
hub / github.com/treeverse/dvc / _show_diff

Method _show_diff

dvc/commands/diff.py:44–116  ·  view source on GitHub ↗

Given a diff structure, generate a string of paths separated by new lines and grouped together by their state. A group's header is colored to enhance readability, for example: Added: another_file.txt backup.tar di

(diff, hide_missing=False)

Source from the content-addressed store, hash-verified

42class CmdDiff(CmdBase):
43 @staticmethod
44 def _show_diff(diff, hide_missing=False):
45 """
46 Given a diff structure, generate a string of paths separated
47 by new lines and grouped together by their state.
48
49 A group's header is colored to enhance readability, for example:
50
51 Added:
52 another_file.txt
53 backup.tar
54 dir/
55 dir/1
56
57 An example of a diff formatted when entries contain hash:
58
59 Added:
60 d3b07384 foo
61
62 Modified:
63 c157a790..f98bf6f1 bar
64
65 If a group has no entries, it won't be included in the result.
66
67 At the bottom, include a summary with the number of files per state.
68 """
69
70 colors = {
71 "added": "green",
72 "modified": "yellow",
73 "deleted": "red",
74 "renamed": "green",
75 "not in cache": "yellow",
76 }
77
78 summary = {}
79
80 states = ["added", "deleted", "renamed", "modified"]
81 if not hide_missing:
82 states.append("not in cache")
83 for state in states:
84 summary[state] = 0
85 entries = diff[state]
86
87 if not entries:
88 continue
89
90 header = state.capitalize()
91 ui.write(f"[{colors[state]}]{header}[/]:", styled=True)
92
93 for entry in entries:
94 path = entry["path"]
95 if isinstance(path, dict):
96 path = f"{path['old']} -> {path['new']}"
97 checksum = entry.get("hash")
98 summary[state] += 1 if not path.endswith(os.sep) else 0
99 ui.write(
100 "{space}{checksum}{separator}{path}".format(
101 space=" ",

Callers 1

runMethod · 0.95

Calls 6

_digestFunction · 0.85
appendMethod · 0.80
writeMethod · 0.80
joinMethod · 0.80
getMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected