···11type rev_id = {
22 change_id : string
33 ; commit_id : string
44+55+ ; divergent : bool(** Indicates the changeid is conflicted and we must use the commitid *)
46}
5768type 'a maybe_unique =
+59-46
jj_tui/lib/process_wrappers.ml
···1111exception FoundStart
1212exception FoundFiller
13131414-(** Function to tag duplicated items in a list *)
1515-let tag_duplicates lst =
1616- (* Create a frequency map to count occurrences of each element *)
1717- let freq_map =
1818- List.fold_left
1919- (fun acc { change_id; _ } ->
2020- let count = try List.assoc change_id acc with Not_found -> 0 in
2121- (change_id, count + 1) :: List.remove_assoc change_id acc)
2222- []
2323- lst
2424- in
2525- (* Tag each item in the list based on the frequency map *)
2626- List.map
2727- (fun ({ change_id; _ } as x) ->
2828- if List.assoc change_id freq_map > 1 then Duplicate x else Unique x)
2929- lst
3030-;;
3131-3214(** Matches any basic ansi escape codes*)
3315let ansi_regex =
3416 let open Re in
···4830 in
4931 Re.compile pattern
5032;;
3333+5134(** Removes any found ansi escape codes*)
5235let remove_ansi str = str |> Re.replace_string ~by:"" ansi_regex
3636+5337let count_ansi str = str |> Re.all ansi_regex |> List.length
54385539let find_selectable_from_graph str =
5656-5757-(** Matches a single revision in the format specificied by the graph template *)
4040+ (* Matches a single revision in the format specificied by the graph template *)
5841 let matches =
5942 str
6043 |> Re.split_full
6144 (Re.Pcre.regexp
6245 ~flags:[ Re.Pcre.(`MULTILINE) ]
6363- {|(^.*?)\$\$--START--\$\$\|(.+?)\|(.+?)\|([\s\S]*?)\$\$--END--\$\$\n?|})
4646+ {|(^.*?)\$\$--START--\$\$\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|([\s\S]*?)\$\$--END--\$\$\n?|})
6447 in
6548 let graph, ids =
6649 matches
6750 |> List.fold_left
6851 (fun (graph_acc, ids_acc) chunk ->
6969- match chunk with
7070- | `Delim selectable ->
7171- let graph_bit = Re.Group.get selectable 1 in
7272- (* In future we should be able to use the strifify function in ocaml*)
7373- let change_id = Re.Group.get selectable 2 |> remove_ansi in
7474- let commit_id = Re.Group.get selectable 3 |> remove_ansi in
7575- let content = Re.Group.get selectable 4 in
7676- ( `Selectable (graph_bit ^ content) :: graph_acc
7777- , { change_id; commit_id } :: ids_acc )
7878- | `Text filler -> (*Anything between our match is non-selectable filler*)
7979- if filler = ""
8080- then
8181- graph_acc, ids_acc
8282- else `Filler filler :: graph_acc, ids_acc)
5252+ match chunk with
5353+ | `Delim selectable ->
5454+ let graph_bit = Re.Group.get selectable 1 in
5555+ (* In future we should be able to use the strifify function in ocaml*)
5656+ let change_id = Re.Group.get selectable 2 |> remove_ansi in
5757+ let commit_id = Re.Group.get selectable 3 |> remove_ansi in
5858+ let divergent =
5959+ match Re.Group.get selectable 4 |> remove_ansi with
6060+ | "true" ->
6161+ true
6262+ | "false" ->
6363+ false
6464+ | content ->
6565+ failwith @@ "Couldn't parse jj divergent value:" ^ content
6666+ in
6767+ let hidden =
6868+ match Re.Group.get selectable 5 |> remove_ansi with
6969+ | "true" ->
7070+ true
7171+ | "false" ->
7272+ false
7373+ | content ->
7474+ failwith @@ "Couldn't parse jj divergent value:" ^ content
7575+ in
7676+ [%log
7777+ debug
7878+ "parsed rev: change_id: %s commit_id: %s divergent: %s"
7979+ change_id
8080+ commit_id
8181+ (Re.Group.get selectable 6 |> remove_ansi)];
8282+ let rev = { commit_id; change_id; divergent } in
8383+ let id = if divergent || hidden then Duplicate commit_id else Unique change_id in
8484+ let content = Re.Group.get selectable 6 in
8585+ `Selectable (graph_bit ^ content) :: graph_acc, id :: ids_acc
8686+ | `Text filler ->
8787+ (*Anything between our match is non-selectable filler*)
8888+ if filler = ""
8989+ then graph_acc, ids_acc
9090+ else `Filler filler :: graph_acc, ids_acc)
8391 ([], [])
8492 |> fun (graph, ids) -> List.rev graph |> Array.of_list, List.rev ids
8593 in
8686- let revs = ids |> tag_duplicates in
9494+ let revs = ids in
8795 graph, revs
8896;;
8997···97105 end) =
98106struct
99107 open Process
100100-(* Currently hard-coded. Soon it'l be settable in config *)
108108+109109+ (* Currently hard-coded. Soon it'l be settable in config *)
101110 let base_graph_template =
102111 {|if(root,
103112 format_root_commit(self),
···115124 )
116125)|}
117126 ;;
118118-119119- let graph_info_template node_template=
120120- {|"$$--START--$$"++"|"++change_id++"|"++commit_id++"|"++|}
127127+128128+ let graph_info_template node_template =
129129+ {|"$$--START--$$"++"|"++change_id++"|"++commit_id++"|"++divergent++"|"++hidden++"|"++|}
121130 ^ node_template
122131 ^ {|++"$$--END--$$"++""|}
123132 ;;
124133125134 let get_graph_info node_template revset_arg =
126126- let output = jj_no_log ([ "log"; "-T"; graph_info_template node_template] @ revset_arg) in
135135+ let output =
136136+ jj_no_log ([ "log"; "-T"; graph_info_template node_template ] @ revset_arg)
137137+ in
127138 output |> find_selectable_from_graph
128139 ;;
129140···142153end
143154144155(*========Tests======*)
145145-146156147157let test_data_3 =
148158 {|@ $$--START--$$|zqtxnkuuryqzzolyksrylpzotmplmvus|8ee443e4a374f7dfdd00494d8bf71af6162a1300|zqtxnkuu eli.jambu@gmail.com 2025-02-15 21:22:48 8ee443e4
···203213 let id = ids.(!ids_idx) in
204214 (match id with
205215 | Unique id ->
206206- id.change_id |> print_endline;
207207- id.commit_id |> print_endline
216216+ (* id.change_id |> print_endline; *)
217217+ (* id.commit_id |> print_endline *)
218218+ id|>print_endline
208219 | Duplicate id ->
209209- id.change_id |> print_endline;
210210- id.commit_id |> print_endline);
220220+ (* id.change_id |> print_endline; *)
221221+ (* id.commit_id |> print_endline); *)
222222+ id|>print_endline
223223+ );
211224 incr ids_idx;
212225 x |> print_endline);
213226 [%expect