diff options
author | John Estabrook <jestabro@vyos.io> | 2023-07-13 09:55:12 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-07-27 14:36:26 -0500 |
commit | 9ceb7a3ffb0e86af35c01aee38420007a1e3fa83 (patch) | |
tree | 5d9d35a6d003c2834fda7405c254d270ccea7263 /src | |
parent | 5085dce15b6e41cf0d1ae3cd832a262f6902ac36 (diff) | |
download | vyos1x-config-9ceb7a3ffb0e86af35c01aee38420007a1e3fa83.tar.gz vyos1x-config-9ceb7a3ffb0e86af35c01aee38420007a1e3fa83.zip |
T5316: drop trim functions
Diffstat (limited to 'src')
-rw-r--r-- | src/config_diff.ml | 52 | ||||
-rw-r--r-- | src/config_diff.mli | 2 |
2 files changed, 0 insertions, 54 deletions
diff --git a/src/config_diff.ml b/src/config_diff.ml index e3e89bd..cd9104b 100644 --- a/src/config_diff.ml +++ b/src/config_diff.ml @@ -177,52 +177,6 @@ let decorate_trees (trees : diff_trees) ?(recurse=true) (path : string list) (m if not (is_empty inter_vals) then trees.inter := clone ~set_values:(Some inter_vals) trees.left !(trees.inter) path -(* define the 'trim' diff_func: - - One can use the diff algorithm with this function to produce 'delete' - commands from the sub(-tract) tree. The subtract tree contains full paths - not present in the right hand side of the original comparison; the delete - tree is the subtract tree with paths ending at the first subtracted node. - - Initial application of diff algorithm with function 'diff_trees': - left, right -> added, subtracted, intersection - Second application of diff algorithm with function 'trim_trees': - subtracted, right -> _, delete, _ - - One needs to keep the distinction of sub and delete trees: the delete - tree is used to produce correct 'delete' commands; the sub tree contains - complete information of the difference, used, for example, in recursively - detecting changes at a node between the effective/session configs. - - The two trees could be produced in one pass of the diff function, but is - an overloaded use and would gain little in optimization: the trim-ing - walk will be on a smaller tree, only involve diff_func calls on the - subtracted nodes, and will end at the first node not present in the - comparison. - *) -let trim_trees (trees : diff_trees) ?(recurse=false) (path : string list) (m : change) = - match m with - | Added -> () - | Subtracted -> trees.sub := clone ~recurse:recurse ~set_values:(Some []) trees.left !(trees.sub) path - | Unchanged -> () - | 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.sub := clone trees.left !(trees.sub) path; - | _, _ -> let ov_set = ValueS.of_list ov in - let v_set = ValueS.of_list v in - let sub_vals = ValueS.elements (ValueS.diff ov_set v_set) in - let add_vals = ValueS.elements (ValueS.diff v_set ov_set) in - (* in practice, the above sets will be disjoint *) - let inter_vals = ValueS.elements (ValueS.inter ov_set v_set) in - if not (is_empty sub_vals) then - if (is_empty add_vals) && (is_empty inter_vals) then - (* delete whole node, not just values *) - trees.sub := clone ~set_values:(Some []) trees.left !(trees.sub) path - else - trees.sub := clone ~set_values:(Some sub_vals) trees.left !(trees.sub) path - (* get sub trees for path-relative comparison *) let tree_at_path path node = try @@ -251,12 +205,6 @@ let diff_tree path left right = let ret = make Config_tree.default_data "" [add_node; sub_node; del_node; int_node] in ret -(* wrapper to return trimmed tree for 'delete' commands *) -let trim_tree left right = - let trees = make_diff_trees left right in - diff [] (trim_trees trees) [(Option.some left, Option.some right)]; - !(trees.sub) - (* the following builds a diff_func to return a unified diff string of configs or config commands *) diff --git a/src/config_diff.mli b/src/config_diff.mli index 85eb2d1..b1c3c09 100644 --- a/src/config_diff.mli +++ b/src/config_diff.mli @@ -18,9 +18,7 @@ exception Nonexistent_child val make_diff_trees : Config_tree.t -> Config_tree.t -> diff_trees val clone : ?recurse:bool -> ?set_values:(string list) option -> Config_tree.t -> Config_tree.t -> string list -> Config_tree.t val decorate_trees : diff_trees -> ?recurse:bool -> string list -> change -> unit -val trim_trees : diff_trees -> ?recurse:bool -> string list -> change -> unit val compare : string list -> Config_tree.t -> Config_tree.t -> diff_trees val diff_tree : string list -> Config_tree.t -> Config_tree.t -> Config_tree.t -val trim_tree : Config_tree.t -> Config_tree.t -> Config_tree.t val show_diff : ?cmds:bool -> string list -> Config_tree.t -> Config_tree.t -> string val tree_union : Config_tree.t -> Config_tree.t -> Config_tree.t |