Skip to content

Commit

Permalink
irmin-tezos: simplify the way we serialise nodes
Browse files Browse the repository at this point in the history
The awkward order is not necessary anymore since irmin 1.4 and no
such order exists in the wild.
  • Loading branch information
samoht committed Jul 24, 2022
1 parent 8850da7 commit cf57f23
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/irmin-tezos/schema.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ struct

type entry = string * M.value

(* Irmin 1.4 uses int8 to store filename lengths.
Irmin 2 use a variable-size encoding for strings; this is using int8
for strings of size stricly less than 128 (e.g. 2^7) which happen to
be the case for all filenames ever produced by Irmin 1.4. *)
let step_t = Irmin.Type.string

let metadata_t =
let some = "\255\000\000\000\000\000\000\000" in
let none = "\000\000\000\000\000\000\000\000" in
Expand All @@ -103,23 +96,15 @@ struct
let open Irmin.Type in
record "Tree.entry" (fun _ _ _ -> assert false)
|+ field "kind" metadata_t metadata_of_entry
|+ field "name" step_t fst
|+ field "name" string fst
|+ field "hash" Hash.t hash_of_entry
|> sealr

let entries_t : entry list Irmin.Type.t =
Irmin.Type.(list ~len:`Int64 entry_t)

let pre_hash_entries = Irmin.Type.(unstage (pre_hash entries_t))
let compare_entry (x, _) (y, _) = String.compare x y
let step_to_string = Irmin.Type.(unstage (to_bin_string Path.step_t))
let str_key (k, v) = (step_to_string k, v)

let pre_hash t =
M.list t
|> List.map str_key
|> List.fast_sort compare_entry
|> pre_hash_entries
let pre_hash t = M.list t |> pre_hash_entries
end

include M
Expand Down

0 comments on commit cf57f23

Please sign in to comment.