Allow retrieval of a commit message
This commit is contained in:
@@ -137,3 +137,22 @@ geef_commit_create(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_commit_message(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
ErlNifBinary bin;
|
||||
geef_object *obj, *tree;
|
||||
const char *msg;
|
||||
|
||||
if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
tree = enif_alloc_resource(geef_object_type, sizeof(geef_object));
|
||||
|
||||
msg = git_commit_message((git_commit *) obj->obj);
|
||||
if (geef_string_to_bin(&bin, msg) < 0)
|
||||
return geef_error(env);
|
||||
|
||||
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
ERL_NIF_TERM geef_commit_tree_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_commit_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_commit_create(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_commit_message(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
#endif
|
||||
|
||||
@@ -192,6 +192,7 @@ static ErlNifFunc geef_funcs[] =
|
||||
{"commit_tree", 1, geef_commit_tree},
|
||||
{"commit_tree_id", 1, geef_commit_tree_id},
|
||||
{"commit_create", 8, geef_commit_create},
|
||||
{"commit_message", 1, geef_commit_message},
|
||||
{"tree_bypath", 2, geef_tree_bypath},
|
||||
{"tree_nth", 2, geef_tree_nth},
|
||||
{"tree_count", 1, geef_tree_count},
|
||||
|
||||
@@ -31,4 +31,12 @@ defmodule Geef.Commit do
|
||||
:geef_commit.create(repo, Signature.to_record(author), Signature.to_record(committer), message, tree, parents, opts)
|
||||
end
|
||||
|
||||
@spec message(t) :: {:ok, String.t} | {:error, term}
|
||||
def message(%Object{type: :commit, handle: handle}) do
|
||||
:geef_nif.commit_message(handle)
|
||||
end
|
||||
|
||||
@spec message!(t) :: String.t
|
||||
def message!(commit), do: message(commit) |> Geef.assert_ok
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
-module(geef_commit).
|
||||
-export([tree_id/1, tree/1, lookup/2]).
|
||||
-export([create/5, create/6, create/7]).
|
||||
-export([message/1]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
@@ -53,3 +54,7 @@ create(Repo, Person = #geef_signature{}, Message, Tree, Parents, Opts) ->
|
||||
|
||||
create(Repo, Person = #geef_signature{}, Message, Tree, Parents) ->
|
||||
create(Repo, Person, Person, Message, Tree, Parents, []).
|
||||
|
||||
-spec message(commit()) -> {ok, binary()} | {error, term()}.
|
||||
message(#geef_object{type=commit,handle=Handle}) ->
|
||||
geef_nif:commit_message(Handle).
|
||||
|
||||
@@ -115,6 +115,10 @@ commit_tree(_Handle) ->
|
||||
commit_create(_RepoHandle, _Ref, _Author, _Committer, _Encoding, _Message, _Tree, _Parents) ->
|
||||
?NIF_FN.
|
||||
|
||||
-spec commit_message(term) -> binary().
|
||||
commit_message(_CommitHandle) ->
|
||||
?NIF_FN.
|
||||
|
||||
-spec tree_bypath(term, iolist()) -> term().
|
||||
tree_bypath(_TreeHandle, _Path) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
@@ -7,7 +7,7 @@ repo_test_() ->
|
||||
{foreach, fun start/0, fun stop/1, [fun bare_test/1, fun odb_write_test/1,
|
||||
fun ref_test/1, fun index_add_test/1,
|
||||
fun ref_iter_test/1, fun revparse_test/1,
|
||||
fun commit_create_test/1]}.
|
||||
fun commit_create_test/1, fun commit_message_test/1]}.
|
||||
|
||||
start() ->
|
||||
{A, B, C} = now(),
|
||||
@@ -104,6 +104,13 @@ commit_create_test(Repo) ->
|
||||
Resp = geef_commit:create(Repo, Sig, Message, TreeId, []),
|
||||
[?_assertMatch({ok, CommitId}, Resp)].
|
||||
|
||||
commit_message_test(Repo) ->
|
||||
commit_create_test(Repo),
|
||||
CommitId = geef_oid:parse("bf968373f95f8fed2a24f9d25ebf06521359c6bc"),
|
||||
{ok, Commit} = geef_commit:lookup(Repo, CommitId),
|
||||
Resp = geef_commit:message(Commit),
|
||||
[?_assertMatch({ok, <<"Commit message">>}, Resp)].
|
||||
|
||||
rm_r(Path) ->
|
||||
case filelib:is_dir(Path) of
|
||||
false ->
|
||||
|
||||
Reference in New Issue
Block a user