Skip to content

Commit

Permalink
fix squash command messages
Browse files Browse the repository at this point in the history
  • Loading branch information
faldor20 committed Aug 18, 2024
1 parent 4e20c0d commit 312daf5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
16 changes: 10 additions & 6 deletions jj_tui/bin/graph_view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
; {
Expand All @@ -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"
Expand All @@ -93,7 +97,7 @@ module Make (Vars : Global_vars.Vars) = struct
; "--from"
; rev
; "--into"
; str
; target
]) )
}
; {
Expand Down
16 changes: 10 additions & 6 deletions jj_tui/bin/jj_process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,26 @@ 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
[
"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
Expand Down
10 changes: 10 additions & 0 deletions jj_tui/lib/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ 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)
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

0 comments on commit 312daf5

Please sign in to comment.