summaryrefslogtreecommitdiff
path: root/lib/resolvers.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/resolvers.ml')
-rw-r--r--lib/resolvers.ml61
1 files changed, 30 insertions, 31 deletions
diff --git a/lib/resolvers.ml b/lib/resolvers.ml
index 9baa116..f7bf31a 100644
--- a/lib/resolvers.ml
+++ b/lib/resolvers.ml
@@ -31,7 +31,7 @@ module Commit = struct
let to_t c =
let open Store.Value in
{
- hash = Store.Value.Commit.digest c |> Store.Hash.to_hex;
+ hash = Commit.digest c |> Store.Hash.to_hex;
parents = Commit.parents c |> List.map Store.Hash.to_hex;
author = Commit.author c;
message = Commit.message c;
@@ -64,36 +64,35 @@ module Commit = struct
walk [] head_commit.hash n
end
-(* module Branch = struct *)
-(* type t = { hash : string; name : string } *)
-
-(* let to_t (branch : Store.Reference.t) = *)
-(* { *)
-(* hash = Store.Reference.hash branch ; *)
-(* name = Store.Reference.contents branch; *)
-(* } *)
-
-(* let of_id repo id = *)
-(* let* store = store repo in *)
-(* let hash = Store.Hash.of_hex id in *)
-(* Store.Ref.resolve store hash *)
-(* |> Lwt_result.map @@ function *)
-(* | Git.Reference.Ref branch -> to_t branch *)
-(* | _ -> failwith "no head tree id" *)
-
-(* let all repo = *)
-(* let* store = store repo in *)
-(* let* refs = Store.Ref.list store in *)
-(* let branches = *)
-(* List.map *)
-(* (fun (reference, hash) -> *)
-(* let name = Git.Reference.to_string reference in *)
-(* let hash = Store.Hash.to_hex hash in *)
-(* { name; hash }) *)
-(* refs *)
-(* in *)
-(* Lwt_result.return branches *)
-(* end *)
+module Branch = struct
+ type t = { name : string; hash : string }
+
+ let to_t (reference, hash) = { name = reference; hash }
+
+ let all repo =
+ let* store = store repo in
+ let open Lwt.Syntax in
+ let* refs = Store.Ref.list store in
+ let branches =
+ List.map
+ (fun (reference, hash) ->
+ let name = Git.Reference.to_string reference in
+ let hash = Store.Hash.to_hex hash in
+ { name; hash })
+ refs
+ in
+ Lwt_result.return branches
+
+ let of_id repo id =
+ let* branches = all repo in
+ let branch =
+ branches
+ |> List.find_opt (fun branch -> Filename.basename branch.name = id)
+ in
+ match branch with
+ | Some branch -> Lwt_result.return branch
+ | None -> Lwt_result.fail @@ `Msg ("Found no branch matching " ^ id)
+end
module Entry = struct
type t = { hash : string; name : string; perm : int }
Copyright 2019--2025 Marius PETER