Add oid_parse(Sha)
This commit is contained in:
28
c_src/oid.c
28
c_src/oid.c
@@ -1,7 +1,18 @@
|
||||
#include <git2.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "geef.h"
|
||||
#include "oid.h"
|
||||
|
||||
int geef_oid_bin(ErlNifBinary *bin, const git_oid *id)
|
||||
{
|
||||
if (!enif_alloc_binary(GIT_OID_RAWSZ, bin))
|
||||
return -1;
|
||||
|
||||
memcpy(bin->data, id, GIT_OID_RAWSZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_oid_fmt(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
@@ -22,3 +33,20 @@ geef_oid_fmt(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
return enif_make_binary(env, &bin_out);
|
||||
}
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_oid_parse(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
ErlNifBinary bin, bin_out;
|
||||
git_oid id;
|
||||
|
||||
if (!enif_inspect_binary(env, argv[0], &bin))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
git_oid_fromstrn(&id, (const char *)bin.data, bin.size);
|
||||
|
||||
if (geef_oid_bin(&bin_out, &id) < 0)
|
||||
return atoms.error;
|
||||
|
||||
return enif_make_binary(env, &bin_out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user