diff options
Diffstat (limited to 'lib/git_unhelpers.ml')
-rw-r--r-- | lib/git_unhelpers.ml | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/git_unhelpers.ml b/lib/git_unhelpers.ml index 28d4d3a..5b55c16 100644 --- a/lib/git_unhelpers.ml +++ b/lib/git_unhelpers.ml @@ -1,11 +1,17 @@ (* These will be reimplemented using OCaml's Git library, one day... *) -let get_git_log repo_path = +let get_latest_commits repo_path count = + let open Printf in let full_path = Filename.concat Config.git_directory repo_path in let full_cmd = - let cmd = Printf.sprintf "git -C %s log" full_path in - let options = [ "--pretty=format:'%ad %s'"; "--date=short"; "-n 10" ] in - String.concat " " (cmd :: options) + let command = sprintf "git -C %s log" full_path in + let options = + let format = "--pretty=format:'%ad %s'" in + let date = "--date=short" in + let count = sprintf "-n %s" (string_of_int count) in + [ format; date; count ] + in + String.concat " " (command :: options) in let ic = Unix.open_process_in full_cmd in let rec read_lines acc = @@ -17,3 +23,24 @@ let get_git_log repo_path = List.rev acc in read_lines [] + +let get_all_branches repo_path = + let open Printf in + let full_path = Filename.concat Config.git_directory repo_path in + let full_cmd = sprintf "git -C %s branch" full_path in + let ic = Unix.open_process_in full_cmd in + let rec read_lines acc = + try + let line = input_line ic |> String.trim in + let clean_line = + if String.length line > 2 && String.sub line 0 2 = "* " then + String.sub line 2 (String.length line - 2) + (* Remove "* " from active branch *) + else line + in + read_lines (clean_line :: acc) + with End_of_file -> + ignore (Unix.close_process_in ic); + List.rev acc + in + read_lines [] |