From 312daf59d517bac37fcaf156bc6faac5bd1859d3 Mon Sep 17 00:00:00 2001 From: Eli Dowling Date: Mon, 19 Aug 2024 08:12:28 +1000 Subject: [PATCH] fix squash command messages --- jj_tui/bin/graph_view.ml | 16 ++++++++++------ jj_tui/bin/jj_process.ml | 16 ++++++++++------ jj_tui/lib/util.ml | 10 ++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/jj_tui/bin/graph_view.ml b/jj_tui/bin/graph_view.ml index bfde3ab..7813f66 100644 --- a/jj_tui/bin/graph_view.ml +++ b/jj_tui/bin/graph_view.ml @@ -68,9 +68,11 @@ module Make (Vars : Global_vars.Vars) = struct ; cmd = Fun (fun _ -> - let curr_msg, prev_msg = get_messages () in - let new_msg = prev_msg ^ curr_msg in let rev = Vars.get_selected_rev () in + let source_msg, dest_msg = get_messages rev (rev ^ "-") in + let new_msg = + [ dest_msg;source_msg ] |> String.concat_non_empty "\n" + in jj [ "squash"; "--quiet"; "-r"; rev; "-m"; new_msg ] |> ignore) } ; { @@ -79,11 +81,13 @@ module Make (Vars : Global_vars.Vars) = struct ; cmd = PromptThen ( "target revision" - , fun str -> - let curr_msg, prev_msg = get_messages () in - let new_msg = prev_msg ^ curr_msg in + , fun target -> Dynamic_r (fun rev -> + let src_msg, dest_msg = get_messages rev target in + let new_msg = + [ dest_msg;src_msg ] |> String.concat_non_empty "\n" + in Cmd [ "squash" @@ -93,7 +97,7 @@ module Make (Vars : Global_vars.Vars) = struct ; "--from" ; rev ; "--into" - ; str + ; target ]) ) } ; { diff --git a/jj_tui/bin/jj_process.ml b/jj_tui/bin/jj_process.ml index 9acebe6..5d46af4 100644 --- a/jj_tui/bin/jj_process.ml +++ b/jj_tui/bin/jj_process.ml @@ -110,7 +110,7 @@ module Make (Vars : Global_vars.Vars) = struct ;; (**gets the description of the current and previous change. Useful when squashing*) - let get_messages () = + let get_messages source dest = let open Base.Result in let output = jj @@ -118,14 +118,18 @@ module Make (Vars : Global_vars.Vars) = struct "log" ; "--no-graph" ; "-T" - ; {|"::"++current_working_copy++"::\n"++description++"\n::end::\n"|} + ; Printf.sprintf + {|if(self.contained_in("%s")||self.contained_in("%s"),description++"%s")++if(self.contained_in("%s")||self.contained_in("%s"),description)|} + source + source + "\u{ab}" + dest + dest ] |> String.trim in - let current, prev = - output |> Jj_tui.OutputParsing.parse_descriptions |> Result.get_ok - in - current |> String.concat "", prev |> String.concat "" + let source, dest = output |> Base.String.lsplit2_exn ~on:'\xab' in + Base.String.drop_suffix source 1, dest ;; open Vars diff --git a/jj_tui/lib/util.ml b/jj_tui/lib/util.ml index fd716e4..d6a7585 100644 --- a/jj_tui/lib/util.ml +++ b/jj_tui/lib/util.ml @@ -29,6 +29,7 @@ let parse_query parser s = ;; Base.List.intersperse + let ( <-$ ) f v = Lwd.map ~f (Lwd.get v) let ( $-> ) v f = Lwd.map ~f (Lwd.get v) let ( let$$ ) v f = Lwd.map ~f (Lwd.get v) @@ -36,3 +37,12 @@ let ( |>$ ) v f = Lwd.map ~f v let ( >> ) f g x = g (f x) let ( << ) f g x = f (g x) let ( |>$$ ) v2 v f = Lwd.map2 ~f v v2 + +module String = struct + include String + +(** Concatenates any non-empty strings in the given array*) + let concat_non_empty sep strings = + strings |> List.filter (Base.String.is_empty >> not) |> String.concat sep + ;; +end