ported code to use rebar and R14B

This commit is contained in:
Scott Chacon
2010-11-03 15:53:14 -07:00
parent fc4b19eff1
commit c1ea72abae
8 changed files with 71 additions and 44 deletions

67
c_src/geef.c Normal file
View File

@@ -0,0 +1,67 @@
#include "erl_nif.h"
#include <stdio.h>
#include <git/commit.h>
#include <git/tag.h>
#include <git/common.h>
#include <git/errors.h>
#include <git/index.h>
#include <git/odb.h>
#include <git/oid.h>
#include <git/revwalk.h>
#include <git/repository.h>
#include <git/zlib.h>
#define MAXBUFLEN 1024
static ERL_NIF_TERM
geef_hex_to_raw(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
char sha[MAXBUFLEN];
(void)memset(&sha, '\0', sizeof(sha));
if (enif_get_string(env, argv[0], sha, sizeof(sha), ERL_NIF_LATIN1) < 1)
return enif_make_badarg(env);
git_oid oid;
git_oid_mkstr(&oid, sha);
ErlNifBinary ibin;
enif_alloc_binary(20, &ibin);
memcpy(ibin.data, (&oid)->id, 20);
return enif_make_binary(env, &ibin);
}
static ERL_NIF_TERM
geef_object_exists(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
char path[MAXBUFLEN];
char sha[MAXBUFLEN];
(void)memset(&path, '\0', sizeof(path));
(void)memset(&sha, '\0', sizeof(sha));
if (enif_get_string(env, argv[0], path, sizeof(path), ERL_NIF_LATIN1) < 1)
return enif_make_badarg(env);
if (enif_get_string(env, argv[1], sha, sizeof(sha), ERL_NIF_LATIN1) < 1)
return enif_make_badarg(env);
git_odb *odb;
git_odb_open(&odb, path);
git_oid oid;
git_oid_mkstr(&oid, sha);
int exists = git_odb_exists(odb, &oid);
if(exists == 1) {
return enif_make_atom(env, "true");
}
return enif_make_atom(env, "false");
}
static ErlNifFunc geef_funcs[] =
{
{"hex_to_raw", 1, geef_hex_to_raw},
{"object_exists", 2, geef_object_exists}
};
ERL_NIF_INIT(geef, geef_funcs, NULL, NULL, NULL, NULL)