Select the types of activity you want to include in your feed.
precommit: Tidy code with idiomatic patterns
- Use pattern match for gitdir parsing instead of String.sub - Use List.filter_map instead of filter + map - Simplify empty string check (s <> "" vs String.length)
···9898 (* .git is a file pointing to the real git dir (worktree) *)
9999 let content = read_file ~fs git_dir_path in
100100 let line = String.trim (List.hd (String.split_on_char '\n' content)) in
101101- if String.length line > 8 && String.sub line 0 8 = "gitdir: " then
102102- String.sub line 8 (String.length line - 8)
103103- else git_dir_path
101101+ match String.split_on_char ' ' line with
102102+ | "gitdir:" :: rest -> String.concat " " rest
103103+ | _ -> git_dir_path
104104105105let init_in_dir ~fs ~dry_run dir =
106106 let dune_project = Filename.concat dir "dune-project" in
···179179180180let list_subdirs ~fs dir =
181181 Eio.Path.read_dir Eio.Path.(fs / dir)
182182- |> List.filter (fun name ->
183183- let path = Filename.concat dir name in
184184- is_directory ~fs path && name.[0] <> '.')
185185- |> List.map (fun name -> Filename.concat dir name)
182182+ |> List.filter_map (fun name ->
183183+ if name.[0] = '.' then None
184184+ else
185185+ let path = Filename.concat dir name in
186186+ if is_directory ~fs path then Some path else None)
186187 |> List.sort String.compare
187188188189let run_in_dir ~process_mgr ~fs dir cmd =
···191192 Eio.Process.parse_out process_mgr Eio.Buf_read.take_all ~cwd
192193 [ "/bin/sh"; "-c"; cmd ]
193194 in
194194- output |> String.split_on_char '\n'
195195- |> List.filter (fun s -> String.length s > 0)
195195+ output |> String.split_on_char '\n' |> List.filter (fun s -> s <> "")
196196197197type ai_commit = { hash : string; subject : string }
198198