diff options
Diffstat (limited to 'lib/git_helpers.ml')
-rw-r--r-- | lib/git_helpers.ml | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/git_helpers.ml b/lib/git_helpers.ml index 4e2215e..07b0d04 100644 --- a/lib/git_helpers.ml +++ b/lib/git_helpers.ml @@ -1,27 +1,21 @@ -open Lwt.Infix +type commit_info = { + hash : string; + message : string option; + author : string; + date : string; +} let full_path path = Filename.concat Config.git_directory path -let head_commit_hash repo_path = - let%lwt store_result = Git_unix.Store.v @@ Fpath.v @@ full_path repo_path in - match store_result with - | Error _ -> Lwt.return_error "Could not open the Git repository." - | Ok store -> ( - Git_unix.Store.Ref.resolve store Git.Reference.head >|= function - | Error _ -> Error ("Failed to resolve HEAD for repo " ^ repo_path) - | Ok hash -> Ok (Git_unix.Store.Hash.to_hex hash)) +let store repo_path = + let path = Fpath.v @@ full_path repo_path in + Git_unix.Store.v ~dotgit:path path -let latest_commits repo_path count = - let cmd = - Printf.sprintf "git -C %s log --pretty=format:'%%ad %%s' --date=short -n %d" - (full_path repo_path) count - in - Lwt.catch - (fun () -> - let%lwt output = Lwt_process.pread ("", [| "sh"; "-c"; cmd |]) in - let lines = String.split_on_char '\n' output in - Lwt.return_ok lines) - (fun exn -> Lwt.return_error (Printexc.to_string exn)) +let latest_commits repo_path ~count = + let open Lwt_result.Syntax in + let* store_result = store repo_path in + let* commits = Git.Commit.Make in + commits let all_branches repo_path = let cmd = |