diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-05-25 15:25:56 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-25 15:25:56 +0200 |
commit | 1f904a2eb07c5d98288aeb6d762f8f4668df79ca (patch) | |
tree | ea0d86f2e815c5d52fc129d054e688d5dbdc259c | |
parent | f0c8906cd19479447ff5d0c1044ecbad6ab845d6 (diff) |
Rename repo_name to repo.
-rw-r--r-- | lib/git_helpers.ml | 51 | ||||
-rw-r--r-- | lib/handlers.ml | 19 | ||||
-rw-r--r-- | lib/views.ml | 46 |
3 files changed, 57 insertions, 59 deletions
diff --git a/lib/git_helpers.ml b/lib/git_helpers.ml index 317398c..1b32735 100644 --- a/lib/git_helpers.ml +++ b/lib/git_helpers.ml @@ -1,22 +1,20 @@ -open Lwt.Infix module Store = Git_unix.Store -module Value = Git.Value - -type user_record = { name : string; email : string } let full_path path = Filename.concat Config.git_directory path -let store repo_path = - let path = Fpath.v @@ full_path repo_path in +let store repo = + let path = Fpath.v @@ full_path repo in Store.v ~dotgit:path path let short_hash hash = String.sub hash 0 8 -let repo_description repo_path = - let description_path = Filename.concat (full_path repo_path) "description" in +let repo_description repo = + let description_path = Filename.concat (full_path repo) "description" in In_channel.with_open_text description_path In_channel.input_all module Commit = struct + open Lwt_result.Syntax + type t = { hash : string; parents : string list; @@ -25,8 +23,9 @@ module Commit = struct } let of_hash store h = - Store.read store h >>= function - | Ok (Value.Commit c) -> + let* v = Store.read store h in + match v with + | Git.Value.Commit c -> Lwt_result.return { hash = Store.Hash.to_hex h; @@ -34,29 +33,25 @@ module Commit = struct author = Store.Value.Commit.author c; message = Store.Value.Commit.message c; } - | Ok _ -> Lwt_result.fail (`Msg "object is not a commit") - | Error e -> Lwt_result.fail e + | _ -> Lwt_result.fail @@ `Msg "value is not a commit" - let recent_commits repo_path n = - let open Lwt_result.Syntax in - let* store = store repo_path in + let recent_commits repo n = + let* store = store repo in let* head = Store.Ref.resolve store Git.Reference.head in let rec walk acc hash count = if count = 0 then Lwt_result.return (List.rev acc) else - of_hash store hash >>= function - | Error e -> Lwt_result.fail e - | Ok commit -> ( - match commit.parents with - | parent :: _ -> - walk (commit :: acc) (Store.Hash.of_hex parent) (count - 1) - | [] -> Lwt_result.return (List.rev (commit :: acc))) + let* commit = of_hash store hash in + match commit.parents with + | parent :: _ -> + walk (commit :: acc) (Store.Hash.of_hex parent) (count - 1) + | [] -> Lwt_result.return (List.rev (commit :: acc)) in walk [] head n - let of_id repo_path id = + let of_id repo id = let open Lwt_result.Syntax in - let* store = store repo_path in + let* store = store repo in let id = Store.Hash.of_hex id in of_hash store id end @@ -64,9 +59,9 @@ end module Branch = struct type t = { name : string } - let all_branches repo_path = + let all_branches repo = let open Lwt_result.Syntax in - let* store = Git_unix.Store.v (Fpath.v repo_path) in + let* store = Git_unix.Store.v (Fpath.v repo) in let open Lwt.Syntax in let* refs = Store.Ref.list store in let branches = @@ -75,3 +70,7 @@ module Branch = struct in Lwt_result.return branches end + +module User = struct + type t = Git.User.t +end diff --git a/lib/handlers.ml b/lib/handlers.ml index 17b9eab..a99f8ae 100644 --- a/lib/handlers.ml +++ b/lib/handlers.ml @@ -9,23 +9,22 @@ let ( let* ) m f = let root _req = Views.root () |> Dream_html.respond module Repo = struct - let repo_path req = Dream.param req "repo_name" + let repo req = Dream.param req "repo_name" let summary req = - let* branches = Git_helpers.Branch.all_branches (repo_path req) in - let* commits = Git_helpers.Commit.recent_commits (repo_path req) 10 in + let* branches = Git_helpers.Branch.all_branches (repo req) in + let* commits = Git_helpers.Commit.recent_commits (repo req) 10 in let authors = [ "John Pork"; "Sebastian Jellybean" ] in - Views.Repo.summary (repo_path req) branches commits authors - |> Dream_html.respond + Views.Repo.summary (repo req) branches commits authors |> Dream_html.respond - let refs req = Views.Repo.refs (repo_path req) |> Dream_html.respond - let log req = Views.Repo.log (repo_path req) |> Dream_html.respond - let tree req = Views.Repo.tree (repo_path req) |> Dream_html.respond + let refs req = Views.Repo.refs (repo req) |> Dream_html.respond + let log req = Views.Repo.log (repo req) |> Dream_html.respond + let tree req = Views.Repo.tree (repo req) |> Dream_html.respond let commit req = let id = match Dream.query req "id" with Some id -> id | None -> "" in - let* commit = Git_helpers.Commit.of_id (repo_path req) id in - Views.Repo.commit (repo_path req) commit |> Dream_html.respond + let* commit = Git_helpers.Commit.of_id (repo req) id in + Views.Repo.commit (repo req) commit |> Dream_html.respond end let all_handlers = diff --git a/lib/views.ml b/lib/views.ml index ccaf73b..843afdc 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -10,14 +10,14 @@ type body_data = { module Components = struct open Dream_html - let topnav repo_path = + let topnav repo = let open HTML in - let () = Dream.log "%s" ("current path is: " ^ repo_path) in + let () = Dream.log "%s" ("current path is: " ^ repo) in let li_of_a (path, text) = let () = Dream.log "%s" ("and path is: " ^ path) in - let is_active = String.ends_with ~suffix:path repo_path in + let is_active = String.ends_with ~suffix:path repo in let attrs = if is_active then [ id "active" ] else [] in - let url = Printf.sprintf "/%s/%s" repo_path path in + let url = Printf.sprintf "/%s/%s" repo path in li attrs [ a [ href "%s" url ] [ txt text ] ] in nav @@ -96,7 +96,7 @@ let root () = Page.render body_data module Repo = struct - let summary repo_path branches commits authors = + let summary repo branches commits authors = let open Dream_html in let li_of_branch branch = HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ]) @@ -129,53 +129,53 @@ module Repo = struct in Page.render { - title = repo_path; - subtitle = Git_helpers.repo_description repo_path; - topnav = Components.topnav repo_path; + title = repo; + subtitle = Git_helpers.repo_description repo; + topnav = Components.topnav repo; content; } - let refs repo_path = + let refs repo = let open Dream_html in Page.render HTML. { - title = repo_path; - subtitle = Git_helpers.repo_description repo_path; - topnav = Components.topnav repo_path; + title = repo; + subtitle = Git_helpers.repo_description repo; + topnav = Components.topnav repo; content = [ null [] ]; } - let log repo_path = + let log repo = let open Dream_html in Page.render HTML. { - title = repo_path; - subtitle = Git_helpers.repo_description repo_path; - topnav = Components.topnav repo_path; + title = repo; + subtitle = Git_helpers.repo_description repo; + topnav = Components.topnav repo; content = [ null [] ]; } - let tree repo_path = + let tree repo = let open Dream_html in Page.render HTML. { - title = repo_path; - subtitle = Git_helpers.repo_description repo_path; - topnav = Components.topnav repo_path; + title = repo; + subtitle = Git_helpers.repo_description repo; + topnav = Components.topnav repo; content = [ null [] ]; } - let commit repo_path (commit : Git_helpers.Commit.t) = + let commit repo (commit : Git_helpers.Commit.t) = let open Dream_html in let open Git_helpers in let message = match commit.message with Some msg -> msg | None -> "" in let content = HTML.[ h3 [] [ txt "%s" message ] ] in - let title = Printf.sprintf "%s : %s" repo_path (short_hash commit.hash) in + let title = Printf.sprintf "%s : %s" repo (short_hash commit.hash) in Page.render - { title; subtitle = ""; topnav = Components.topnav repo_path; content } + { title; subtitle = ""; topnav = Components.topnav repo; content } end let error_page message = |