[OCaml] Mobile-friendly clone of cgit.
refactor merge read_root_readme/read_subdir_readme
Extract read_readme_in as a shared helper parameterized by directory. Both read_root_readme and read_subdir_readme are now one-liners.
lib/resolvers.ml
@@ -762,14 +762,14 @@
762
762
| _ -> Lwt_result.fail (Internal ("could not read file " ^ entry.name)))
763
763
end
764
764
765
Removed:
let read_root_readme config =
765
Added:
let read_readme_in dir =
766
766
let readme_candidates =
767
767
[ "README"; "README.md"; "README.org"; "README.txt" ]
768
768
in
769
769
let rec try_candidates = function
770
770
| [] -> None
771
771
| name :: rest -> (
772
Removed:
let path = Filename.concat config.Config.git_project_root name in
772
Added:
let path = Filename.concat dir name in
773
773
try
774
774
let content = In_channel.with_open_text path In_channel.input_all in
775
775
Some { Blob.content }
@@ -777,6 +777,8 @@
777
777
in
778
778
try_candidates readme_candidates
779
779
780
Added:
let read_root_readme config = read_readme_in config.Config.git_project_root
781
Added:
780
782
let scan_subdirectory config subdir =
781
783
let full_path = Filename.concat config.Config.git_project_root subdir in
782
784
if not (Sys.file_exists full_path && Sys.is_directory full_path) then
@@ -784,17 +786,4 @@
784
786
else scan_directory full_path
785
787
786
788
let read_subdir_readme config subdir =
787
Removed:
let readme_candidates =
788
Removed:
[ "README"; "README.md"; "README.org"; "README.txt" ]
789
Removed:
in
790
Removed:
let base = Filename.concat config.Config.git_project_root subdir in
791
Removed:
let rec try_candidates = function
792
Removed:
| [] -> None
793
Removed:
| name :: rest -> (
794
Removed:
let path = Filename.concat base name in
795
Removed:
try
796
Removed:
let content = In_channel.with_open_text path In_channel.input_all in
797
Removed:
Some { Blob.content }
798
Removed:
with Sys_error _ -> try_candidates rest)
799
Removed:
in
800
Removed:
try_candidates readme_candidates
789
Added:
read_readme_in (Filename.concat config.Config.git_project_root subdir)