raw tree diff

This commit is contained in:
Amber 2024-11-19 14:06:33 +01:00
parent bab7a21c8e
commit 4d1963f91c

View File

@ -1,58 +1,31 @@
from testing import sync
from iface import snap as _snap
from lib.snapshot import diff as _diff
from tools import pretty_table
def table_formatter(heads , tree_diff):
removed = tree_diff.get('removed') or []
changed = tree_diff.get('changed') or []
added = tree_diff.get('added') or []
moved = tree_diff.get('moved') or []
rows = []
for item in removed:
row = [
item['rel_path'] + item['name'],
'P',
'R',
]
rows.append(row)
for item in changed:
row = [
item['rel_path'] + item['name'],
'C',
'P',
]
rows.append(row)
for item in added:
row = [
item['rel_path'] + item['name'],
'_',
'A',
]
rows.append(row)
for item in moved:
row = [
item['rel_path'] + item['name'],
'P',
'M',
]
rows.append(row)
mlen = []
for k, v in tree_diff.items():
if not v: continue
## max name + relpath of each node for each transformation
m = max([(len(item['name']) + len(item['rel_path'])) for item in v ])
mlen.append(m)
# name and relpath of node
for node_path, node_dict in tree_diff.items():
row = [node_path]
mlen.append(len(node_path))
if node_dict.get('tree_a') is not None:
row.append('x')
else:
row.append('-')
if node_dict.get('tree_b') is not None:
row.append('x')
else:
row.append('-')
rows.append(row)
padding_right = 5
hflen = max(mlen) + padding_right
hsclen = 11 + padding_right
@ -75,7 +48,7 @@ def human_tree_diff_local_remote():
remote_tree_hash = agent.generate_tree_hash_oversftp(remote_path)
tree_diff = _snap.diff_snap(local_tree_hash, remote_tree_hash)
tree_diff = _diff.raw_diff(local_tree_hash, remote_tree_hash)
table_formatter(['Node', 'Local', 'Remote'], tree_diff)
return tree_diff
@ -85,6 +58,6 @@ def human_tree_diff_local():
local_hash_before = m.load_local_hash()
local_hash_after = m.compute_local_hash()
tree_diff = _snap.diff_snap(local_hash_before, local_hash_after)
tree_diff = _diff.raw_diff(local_hash_before, local_hash_after)
table_formatter(['Node', 'Local Before', 'Local After'], tree_diff)
return tree_diff