summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-06-09 18:12:49 +0200
committerMarius Peter <marius.peter@tutanota.com>2025-06-09 18:12:49 +0200
commitacf181316989cabc6ea16b42537eec8b03257187 (patch)
tree02149598d5c357257908a6c16ca9f6416175f67f
parent50960c7ccbae4a4e8f4f53010543752635b4d8cd (diff)
Refactor miscellaneous functions.
-rw-r--r--lib/git_presenters.ml15
-rw-r--r--lib/handlers.ml29
-rw-r--r--lib/views.ml17
3 files changed, 29 insertions, 32 deletions
diff --git a/lib/git_presenters.ml b/lib/git_presenters.ml
index 215e9c5..e098ecc 100644
--- a/lib/git_presenters.ml
+++ b/lib/git_presenters.ml
@@ -2,8 +2,8 @@
module Store = Git_unix.Store
open Lwt_result.Syntax
-open Config
open Lwt_result.Infix
+open Config
let full_path path = Filename.concat config.git_project_root path
@@ -29,8 +29,7 @@ type commit = {
}
let to_commit store hash =
- let* v = Store.read store hash in
- match v with
+ Store.read store hash >>= function
| Git.Value.Commit c ->
let hash = Store.Hash.to_hex hash in
Lwt_result.return
@@ -102,14 +101,12 @@ let to_entry (entry : Store.Value.Tree.entry) =
let short_hash = String.sub hash 0 8 in
{ hash; short_hash; name = entry.name; perm }
-let present_tree tree = Store.Value.Tree.to_list tree |> List.map to_entry
-
let to_tree store hash =
Store.read store hash >>= function
| Git.Value.Tree tree ->
let hash = Store.Hash.to_hex hash in
let short_hash = String.sub hash 0 8 in
- let entries = present_tree tree in
+ let entries = Store.Value.Tree.to_list tree |> List.map to_entry in
Lwt_result.return { hash; short_hash; entries }
| _ -> Lwt_result.fail (`Msg "value is not a tree")
@@ -118,7 +115,7 @@ let to_blob store hash =
| Git.Value.Blob blob ->
let content = Store.Value.Blob.to_string blob in
Lwt_result.return { content }
- | _ -> Lwt_result.fail (`Msg "value is not a tree")
+ | _ -> Lwt_result.fail (`Msg "value is not a blob")
let head_tree_id store =
Store.Ref.resolve store Git.Reference.head >>= Store.read store >>= function
@@ -133,10 +130,10 @@ let head_tree repo =
let tree_of_id repo id =
let* store = store repo in
- let* hash = Lwt_result.return (Store.Hash.of_hex id) in
+ let hash = Store.Hash.of_hex id in
to_tree store hash
let blob_of_id repo id =
let* store = store repo in
- let* hash = Lwt_result.return (Store.Hash.of_hex id) in
+ let hash = Store.Hash.of_hex id in
to_blob store hash
diff --git a/lib/handlers.ml b/lib/handlers.ml
index 21d3ea8..7d2fe8d 100644
--- a/lib/handlers.ml
+++ b/lib/handlers.ml
@@ -22,27 +22,27 @@ module Repo = struct
let authors = [ "John Pork"; "Sebastian Jellybean" ] in
Views.Repo.summary (repo req) branches commits authors |> Dream_html.respond
- let refs req =
- let* branches = all_branches (repo req) in
- Views.Repo.refs (repo req) branches |> Dream_html.respond
-
let log req =
let* commits = recent_commits (repo req) 100 in
Views.Repo.log (repo req) commits |> Dream_html.respond
- let tree_head req =
+ let files_at_head req =
let* tree = head_tree (repo req) in
- Views.Repo.tree (repo req) tree |> Dream_html.respond
+ Views.Repo.files (repo req) tree |> Dream_html.respond
- let tree_id req =
+ let files_id req =
let id = id_of_req req in
let* tree = tree_of_id (repo req) id in
- Views.Repo.tree (repo req) tree |> Dream_html.respond
+ Views.Repo.files (repo req) tree |> Dream_html.respond
- let blob_id req =
+ let file_id req =
let id = id_of_req req in
let* blob = blob_of_id (repo req) id in
- Views.Repo.blob (repo req) blob |> Dream_html.respond
+ Views.Repo.file (repo req) blob |> Dream_html.respond
+
+ let refs req =
+ let* branches = all_branches (repo req) in
+ Views.Repo.refs (repo req) branches |> Dream_html.respond
let commit req =
let id = id_of_req req in
@@ -58,11 +58,12 @@ let all_handlers =
Repo.
[
get "/" summary;
- get "/refs/" refs;
+ get "/summary/" summary;
get "/log/" log;
- get "/tree/" tree_head;
- get "/tree/:id" tree_id;
- get "/blob/:id" blob_id;
+ get "/files/" files_at_head;
+ get "/files/:id" files_id;
+ get "/file/:id" file_id;
+ get "/refs/" refs;
get "/commit/:id" commit;
];
get "/static/**" (static "./lib/static");
diff --git a/lib/views.ml b/lib/views.ml
index ba87571..1e0a858 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -76,7 +76,7 @@ let root () =
let all_repositories =
let repos =
Sys.readdir config.git_project_root
- |> Array.to_list |> List.sort String.compare
+ |> Array.to_list (* |> List.sort String.compare *)
in
let li_of_repo repo =
HTML.li [] [ Routes.link_to (Routes.Repo repo) (txt "%s" repo) ]
@@ -100,8 +100,7 @@ module Repo = struct
let li_of_author author = HTML.(li [] [ txt "%s" author ])
let li_of_branch repo (branch : branch) =
- HTML.(
- li [] [ Routes.link_to (Tag (repo, branch.name)) (txt "%s" branch.name) ])
+ HTML.(li [] [ Routes.link_to (Refs repo) (txt "%s" branch.name) ])
let li_of_commit repo commit =
let open HTML in
@@ -124,8 +123,8 @@ module Repo = struct
if entry.perm = 0o040000 then entry.name ^ "/" else entry.name
in
let route =
- if entry.perm = 0o040000 then Routes.Tree (repo, entry.hash)
- else Routes.Blob (repo, entry.hash)
+ if entry.perm = 0o040000 then Routes.Files repo
+ else Routes.File (repo, entry.hash)
in
HTML.(li [] [ Routes.link_to route @@ txt "%s" display_name ])
@@ -135,7 +134,7 @@ module Repo = struct
[
h3 [] [ txt "Branches" ];
ul [] (List.map (li_of_branch repo) branches);
- h3 [] [ txt "Recent commits" ];
+ h3 [] [ txt "Latest commits" ];
ul [] (List.map (li_of_commit repo) commits);
h3 [] [ txt "Authors" ];
ul [] (List.map li_of_author authors);
@@ -181,12 +180,12 @@ module Repo = struct
content;
}
- let tree repo tree =
+ let files repo tree =
let title = Printf.sprintf "%s" repo in
let content =
HTML.
[
- h3 [] [ txt "Tree %s" tree.short_hash ];
+ h3 [] [ txt "Files %s" tree.short_hash ];
ul [] (List.map (li_of_entry repo) tree.entries);
]
in
@@ -219,7 +218,7 @@ module Repo = struct
{
title;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.(v ~active_path:Files repo);
content;
}
Copyright 2019--2025 Marius PETER