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.

Enforce limit to the number of commits

The limit can be configured in the config using the
max_commits setting

+48 -33
+7 -5
jj_tui/bin/graph_view.ml
··· 12 12 module Process = Jj_process.Make (Vars) 13 13 open Process 14 14 open Jj_tui.Process_wrappers.Make (Process) 15 - 15 + 16 16 (* Import graph commands *) 17 17 module GraphCommands = Graph_commands.Make (Vars) 18 - 18 + 19 19 let bookmark_select_prompt get_bookmark_list name func = 20 20 Selection_prompt 21 21 ( name ··· 33 33 34 34 (* Remove the hardcoded make_command_mapping function and use the dynamic one *) 35 35 let command_mapping = ref None 36 - 36 + 37 37 let rec get_command_mapping () = 38 38 match !command_mapping with 39 - | Some mapping -> mapping 39 + | Some mapping -> 40 + mapping 40 41 | None -> 41 42 let key_map = (Lwd.peek ui_state.config).key_map.graph in 42 43 let registry = GraphCommands.get_command_registry get_command_mapping in ··· 64 65 |> Lwd.get 65 66 |> Lwd.map2 (Lwd.get Vars.ui_state.revset) ~f:(fun revset _ -> 66 67 try 67 - let res = graph_and_revs ?revset () in 68 + let max_commits = (Vars.config |> Lwd.peek).max_commits in 69 + let res = graph_and_revs ?revset max_commits () in 68 70 error_var $= None; 69 71 res 70 72 with
+9 -12
jj_tui/lib/config.ml
··· 1 1 open Util 2 2 open Logging 3 3 4 + type t = { 5 + key_map : Key_map.key_config [@updater] 6 + ; single_pane_width_threshold : int 7 + ; max_commits: int 8 + } 9 + [@@deriving yaml, record_updater ~derive:yaml] 4 10 5 - type t = { key_map : Key_map.key_config[@updater]; single_pane_width_threshold:int } [@@deriving yaml, record_updater ~derive: yaml] 6 - 7 - 8 - let default_config:t = 9 - { 10 - key_map= Key_map.default; 11 - single_pane_width_threshold=100; 12 - } 13 - ;; 11 + let default_config : t = { key_map = Key_map.default; single_pane_width_threshold = 100; max_commits= 100} 14 12 15 13 let get_config_dir () = 16 14 let os = Os.poll_os () in ··· 29 27 Filename.concat config_home "jj_tui" 30 28 ;; 31 29 32 - 33 30 let load_config () = 34 31 [%log info "Loading config..."]; 35 32 let config_file = Filename.concat (get_config_dir ()) "config.yaml" in ··· 39 36 close_in ic; 40 37 let json = Yaml.of_string_exn content in 41 38 match t_update_t_of_yaml json with 42 - | Ok (config_update) -> 39 + | Ok config_update -> 43 40 [%log info "Config loaded!"]; 44 - default_config |> t_apply_update config_update 41 + default_config |> t_apply_update config_update 45 42 | Error (`Msg msg) -> 46 43 [%log warn "Error parsing config: %s" msg]; 47 44 default_config
+32 -16
jj_tui/lib/process_wrappers.ml
··· 36 36 37 37 let count_ansi str = str |> Re.all ansi_regex |> List.length 38 38 39 - let find_selectable_from_graph str = 39 + let find_selectable_from_graph limit str = 40 40 (* Matches a single revision in the format specificied by the graph template *) 41 41 let matches = 42 42 str ··· 45 45 ~flags:[ Re.Pcre.(`MULTILINE) ] 46 46 {|(^.*?)\$\$--START--\$\$\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|([\s\S]*?)\$\$--END--\$\$\n?|}) 47 47 in 48 - let graph, ids = 48 + let selectable_count = ref 0 in 49 + let graph_rev, ids_rev = 49 50 matches 50 51 |> List.fold_left 51 52 (fun (graph_acc, ids_acc) chunk -> ··· 63 64 false 64 65 | content -> 65 66 failwith @@ "Couldn't parse jj divergent value:" ^ content 66 - in 67 + in 67 68 let hidden = 68 69 match Re.Group.get selectable 5 |> remove_ansi with 69 70 | "true" -> ··· 80 81 commit_id 81 82 (Re.Group.get selectable 6 |> remove_ansi)]; 82 83 let rev = { commit_id; change_id; divergent } in 83 - let id = if divergent || hidden then Duplicate commit_id else Unique change_id in 84 + let id = 85 + if divergent || hidden then Duplicate commit_id else Unique change_id 86 + in 84 87 let content = Re.Group.get selectable 6 in 88 + incr selectable_count; 85 89 `Selectable (graph_bit ^ content) :: graph_acc, id :: ids_acc 86 90 | `Text filler -> 87 91 (*Anything between our match is non-selectable filler*) ··· 89 93 then graph_acc, ids_acc 90 94 else `Filler filler :: graph_acc, ids_acc) 91 95 ([], []) 92 - |> fun (graph, ids) -> List.rev graph |> Array.of_list, List.rev ids 93 96 in 94 - let revs = ids in 95 - graph, revs 97 + let graph = 98 + (if !selectable_count >= (limit) 99 + then ( 100 + [%log debug "limit: %d selectable: %d" limit !selectable_count]; 101 + let txt = 102 + Printf.sprintf 103 + "\nHit limit of %d items.\nIncrease limit in config or make your revset more \ 104 + precise\n" 105 + limit 106 + in 107 + `Filler txt :: graph_rev) 108 + else graph_rev) 109 + |> List.rev 110 + |> Array.of_list 111 + in 112 + graph, ids_rev |> List.rev 96 113 ;; 97 114 98 115 module Make (Process : sig ··· 131 148 ^ {|++"$$--END--$$"++""|} 132 149 ;; 133 150 134 - let get_graph_info node_template revset_arg = 151 + let get_graph_info node_template revset_arg limit = 135 152 let output = 136 - jj_no_log ([ "log"; "-T"; graph_info_template node_template ] @ revset_arg) 153 + jj_no_log ([ "log"; "-T"; graph_info_template node_template;"--limit"; limit |>string_of_int] @ revset_arg) 137 154 in 138 - output |> find_selectable_from_graph 155 + output |> find_selectable_from_graph limit 139 156 ;; 140 157 141 158 (** returns the graph and a list of revs within that graph*) 142 - let graph_and_revs ?revset () = 159 + let graph_and_revs ?revset limit () = 143 160 (*We join_after here to ensure any errors in sub-fibers only propegate to here, otherwise fibers everywhere would get cancelled when an error here occurs*) 144 161 Flock.join_after @@ fun _ -> 145 162 let graph = 146 163 Flock.fork_as_promise @@ fun () -> 147 164 let revset_arg = match revset with Some revset -> [ "-r"; revset ] | None -> [] in 148 - get_graph_info base_graph_template revset_arg 165 + get_graph_info base_graph_template revset_arg limit 149 166 in 150 167 let graph, revs = Promise.await graph in 151 168 graph, revs |> Array.of_list ··· 199 216 ;; 200 217 201 218 let%expect_test "revs_graph_parsing" = 202 - let graph, ids = find_selectable_from_graph test_data_3 in 219 + let graph, ids = find_selectable_from_graph 2000 test_data_3 in 203 220 let ids = ids |> Array.of_list in 204 221 let ids_idx = ref 0 in 205 222 graph ··· 215 232 | Unique id -> 216 233 (* id.change_id |> print_endline; *) 217 234 (* id.commit_id |> print_endline *) 218 - id|>print_endline 235 + id |> print_endline 219 236 | Duplicate id -> 220 237 (* id.change_id |> print_endline; *) 221 238 (* id.commit_id |> print_endline); *) 222 - id|>print_endline 223 - ); 239 + id |> print_endline); 224 240 incr ids_idx; 225 241 x |> print_endline); 226 242 [%expect