From d76f1e87f21fb8ec46a7a9e99e1c19085b1744d9 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Mon, 24 May 2010 17:09:32 -0700 Subject: [PATCH] actually loading and running some libgit2 code --- .gitignore | 3 +++ Makefile | 2 ++ geef.c | 10 ++++++++++ test | 13 ++++--------- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9214bc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.beam +*.so +*.o diff --git a/Makefile b/Makefile index 43a1b54..b8ffcb5 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ INCLUDES = -I$(OTPROOT)/erts/emulator/beam/ # OS X flags. GCCFLAGS = -O3 -fPIC -bundle -flat_namespace -undefined suppress -fno-common -Wall -m32 +LIBS = -lz -lgit2 + # Linux Flags #GCCFLAGS = -O3 -fPIC -shared -fno-common -Wall diff --git a/geef.c b/geef.c index 1b96896..4d574e8 100644 --- a/geef.c +++ b/geef.c @@ -1,4 +1,8 @@ #include "erl_nif.h" +#include +#include +#include + static int load(ErlNifEnv* env, void** priv, ERL_NIF_TERM load_info) @@ -28,6 +32,12 @@ unload(ErlNifEnv* env, void* priv) static ERL_NIF_TERM object_exists(ErlNifEnv* env, ERL_NIF_TERM a1) { + git_oid oid; + static char *sha = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"; + printf("sha: %s\n", sha); + git_oid_mkstr(&oid, sha); + //printf("raw: %s", (&oid)->id); + unsigned long val; if(!enif_get_ulong(env, a1, &val)) { return enif_make_badarg(env); diff --git a/test b/test index 3fb7bed..a3459a4 100755 --- a/test +++ b/test @@ -3,18 +3,13 @@ %%! debug verbose -noshell main([Object]) -> - try - geef:start(), - Test = geef:object_exists(4), - io:format("factorial ~s:~w~n", [Object, Test]) - catch - _:_ -> - usage() - end; + geef:start(), + Test = geef:object_exists(4), + io:format("exists ~s:~w~n", [Object, Test]); main(_) -> usage(). usage() -> - io:format("usage: factorial integer\n"), + io:format("usage: ./test SHA\n"), halt(1).