[OCaml] Mobile-friendly clone of cgit.
fix match favorite/archived repos with or without .git suffix
Config entries like 'ogit' now match a repo directory named 'ogit.git' and vice versa. Directory entries (trailing /) still require an exact match.
lib/handlers.ml
@@ -55,18 +55,35 @@
55
55
| Resolvers.Repo { repo_name; _ } -> repo_name
56
56
| Resolvers.Directory (dir_name, _) -> dir_name ^ "/"
57
57
in
58
Added:
let strip_dot_git name =
59
Added:
if String.ends_with ~suffix:".git" name then
60
Added:
String.sub name 0 (String.length name - 4)
61
Added:
else name
62
Added:
in
63
Added:
let name_matches config_entry node_name =
64
Added:
(* Directories end with '/' — match exactly *)
65
Added:
if String.ends_with ~suffix:"/" node_name then node_name = config_entry
66
Added:
else
67
Added:
(* Repos: match with or without .git suffix *)
68
Added:
strip_dot_git node_name = strip_dot_git config_entry
69
Added:
in
70
Added:
let is_in_list config_list node =
71
Added:
let name = node_name node in
72
Added:
List.exists (fun entry -> name_matches entry name) config_list
73
Added:
in
58
74
let is_favorite node =
59
Removed:
List.mem (node_name node) config.Config.favorite_repositories
75
Added:
is_in_list config.Config.favorite_repositories node
60
76
in
61
77
let is_archived node =
62
Removed:
List.mem (node_name node) config.Config.archived_repositories
78
Added:
is_in_list config.Config.archived_repositories node
63
79
in
64
80
let favorites, rest = List.partition is_favorite nodes in
65
81
let archived, regular = List.partition is_archived rest in
66
82
(* Preserve the order specified in the config for favorites *)
67
83
let sorted_favorites =
68
84
List.filter_map
69
Removed:
(fun name -> List.find_opt (fun n -> node_name n = name) favorites)
85
Added:
(fun entry ->
86
Added:
List.find_opt (fun n -> name_matches entry (node_name n)) favorites)
70
87
config.Config.favorite_repositories
71
88
in
72
89
let readme = Resolvers.read_root_readme config in