diff options
Diffstat (limited to 'lib/git_helpers.ml')
-rw-r--r-- | lib/git_helpers.ml | 51 |
1 files changed, 25 insertions, 26 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 |