Something went wrong. Try again.
A local Git merge queue with content-bound gate verdicts
Something went wrong. Try again.
1.7 kB · 50 lines
OCaml
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051module M = Merge_queueopen Merge_queue_eioopen Command
let source ctx (q : queue) = { Server.title = Fpath.to_string q.location.checkout; status = (fun branch -> match Command_status.view ctx ~branch with | Ok v -> Ok (M.Status.document ~why:false v) | Error o -> Error (M.Outcome.first_line o)); events = (fun ~after -> let from = match after with None -> `End | Some seq -> `After seq in let c = Command_events.cursor q.perform ~from in (* A reader that resumes reads what it missed at once. *) let resumed = ref (after <> None) in fun () -> let reading = if !resumed then ( resumed := false; Command_events.read c) else Command_events.wait c in List.map (fun (r : Journal.record) -> (r.seq, r.line)) reading.records); }
let run ?stop ctx ~port ~on_listen = with_queue ~writes:false ctx @@ fun q -> initialised q @@ fun _ -> let token = Server.token () in let routes = Server.routes token (source ctx q) in let port = Option.value ~default:0 port in (* The URL names the address the listener is bound to, as it is bound. *) let listening = function | `Tcp (ip, port) -> Fmt.kstr on_listen "http://%a:%d%s" Eio.Net.Ipaddr.pp ip port (Server.root token) | `Unix _ -> () in match Respond_eio.run ?stop ~net:(Eio.Stdenv.net ctx.env) ~on_listen:listening ~addr:(`Tcp (Eio.Net.Ipaddr.V4.loopback, port)) routes with | () -> Ok () | exception (Eio.Io (_, _) as e) -> Error (Fmt.kstr unavailable "cannot listen on 127.0.0.1:%d: %a" port Fmt.exn e)