summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-06-11 11:46:12 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-07-06 18:31:49 -0500
commit73d0eec02cae106c6b79a5f4c6c42967c829c546 (patch)
tree1820f1122d565f9d161edb9727a93ad19ab4057e /lib
parentc83ec7e268265fb11cc8bba8c296e0ef8bc1a3b4 (diff)
downloadlibvyosconfig-73d0eec02cae106c6b79a5f4c6c42967c829c546.tar.gz
libvyosconfig-73d0eec02cae106c6b79a5f4c6c42967c829c546.zip
T7499: bindings for (non-)destructive configtree merge
Diffstat (limited to 'lib')
-rw-r--r--lib/bindings.ml15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/bindings.ml b/lib/bindings.ml
index 604c05f..2d9a5d1 100644
--- a/lib/bindings.ml
+++ b/lib/bindings.ml
@@ -7,6 +7,7 @@ open Commitd_client
module CT = Config_tree
module CD = Config_diff
+module TA = Tree_alg
module CM = Commit
module VC = Vycall_client
@@ -247,7 +248,18 @@ let tree_union c_ptr_l c_ptr_r =
let ct_ret = CD.tree_union ct_l ct_r in
Ctypes.Root.create ct_ret
with
- CD.Nonexistent_child -> error_message := "Nonexistent child"; Ctypes.null
+ | TA.Nonexistent_child -> error_message := "Nonexistent child"; Ctypes.null
+ | TA.Incompatible_union -> error_message := "Trees must have equivalent root"; Ctypes.null
+
+let tree_merge destructive c_ptr_l c_ptr_r =
+ let ct_l = Root.get c_ptr_l in
+ let ct_r = Root.get c_ptr_r in
+ try
+ let ct_ret = CD.tree_merge ~destructive:destructive ct_l ct_r in
+ Ctypes.Root.create ct_ret
+ with
+ | TA.Nonexistent_child -> error_message := "Nonexistent child"; Ctypes.null
+ | TA.Incompatible_union -> error_message := "Trees must have equivalent root"; Ctypes.null
let reference_tree_to_json internal_cache from_dir to_file =
try
@@ -304,6 +316,7 @@ struct
let () = I.internal "diff_tree" (string @-> (ptr void) @-> (ptr void) @-> returning (ptr void)) diff_tree
let () = I.internal "show_diff" (bool @-> string @-> (ptr void) @-> (ptr void) @-> returning string) show_diff
let () = I.internal "tree_union" ((ptr void) @-> (ptr void) @-> returning (ptr void)) tree_union
+ let () = I.internal "tree_merge" (bool @-> (ptr void) @-> (ptr void) @-> returning (ptr void)) tree_merge
let () = I.internal "reference_tree_to_json" (string @-> string @-> string @-> returning int) reference_tree_to_json
let () = I.internal "mask_tree" ((ptr void) @-> (ptr void) @-> returning (ptr void)) mask_tree
end