open Lwt
open Irmin_unix
let opt_eq x = function
| None -> None = x
| Some v -> v = x
module ImapContents =
struct
include Irmin.Contents.String
let merge path ~old x y =
let open Irmin.Merge.OP in
Printf.printf "merging path: %s %b\n%!" (String.concat "/" path) (x = y);
old () >>= function
| `Conflict _ -> ok y
| `Ok old ->
if opt_eq x old then (
ok y
) else if opt_eq y old then (
ok x
) else (
ok y
)
end
let fetch remote local =
let store = Irmin.basic (module Irmin_git.FS) (module ImapContents) in
let config = Irmin_git.config ~root:local ~bare:true () in
Irmin.create store config task >>= fun t ->
let upstream = Irmin.remote_uri remote in
Irmin.pull_exn (t "Syncing with upstream store") upstream `Merge
let () =
Lwt_main.run (
catch (fun () -> fetch Sys.argv.(1) Sys.argv.(2))
(fun ex -> Printf.printf "----- exception %s\n%!" (Printexc.to_string ex); return ())
)
I have a question about Irmin merge call back for user-defined contents. It appears that merge is only called for the content that was changed but not added or deleted. Is it possible to have it called for all actions?
It's supposed to be called even when one of the version is added or deleted. In that case one of the values will be a None. That's why the merge callback [1] takes an option type. Notice that you should not normally have None for all the 3 elements of the 3-way merge.
Best,
Thomas
[1]
http://mirage.github.io/irmin/Irmin.Contents.S.html#VALmerge