Add geef_odb:write
This commit is contained in:
@@ -89,6 +89,7 @@ static ErlNifFunc geef_funcs[] =
|
||||
{"repository_get_workdir", 1, geef_repository_workdir},
|
||||
{"repository_get_odb", 1, geef_repository_odb},
|
||||
{"odb_object_exists", 2, geef_odb_exists},
|
||||
{"odb_write", 3, geef_odb_write},
|
||||
{"reference_list", 1, geef_reference_list},
|
||||
{"reference_to_id", 2, geef_reference_to_id},
|
||||
{"reference_glob", 2, geef_reference_glob},
|
||||
|
||||
@@ -28,6 +28,20 @@ ERL_NIF_TERM geef_object_type2atom(const git_otype type)
|
||||
}
|
||||
}
|
||||
|
||||
git_otype geef_object_atom2type(ERL_NIF_TERM term)
|
||||
{
|
||||
if (!enif_compare(term, atoms.commit))
|
||||
return GIT_OBJ_COMMIT;
|
||||
else if (!enif_compare(term, atoms.tree))
|
||||
return GIT_OBJ_TREE;
|
||||
else if (!enif_compare(term, atoms.blob))
|
||||
return GIT_OBJ_BLOB;
|
||||
else if (!enif_compare(term, atoms.tag))
|
||||
return GIT_OBJ_TAG;
|
||||
|
||||
return GIT_OBJ_BAD;
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_object_lookup(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ ERL_NIF_TERM geef_object_lookup(ErlNifEnv *env, int argc, const ERL_NIF_TERM arg
|
||||
ERL_NIF_TERM geef_object_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
|
||||
ERL_NIF_TERM geef_object_type2atom(const git_otype type);
|
||||
git_otype geef_object_atom2type(ERL_NIF_TERM term);
|
||||
|
||||
void geef_object_free(ErlNifEnv *env, void *cd);
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "repository.h"
|
||||
#include "object.h"
|
||||
#include "oid.h"
|
||||
#include "geef.h"
|
||||
#include <string.h>
|
||||
#include <git2.h>
|
||||
@@ -191,3 +193,27 @@ geef_odb_exists(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
return atoms.false;
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_odb_write(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
git_otype type;
|
||||
git_oid oid;
|
||||
geef_odb *odb;
|
||||
ErlNifBinary contents, oid_bin;
|
||||
|
||||
if (!enif_get_resource(env, argv[0], geef_odb_type, (void **) &odb))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
if (!enif_inspect_iolist_as_binary(env, argv[1], &contents))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
type = geef_object_atom2type(argv[2]);
|
||||
if (git_odb_write(&oid, odb->odb, contents.data, contents.size, type) < 0)
|
||||
return geef_error(env);
|
||||
|
||||
if (geef_oid_bin(&oid_bin, &oid) < 0)
|
||||
return atoms.error;
|
||||
|
||||
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &oid_bin));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ ERL_NIF_TERM geef_repository_workdir(ErlNifEnv *env, int argc, const ERL_NIF_TER
|
||||
ERL_NIF_TERM geef_repository_is_bare(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_repository_odb(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_odb_exists(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
ERL_NIF_TERM geef_odb_write(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
|
||||
|
||||
void geef_repository_free(ErlNifEnv *env, void *cd);
|
||||
|
||||
Reference in New Issue
Block a user