Compare commits
2 Commits
f38ef1bfff
...
4d1963f91c
Author | SHA1 | Date | |
---|---|---|---|
|
4d1963f91c | ||
|
bab7a21c8e |
@ -1,24 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def recursive_raw_diff(tree_a, tree_b, tree_a_tag, tree_b_tag, path, res):
|
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():
|
for key_a, hsh_a in tree_a.items():
|
||||||
hsh_b = tree_b.get(key_a)
|
hsh_b = tree_b.get(key_a)
|
||||||
|
|
||||||
if hsh_b is None:
|
if hsh_b is None:
|
||||||
'''
|
|
||||||
already in `a_keys_not_in_b`
|
|
||||||
'''
|
|
||||||
res[f'{path}{key_a}'] = {
|
res[f'{path}{key_a}'] = {
|
||||||
tree_a_tag : 'x',
|
tree_a_tag : 'x',
|
||||||
}
|
}
|
||||||
|
@ -1,58 +1,31 @@
|
|||||||
from testing import sync
|
from testing import sync
|
||||||
from iface import snap as _snap
|
from iface import snap as _snap
|
||||||
|
|
||||||
|
from lib.snapshot import diff as _diff
|
||||||
|
|
||||||
from tools import pretty_table
|
from tools import pretty_table
|
||||||
|
|
||||||
def table_formatter(heads , tree_diff):
|
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 = []
|
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 = []
|
mlen = []
|
||||||
for k, v in tree_diff.items():
|
|
||||||
if not v: continue
|
for node_path, node_dict in tree_diff.items():
|
||||||
## max name + relpath of each node for each transformation
|
row = [node_path]
|
||||||
m = max([(len(item['name']) + len(item['rel_path'])) for item in v ])
|
mlen.append(len(node_path))
|
||||||
mlen.append(m)
|
|
||||||
# name and relpath of node
|
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
|
padding_right = 5
|
||||||
hflen = max(mlen) + padding_right
|
hflen = max(mlen) + padding_right
|
||||||
hsclen = 11 + 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)
|
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)
|
table_formatter(['Node', 'Local', 'Remote'], tree_diff)
|
||||||
return tree_diff
|
return tree_diff
|
||||||
@ -85,6 +58,6 @@ def human_tree_diff_local():
|
|||||||
local_hash_before = m.load_local_hash()
|
local_hash_before = m.load_local_hash()
|
||||||
local_hash_after = m.compute_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)
|
table_formatter(['Node', 'Local Before', 'Local After'], tree_diff)
|
||||||
return tree_diff
|
return tree_diff
|
||||||
|
Loading…
Reference in New Issue
Block a user