[OCaml] Mobile-friendly clone of cgit.
Start proper implementation of git helper functions.
lib/git_helpers.ml
@@ -1,27 +1,21 @@
1
Removed:
open Lwt.Infix
1
Added:
type commit_info = {
2
Added:
hash : string;
3
Added:
message : string option;
4
Added:
author : string;
5
Added:
date : string;
6
Added:
}
2
7
3
8
let full_path path = Filename.concat Config.git_directory path
4
9
5
Removed:
let head_commit_hash repo_path =
6
Removed:
let%lwt store_result = Git_unix.Store.v @@ Fpath.v @@ full_path repo_path in
7
Removed:
match store_result with
8
Removed:
| Error _ -> Lwt.return_error "Could not open the Git repository."
9
Removed:
| Ok store -> (
10
Removed:
Git_unix.Store.Ref.resolve store Git.Reference.head >|= function
11
Removed:
| Error _ -> Error ("Failed to resolve HEAD for repo " ^ repo_path)
12
Removed:
| Ok hash -> Ok (Git_unix.Store.Hash.to_hex hash))
10
Added:
let store repo_path =
11
Added:
let path = Fpath.v @@ full_path repo_path in
12
Added:
Git_unix.Store.v ~dotgit:path path
13
13
14
Removed:
let latest_commits repo_path count =
15
Removed:
let cmd =
16
Removed:
Printf.sprintf "git -C %s log --pretty=format:'%%ad %%s' --date=short -n %d"
17
Removed:
(full_path repo_path) count
18
Removed:
in
19
Removed:
Lwt.catch
20
Removed:
(fun () ->
21
Removed:
let%lwt output = Lwt_process.pread ("", [| "sh"; "-c"; cmd |]) in
22
Removed:
let lines = String.split_on_char '\n' output in
23
Removed:
Lwt.return_ok lines)
24
Removed:
(fun exn -> Lwt.return_error (Printexc.to_string exn))
14
Added:
let latest_commits repo_path ~count =
15
Added:
let open Lwt_result.Syntax in
16
Added:
let* store_result = store repo_path in
17
Added:
let* commits = Git.Commit.Make in
18
Added:
commits
25
19
26
20
let all_branches repo_path =
27
21
let cmd =