summaryrefslogtreecommitdiff
path: root/src/config_diff.ml
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-11-10 08:17:23 -0600
committerJohn Estabrook <jestabro@vyos.io>2025-11-11 10:51:45 -0600
commitf96c02f7b9819212086da69cebbbf4f90e48766b (patch)
treea4f370050769fd11ae4b01b18b8473119b9c9d4f /src/config_diff.ml
parent3977073509a33d872bdb22d9a07c5e52ff90463b (diff)
downloadvyos1x-config-f96c02f7b9819212086da69cebbbf4f90e48766b.tar.gz
vyos1x-config-f96c02f7b9819212086da69cebbbf4f90e48766b.zip
T7988: enforce lexical-numeric order for option tuple compare
The comparison function used to order children in the diff function was unnecessarily general: maintain lexical-numeric ordering of nodes.
Diffstat (limited to 'src/config_diff.ml')
-rw-r--r--src/config_diff.ml25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/config_diff.ml b/src/config_diff.ml
index 976adf7..c97fd40 100644
--- a/src/config_diff.ml
+++ b/src/config_diff.ml
@@ -86,24 +86,17 @@ let right_opt_pairs n m =
name_of x = name_of y) in
(maybe_node, Some y))
-(* this is module option 'compare', but with Some _ preceding None, which is
- useful for maintaing left-right -> top-down order for diff_compare
- *)
-let opt_cmp o0 o1 =
- match o0, o1 with
- | Some v0, Some v1 -> compare (name_of v0) (name_of v1)
- | None, None -> 0
- | None, Some _ -> 1
- | Some _, None -> -1
-
-let tuple_cmp t1 t2 =
- match t1, t2 with
- | (x1, y1), (x2, y2) ->
- let first = opt_cmp x1 x2 in
- if first <> 0 then first else opt_cmp y1 y2
+let opt_tuple_cmp t1 t2 =
+ let opt_tuple_val t =
+ match t with
+ | None, None -> ""
+ | Some x, None -> name_of x
+ | None, Some y -> name_of y
+ | Some x, Some _ -> name_of x
+ in Util.lexical_numeric_compare (opt_tuple_val t1) (opt_tuple_val t2)
let opt_zip n m =
- left_opt_pairs n m @ right_opt_pairs n m |> List.sort_uniq tuple_cmp
+ left_opt_pairs n m @ right_opt_pairs n m |> List.sort_uniq opt_tuple_cmp
let get_opt_name left_opt right_opt =
match left_opt, right_opt with