Fix looking up a commit's tree
We were generating the term from the wrong object, meaning the system was not keeping the object we should be. We were also not setting the repository or increasing its refcount, meaning bad news when it came time to GC the object.
This commit is contained in:
@@ -30,7 +30,7 @@ geef_commit_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
ErlNifBinary bin;
|
||||
geef_object *obj, *tree;
|
||||
ERL_NIF_TERM term_obj;
|
||||
ERL_NIF_TERM term_tree;
|
||||
|
||||
if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
|
||||
return enif_make_badarg(env);
|
||||
@@ -40,13 +40,16 @@ geef_commit_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
if (git_commit_tree((git_tree **) &tree->obj, (git_commit *) obj->obj) < 0)
|
||||
return geef_error(env);
|
||||
|
||||
term_obj = enif_make_resource(env, obj);
|
||||
enif_release_resource(obj);
|
||||
term_tree = enif_make_resource(env, tree);
|
||||
enif_release_resource(tree);
|
||||
|
||||
if (geef_oid_bin(&bin, git_object_id(tree->obj)) < 0)
|
||||
return geef_oom(env);
|
||||
|
||||
return enif_make_tuple3(env, atoms.ok, enif_make_binary(env, &bin), term_obj);
|
||||
tree->repo = obj->repo;
|
||||
enif_keep_resource(tree->repo);
|
||||
|
||||
return enif_make_tuple3(env, atoms.ok, enif_make_binary(env, &bin), term_tree);
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
|
||||
@@ -7,7 +7,8 @@ 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_message_test/1]}.
|
||||
fun commit_create_test/1, fun commit_message_test/1,
|
||||
fun commit_tree_test/1]}.
|
||||
|
||||
start() ->
|
||||
{A, B, C} = now(),
|
||||
@@ -111,6 +112,13 @@ commit_message_test(Repo) ->
|
||||
Resp = geef_commit:message(Commit),
|
||||
[?_assertMatch({ok, <<"Commit message">>}, Resp)].
|
||||
|
||||
commit_tree_test(Repo) ->
|
||||
commit_create_test(Repo),
|
||||
CommitId = geef_oid:parse("bf968373f95f8fed2a24f9d25ebf06521359c6bc"),
|
||||
{ok, Commit} = geef_commit:lookup(Repo, CommitId),
|
||||
Resp = geef_commit:tree(Commit),
|
||||
[?_assertMatch({ok, _}, Resp)].
|
||||
|
||||
rm_r(Path) ->
|
||||
case filelib:is_dir(Path) of
|
||||
false ->
|
||||
|
||||
Reference in New Issue
Block a user