From 906b58a2c8a0862786c4fb35eb36606baf1c9ead Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Thu, 12 Mar 2015 11:07:59 +0200 Subject: [PATCH 1/2] Update to support libgit2 0.22 --- .gitignore | 2 ++ c_src/geef.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6890eea..713629c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ rebar ebin/ .eunit +.rebar/ +_build/ \ No newline at end of file diff --git a/c_src/geef.c b/c_src/geef.c index b854e1f..e0b60ff 100644 --- a/c_src/geef.c +++ b/c_src/geef.c @@ -31,7 +31,7 @@ geef_atoms atoms; static int load(ErlNifEnv *env, void **priv, ERL_NIF_TERM load_info) { - git_threads_init(); + git_libgit2_init(); geef_repository_type = enif_open_resource_type(env, NULL, "repository_type", geef_repository_free, ERL_NIF_RT_CREATE, NULL); @@ -99,7 +99,7 @@ int upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM static void unload(ErlNifEnv* env, void* priv_data) { - git_threads_shutdown(); + git_libgit2_shutdown(); } ERL_NIF_TERM From 4b889ed3bb672406c9839b04d9d087109211d6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 24 Apr 2015 15:38:00 +0200 Subject: [PATCH 2/2] 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. --- c_src/commit.c | 11 +++++++---- test/repo_test.erl | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/c_src/commit.c b/c_src/commit.c index b1a24d7..c3e72f1 100644 --- a/c_src/commit.c +++ b/c_src/commit.c @@ -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 diff --git a/test/repo_test.erl b/test/repo_test.erl index 5069118..581f47d 100644 --- a/test/repo_test.erl +++ b/test/repo_test.erl @@ -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 ->