# # # patch "automate.ml" # from [bd6b8f753127cfd4676276294b96ebdfea404823] # to [ae72699f11e1740a3d117761a63dc7a227d226e8] # # patch "automate.mli" # from [e5b4eb3d7c214f7613e11395a39e15e30357a273] # to [64a15340bcb799983b67576fb276bb4e8bfd57c6] # # patch "monotone.ml" # from [09285df497298120461dcdc7612d50e70b24ce14] # to [e96a644b538acbca1d01fb33357b1c3198c71d12] # # patch "monotone.mli" # from [10c00b941773d4fd958d3eedf8b6f4d11b6c85a8] # to [841d81a6923af9acbb6560c7e62238fa0a309d96] # # patch "query.ml" # from [dbbb0fd4e0706565765269e29ca73954048f99c8] # to [3d7d0d1c12b82829e2827e6e349dcdacfa500a80] # # patch "unidiff.ml" # from [6446132389b142a377ad1922e73e7104241c88a6] # to [a84b8a696a2e5075b1cfe0ced654bcfe367f7002] # ============================================================ --- automate.ml bd6b8f753127cfd4676276294b96ebdfea404823 +++ automate.ml ae72699f11e1740a3d117761a63dc7a227d226e8 @@ -63,10 +63,11 @@ type t = { mutable process : process option ; } +let get_info c = + c.mtn, c.db_fname - let string_of_conditions cond = let s = String.make 6 '.' in Array.iteri ============================================================ --- automate.mli e5b4eb3d7c214f7613e11395a39e15e30357a273 +++ automate.mli 64a15340bcb799983b67576fb276bb4e8bfd57c6 @@ -6,6 +6,8 @@ type output = [ | `ERROR of string | `SYNTAX_ERROR of string] +val get_info : t -> string * string + val make : string -> string -> t val exit : t -> unit ============================================================ --- monotone.ml 09285df497298120461dcdc7612d50e70b24ce14 +++ monotone.ml e96a644b538acbca1d01fb33357b1c3198c71d12 @@ -5,6 +5,49 @@ let exit = Automate.exit let make = Automate.make let exit = Automate.exit +let spawn_monotone mtn cmd input status cb = + let mtn_exe, db_fname = Automate.get_info mtn in + let cmd = mtn_exe :: "--db" :: db_fname :: cmd in + if Viz_misc.debug "exec" + then Printf.eprintf "### exec: Running '%s'\n%!" (String.concat " " cmd) ; + try + status#push "Running monotone ..." ; + Subprocess.spawn + ~encoding:`NONE ~cmd ~input + ~reap_callback:status#pop + (fun ~exceptions ~stdout ~stderr status -> + if status = 0 + then + cb (`OUTPUT stdout) + else + let error fmt = + Printf.kprintf (fun s -> cb (`SUB_PROC_ERROR s)) fmt in + if stderr = "" + then + error "Monotone exited with status %d:\n%s" status + (String.concat "\n" (List.map Printexc.to_string exceptions)) + else + error "Monotone error:\n%s" stderr) + with Gspawn.Error (_, msg) -> + Viz_types.errorf "Could not execute monotone:\n%s" msg + + +let run_monotone_diff mtn status cb (old_id, new_id) = + ignore (spawn_monotone + mtn + [ "--revision" ; old_id ; + "--revision" ; new_id ; "diff" ] + None status cb) + + + + + + + + + + let escape_selector s = let len = String.length s in let nb_escp = ref 0 in @@ -271,3 +314,36 @@ let agraph mtn query = (* TODO: - distinguish between true neighbor nodes and nodes that are outside the date limit. *) + + +let join nb cb = + let cnt = ref nb in + let acc = ref [] in + function + | `OUTPUT data when !cnt = 1 -> + let total = List.rev (data :: !acc) in + cb (`OUTPUT total) + | `OUTPUT data -> + acc := data :: !acc ; + decr cnt + | `ERROR msg + | `SYNTAX_ERROR msg -> + cnt := 0 ; + cb (`SUB_PROC_ERROR msg) + +let decode cb = function + | `SUB_PROC_ERROR _ as r -> + cb r + | `OUTPUT d -> + let ids = List.flatten (List.map (Viz_misc.string_split '\n') d) in + cb (`IDS ids) + +let select_async mtn cb selectors = + let nb_selectors = + List.length selectors in + let auto_cb = join nb_selectors (decode cb) in + List.map + (fun sel -> Automate.submit mtn [ "select" ; sel ] auto_cb) + selectors + + ============================================================ --- monotone.mli 10c00b941773d4fd958d3eedf8b6f4d11b6c85a8 +++ monotone.mli 841d81a6923af9acbb6560c7e62238fa0a309d96 @@ -1,12 +1,25 @@ -type t +type t = Automate.t val make : string -> string -> t val exit : t -> unit +val run_monotone_diff : + t -> + unit; pop : unit -> unit; ..> -> + ([>`SUB_PROC_ERROR of string | `OUTPUT of string] -> unit) -> + string * string -> unit + +val escape_selector : string -> string + val branches : t -> (string * int) list val get_revision : t -> string -> Viz_types.node_data val get_certs_and_revision : t -> string -> Viz_types.node_data val cert_value : t -> string -> string -> string list val select : t -> string -> string list val agraph : t -> Viz_types.query -> Viz_types.agraph + +val select_async : + t -> + ([>`SUB_PROC_ERROR of string | `IDS of string list] -> unit) -> + string list -> Automate.command_id list ============================================================ --- query.ml dbbb0fd4e0706565765269e29ca73954048f99c8 +++ query.ml 3d7d0d1c12b82829e2827e6e349dcdacfa500a80 @@ -13,8 +13,8 @@ module Selector = struct let abort () = match !running_select with - | Some id -> - Subprocess.abort id ; + | Some (mtn, id) -> + List.iter (Automate.abort mtn) id ; running_select := None | _ -> () @@ -27,17 +27,15 @@ module Selector = struct `IDS (List.filter (Agraph.mem g) ids) | x -> x - let select ctrl db g sel cont = - let id = - Database.run_monotone_select - db - ctrl#get_prefs.Viz_style.monotone_path - (ctrl#status "search") + let select mtn g sel cont = + let ids = + Monotone.select_async + mtn (fun r -> running_select := None ; cont (filter_present g r)) (make_selectors g sel) in - running_select := Some id + running_select := Some (mtn, ids) end @@ -104,7 +102,7 @@ let do_query ~selector ~revision_content match ctrl#get_mtn, ctrl#get_agraph with | Some mtn, Some g when selector <> "" -> Selector.select - ctrl (some ctrl#get_db) g selector + mtn g selector (function | `IDS ids when revision_content <> "" -> results_ids ============================================================ --- unidiff.ml 6446132389b142a377ad1922e73e7104241c88a6 +++ unidiff.ml a84b8a696a2e5075b1cfe0ced654bcfe367f7002 @@ -228,13 +228,12 @@ let show ctrl old_id new_id = d#show () let show ctrl old_id new_id = - match ctrl#get_db with + match ctrl#get_mtn with | None -> () - | Some db -> + | Some mtn -> try - Database.run_monotone_diff - db - ctrl#get_prefs.Viz_style.monotone_path + Monotone.run_monotone_diff + mtn (ctrl#status "monotone") (fun res -> match res with