diff options
author | John Estabrook <jestabro@vyos.io> | 2022-02-25 10:43:13 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2022-02-25 10:43:13 -0600 |
commit | 7e4d9ff86ca96a990f52e05310a0486cb668cfb8 (patch) | |
tree | cf032f1ef446b1eda518fa5816be8aa04fe7e681 /src | |
parent | 23173c6b5d12e5b7990fafe2b43d40f5cbf1a2a5 (diff) | |
download | vyos1x-config-7e4d9ff86ca96a990f52e05310a0486cb668cfb8.tar.gz vyos1x-config-7e4d9ff86ca96a990f52e05310a0486cb668cfb8.zip |
T4235: keep full paths in subtract tree
In the intial implementation, the delete tree only kept the first node
of a path not present in the RHS of the comparison; this was done as a
convenience for generating 'trimmed' delete commands for the CLI.
However, this loses needed information, and breaks the symmetry of
results:
LHS, RHS -> del, inter, add
RHS, LHS -> add, inter, del
Keep full paths in delete tree and rename trees.del to trees.sub(-tract).
A separate function 'trim_tree' will be provided to produce a
CLI-appopriate delete tree and commands.
Diffstat (limited to 'src')
-rw-r--r-- | src/config_diff.ml | 16 | ||||
-rw-r--r-- | src/config_diff.mli | 2 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/config_diff.ml b/src/config_diff.ml index 565d64f..6d7c328 100644 --- a/src/config_diff.ml +++ b/src/config_diff.ml @@ -6,7 +6,7 @@ type diff_trees = { left: Config_tree.t; right: Config_tree.t; add: Config_tree.t ref; - del: Config_tree.t ref; + sub: Config_tree.t ref; inter: Config_tree.t ref; } @@ -17,7 +17,7 @@ module ValueS = Set.Make(struct type t = string let compare = compare end) let make_diff_trees l r = { left = l; right = r; add = ref (Config_tree.make "root"); - del = ref (Config_tree.make "root"); + sub = ref (Config_tree.make "root"); inter = ref (Config_tree.make "root"); } @@ -123,13 +123,13 @@ let graft_tree stem stock path = let decorate_trees (trees : diff_trees) ?(with_children=true) (path : string list) (m : change) = match m with | Added -> trees.add := clone trees.right !(trees.add) path - | Deleted -> trees.del := clone ~with_children:false trees.left !(trees.del) path + | Deleted -> trees.sub := clone trees.left !(trees.sub) path | Unchanged -> trees.inter := clone ~with_children:with_children trees.left !(trees.inter) path | Updated v -> (* if in this case, node at path is guaranteed to exist *) let ov = Config_tree.get_values trees.left path in match ov, v with - | [_], [_] -> trees.del := clone trees.left !(trees.del) path; + | [_], [_] -> trees.sub := clone trees.left !(trees.sub) path; trees.add := clone trees.right !(trees.add) path | _, _ -> let ovs = ValueS.of_list ov in let vs = ValueS.of_list v in @@ -137,7 +137,7 @@ let decorate_trees (trees : diff_trees) ?(with_children=true) (path : string lis let set_v = ValueS.elements (ValueS.diff vs ovs) in let set_inter = ValueS.elements (ValueS.inter ovs vs) in if not (set_ov = []) then - trees.del := clone ~set_values:set_ov trees.left !(trees.del) path; + trees.sub := clone ~set_values:set_ov trees.left !(trees.sub) path; if not (set_v = []) then trees.add := clone ~set_values:set_v trees.right !(trees.add) path; if not (set_inter = []) then @@ -165,10 +165,10 @@ let compare path left right = let diff_tree path left right = let trees = compare path left right in let add_node = Config_tree.make "add" in - let del_node = Config_tree.make "delete" in + let sub_node = Config_tree.make "sub" in let int_node = Config_tree.make "inter" in - let ret = make Config_tree.default_data "root" [add_node; del_node; int_node] in + let ret = make Config_tree.default_data "root" [add_node; sub_node; int_node] in let ret = graft_tree !(trees.add) ret ["add"] in - let ret = graft_tree !(trees.del) ret ["delete"] in + let ret = graft_tree !(trees.sub) ret ["sub"] in let ret = graft_tree !(trees.inter) ret ["inter"] in ret diff --git a/src/config_diff.mli b/src/config_diff.mli index 5f96209..5aa6d30 100644 --- a/src/config_diff.mli +++ b/src/config_diff.mli @@ -6,7 +6,7 @@ type diff_trees = { left: Config_tree.t; right: Config_tree.t; add: Config_tree.t ref; - del: Config_tree.t ref; + sub: Config_tree.t ref; inter: Config_tree.t ref; } |