summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-04-06 19:24:09 +0200
committerMarius Peter <marius.peter@tutanota.com>2025-04-06 19:24:09 +0200
commit1ab828cd61c355e8918ce864ba08bb2ba864be2a (patch)
treefe67f2ea032d020b0bc3e335de39335e7464b7d4
parent4d38a55e52bbb88cacb8c5f5a996c7cdbfcc75bb (diff)
Start working with utop session stashes...
Hopefully, this will increase developement velocity!
-rw-r--r--lib/handlers.ml2
-rw-r--r--lib/views.ml53
2 files changed, 12 insertions, 43 deletions
diff --git a/lib/handlers.ml b/lib/handlers.ml
index d50eca8..171cef2 100644
--- a/lib/handlers.ml
+++ b/lib/handlers.ml
@@ -6,7 +6,7 @@ let repo_root req =
let repo_tree req =
let repo_name = Dream.param req "repo_name" in
- let dir_path = Dream.query req "path" |> Option.value ~default:"" in
+ let dir_path = Dream.target req in
Views.Repo_tree.render repo_name dir_path |> Dream_html.respond
let repo_blob req =
diff --git a/lib/views.ml b/lib/views.ml
index 6621831..bbb9de5 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -101,13 +101,17 @@ module Repo_root = struct
open Dream_html
open HTML
+ let branches =
+ let repo_path = Fpath.v "/home/blendux/git.test/ogit.git/" in
+ let load_repo () = Git_unix.Store.v ~dotgit:repo_path repo_path in
+ let store = Lwt_main.run @@ load_repo () in
+ let refs = Lwt_main.run @@ Git_unix.Store.Ref.list @@ Result.get_ok store in
+ refs |> List.map fst |> List.map Git.Reference.to_string
+
let render repo_path =
let title = repo_path in
let subtitle = Filename.concat Config.git_directory repo_path in
- let all_branches = Git_unhelpers.get_all_branches repo_path in
- let li_of_branch branch =
- li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ]
- in
+ let li_of_branch hash = li [] [ txt "%s" hash ] in
let recent_commits = Git_unhelpers.get_latest_commits repo_path 10 in
let li_of_commit commit =
li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ]
@@ -115,7 +119,7 @@ module Repo_root = struct
let content =
[
h3 [] [ txt "Branches" ];
- ul [] (List.map li_of_branch all_branches);
+ ul [] (List.map li_of_branch branches);
h3 [] [ txt "Recent commits" ];
ul [] (List.map li_of_commit recent_commits);
]
@@ -159,50 +163,15 @@ module Repo_tree = struct
let display_name = if is_dir then entry ^ "/" else entry in
li [] [ a [ href "%s" link ] [ txt "%s" display_name ] ]
- (* Generate breadcrumb navigation for the directory path *)
- let breadcrumb_navigation repo_name dir_path =
- let parts = String.split_on_char '/' dir_path in
-
- let rec build_paths acc paths =
- match paths with
- | [] -> List.rev acc
- | part :: rest ->
- let new_path =
- match acc with [] -> part | _ -> List.hd acc ^ "/" ^ part
- in
- build_paths (new_path :: acc) rest
- in
-
- let breadcrumb_links =
- build_paths [] parts
- |> List.mapi (fun i path ->
- let display_name = List.nth parts i in
- a
- [ href "%s" (Printf.sprintf "/%s/tree?path=%s" repo_name path) ]
- [ txt "%s" display_name ])
- in
-
- (* Manually intersperse " / " separators *)
- let rec intersperse sep = function
- | [] -> []
- | [ x ] -> [ x ]
- | x :: xs -> x :: txt sep :: intersperse sep xs
- in
-
- match breadcrumb_links with
- | [] -> txt "/"
- | _ -> span [] (intersperse " / " breadcrumb_links)
-
(* Render function *)
let render repo_name dir_path =
let title = repo_name in
- (* Only display the repo name as the title *)
let subtitle = "Files" in
- let repo_entries = ls_dir repo_name dir_path in
+ let repo_entries = ls_dir repo_name @@ dir_path in
let content =
[
- h3 [] [ breadcrumb_navigation repo_name dir_path ];
+ txt "%s" dir_path;
ul [] (List.map (link_for_entry repo_name) repo_entries);
]
in
Copyright 2019--2025 Marius PETER