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.

fix log file cleanup function

+28 -22
+1 -1
jj_tui/bin/global_funcs.ml
··· 46 46 (* From now on we use ignore-working-copy so we don't re-snapshot the state and so 47 47 we can operate in paralell *) 48 48 (* TODO: stop using dop last twice *) 49 - Show_view.reRender (); 49 + Show_view.re_render (); 50 50 let files_list = Flock.fork_as_promise (fun _ -> list_files ~rev ()) in 51 51 Vars.ui_state.jj_branches $= branches; 52 52 (*wait for all our tasks*)
+3
jj_tui/bin/graph_view.ml
··· 430 430 (*Respond to change in selected revision*) 431 431 Lwd.set Vars.ui_state.hovered_revision hovered; 432 432 Lwd.set Vars.ui_state.selected_revisions selected; 433 + (*If the files are focused we shouldn't send this*) 434 + if Show_view.lastMessage 433 435 Show_view.(pushStatus (Graph_preview (Vars.get_hovered_rev ()))); 436 + 434 437 [%log debug "Hovered revision: '%s'" (Global_vars.get_unique_id hovered)]; 435 438 Picos_std_structured.Flock.fork (fun () -> Global_funcs.update_views ())) 436 439 ~custom_handler:(fun ~selected ~selectable_items key -> handleKeys key)
+1 -1
jj_tui/bin/show_view.ml
··· 12 12 let pushStatus status = Stream.push statusStream status 13 13 14 14 (** pushes the last message to the queue again to re-render everything *) 15 - let reRender () = lastMessage |> Option.iter pushStatus 15 + let re_render () = lastMessage |> Option.iter pushStatus 16 16 17 17 module Make (Vars : Global_vars.Vars) = struct 18 18 open Lwd_infix
+23 -20
jj_tui/lib/logging.ml
··· 1 1 (** A version of the logging module that adds timestamps to the logs *) 2 2 3 + let time_to_string tm = 4 + let ms = (tm |> Float.modf |> fst) *. 1000. |> Float.to_int in 5 + let tm = tm |> Unix.localtime in 6 + Printf.sprintf 7 + "%04d-%02d-%02d %02d:%02d:%02d.%03d" 8 + (tm.Unix.tm_year + 1900) 9 + (tm.Unix.tm_mon + 1) 10 + tm.Unix.tm_mday 11 + tm.Unix.tm_hour 12 + tm.Unix.tm_min 13 + tm.Unix.tm_sec 14 + ms 15 + ;; 16 + 3 17 module Log = struct 4 18 let timestamp_tag = 5 - let now () = Unix.gettimeofday () |> Unix.localtime in 6 - let time_to_string tm = 7 - Printf.sprintf 8 - "%04d-%02d-%02d %02d:%02d:%02d" 9 - (tm.Unix.tm_year + 1900) 10 - (tm.Unix.tm_mon + 1) 11 - tm.Unix.tm_mday 12 - tm.Unix.tm_hour 13 - tm.Unix.tm_min 14 - tm.Unix.tm_sec 15 - in 16 19 Logs.Tag.def "timestamp" ~doc:"Timestamp" (fun fmt tm -> 17 20 time_to_string tm |> Format.pp_print_string fmt) 18 21 ;; ··· 20 23 let timestamp_wrap fn : ('a, 'b) Logs.msgf = 21 24 fun m -> 22 25 fn (fun ?header ?(tags = Logs.Tag.empty) fmt -> 23 - let timestamp = Unix.gettimeofday () |> Unix.localtime in 24 - let tags = Logs.Tag.add timestamp_tag timestamp Logs.Tag.empty in 26 + let timestamp = Unix.gettimeofday () in 27 + let tags = Logs.Tag.add timestamp_tag timestamp tags in 25 28 m ?header ~tags fmt) 26 29 ;; 27 30 ··· 64 67 65 68 (** Removes old log files, keeping only the 20 most recent *) 66 69 let cleanup_logs log_path = 70 + [%log debug "cleaning up logs at %s" log_path]; 67 71 let log_files = 68 72 Sys.readdir log_path 69 73 |> Array.to_list ··· 77 81 if i >= 20 78 82 then ( 79 83 let file_path = Filename.concat log_path file in 80 - Unix.unlink file_path)) 84 + Unix.unlink file_path; 85 + [%log debug "deleted log file:%s" file_path])) 81 86 log_files 82 87 ;; 83 88 ··· 140 145 (*just no logging if we can't find a log file*) 141 146 (*TODO: log to stderr *) 142 147 match get_log_dir () with 143 - | Some log_dir -> 148 + | Some state_dir -> 149 + let log_dir = Filename.concat state_dir "jj_tui" in 144 150 (*creates or opens the log file*) 145 151 let get_log_file_channel () = 146 - let jj_tui_dir = Filename.concat log_dir "jj_tui" in 147 - (try Unix.mkdir jj_tui_dir 0o755 with 148 - | Unix.Unix_error (Unix.EEXIST, _, _) -> 149 - ()); 152 + (try Unix.mkdir log_dir 0o755 with Unix.Unix_error (Unix.EEXIST, _, _) -> ()); 150 153 let timestamp = Unix.time () |> Unix.localtime in 151 154 let timestamp_str = 152 155 Printf.sprintf ··· 159 162 timestamp.tm_sec 160 163 in 161 164 let log_file = 162 - Filename.concat jj_tui_dir (Printf.sprintf "log_%s.log" timestamp_str) 165 + Filename.concat log_dir (Printf.sprintf "log_%s.log" timestamp_str) 163 166 in 164 167 let log_channel = open_out_gen [ Open_append; Open_creat ] 0o644 log_file in 165 168 log_channel