terminal user interface to jujutsu. Focused on speed and clarity
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

recover stale file-view revisions after squash

+53 -3
+53 -3
jj_tui/bin/global_funcs.ml
··· 6 6 7 7 let colored_string = Jj_tui.AnsiReverse.colored_string 8 8 9 - (**lists the files in a specific revision*) 10 - let list_files ?(rev = "@") () = 11 - jj_no_log ~snapshot:false ~color:false [ "diff"; "-r"; rev; "--summary" ] 9 + let parse_changed_files output = 10 + output 12 11 |> String.split_on_char '\n' 13 12 |> List.filter_map (fun x -> 14 13 if x |> String.trim <> "" then Base.String.lsplit2 ~on:' ' x else None) 14 + ;; 15 + 16 + let is_missing_revision_error error = 17 + Base.String.is_substring error ~substring:"doesn't exist" 18 + || Base.String.is_substring error ~substring:"Revision `" 19 + ;; 20 + 21 + (** History-rewriting jj commands like squash can delete the revision currently held 22 + in UI state. When that happens, the graph will soon refresh to a valid node, but 23 + the file pane may still try to diff the stale revision in the meantime. Reset the 24 + transient selection state so follow-up refreshes target a revision that still exists. *) 25 + let recover_missing_revision rev = 26 + let hovered_matches = String.equal (Vars.get_hovered_rev ()) rev in 27 + let selected_contains = Vars.get_selected_revs () |> List.exists (String.equal rev) in 28 + if hovered_matches then Vars.ui_state.hovered_revision $= Unique "@"; 29 + if hovered_matches || selected_contains 30 + then ( 31 + Vars.ui_state.selected_revisions $= []; 32 + Vars.reset_selection ()) 33 + ;; 34 + 35 + (**lists the files in a specific revision*) 36 + let list_files ?(rev = "@") () = 37 + let diff_summary rev = 38 + jj_no_log_errorable ~snapshot:false ~color:false [ "diff"; "-r"; rev; "--summary" ] 39 + in 40 + match diff_summary rev with 41 + | Ok (output, _) -> 42 + output |> parse_changed_files 43 + | Error (`BadExit (_, error)) when is_missing_revision_error error -> 44 + (* This is the crash path hit after squash: the selected revision disappeared 45 + between UI updates. Recover locally instead of raising through startup/render 46 + fibers, then repopulate the file list from the working copy. *) 47 + [%log 48 + warn "Revision '%s' disappeared while updating file list; falling back to @" rev]; 49 + recover_missing_revision rev; 50 + (match diff_summary "@" with 51 + | Ok (output, _) -> 52 + output |> parse_changed_files 53 + | Error (`BadExit (_, error)) -> 54 + [%log warn "Failed to refresh fallback file list for @: %s" error]; 55 + [] 56 + | Error (`Exception error) -> 57 + [%log warn "Failed to refresh fallback file list for @: %s" error]; 58 + []) 59 + | Error (`BadExit (_, error)) -> 60 + [%log warn "Failed to update file list for revision '%s': %s" rev error]; 61 + [] 62 + | Error (`Exception error) -> 63 + [%log warn "Failed to update file list for revision '%s': %s" rev error]; 64 + [] 15 65 ;; 16 66 17 67 let check_startup () =