Compare commits

...

2 Commits

Author SHA1 Message Date
Amber
4d1963f91c raw tree diff 2024-11-19 14:06:33 +01:00
Amber
bab7a21c8e rawdiff 2024-11-18 17:00:29 +01:00
2 changed files with 21 additions and 62 deletions

View File

@ -1,24 +1,10 @@
import os
def recursive_raw_diff(tree_a, tree_b, tree_a_tag, tree_b_tag, path, res):
# a_keys_not_in_b = set(tree_a.keys()) - set(tree_b.keys())
# b_keys_not_in_a = set(tree_b.keys()) - set(tree_a.keys())
## name last is a dir
# manage below
# if a_keys_not_in_b:
# for key in a_keys_not_in_b:
# print(f'node {path}{key} subtree added in {tree_a_tag}')
# res[f'{path}{key}'] = {
# tree_a_tag : 'x',
# }
for key_a, hsh_a in tree_a.items():
hsh_b = tree_b.get(key_a)
if hsh_b is None:
'''
already in `a_keys_not_in_b`
'''
res[f'{path}{key_a}'] = {
tree_a_tag : 'x',
}

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