Expose git_libgit2_version

This commit is contained in:
Carlos Martín Nieto
2013-04-01 15:08:05 +02:00
parent c2d1acbbe6
commit f41ff25a59
4 changed files with 26 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
#include "commit.h" #include "commit.h"
#include "tree.h" #include "tree.h"
#include "blob.h" #include "blob.h"
#include "library.h"
#include "geef.h" #include "geef.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -112,6 +113,7 @@ static ErlNifFunc geef_funcs[] =
{"tree_bypath", 2, geef_tree_bypath}, {"tree_bypath", 2, geef_tree_bypath},
{"blob_size", 1, geef_blob_size}, {"blob_size", 1, geef_blob_size},
{"blob_content", 1, geef_blob_content}, {"blob_content", 1, geef_blob_content},
{"library_version", 0, geef_library_version},
}; };
ERL_NIF_INIT(geef, geef_funcs, load, NULL, upgrade, unload) ERL_NIF_INIT(geef, geef_funcs, load, NULL, upgrade, unload)

11
c_src/library.c Normal file
View File

@@ -0,0 +1,11 @@
#include "erl_nif.h"
#include <git2.h>
ERL_NIF_TERM geef_library_version(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int major, minor, rev;
git_libgit2_version(&major, &minor, &rev);
return enif_make_tuple3(env, enif_make_int(env, major), enif_make_int(env, minor), enif_make_int(env, rev));
}

6
c_src/library.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef GEEF_LIBRARY_H
#define GEEF_LIBRARY_H
ERL_NIF_TERM geef_library_version(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
#endif

View File

@@ -16,6 +16,9 @@
% objects % objects
-export([object_lookup/2, object_id/1, commit_tree_id/1, commit_tree/1, tree_bypath/2, blob_size/1, blob_content/1]). -export([object_lookup/2, object_id/1, commit_tree_id/1, commit_tree/1, tree_bypath/2, blob_size/1, blob_content/1]).
% git_libgit2
-export([library_version/0]).
-on_load(load_enif/0). -on_load(load_enif/0).
hex_to_raw(_Val) -> hex_to_raw(_Val) ->
@@ -108,6 +111,10 @@ blob_size(_ObjHandle) ->
blob_content(_ObjHandle) -> blob_content(_ObjHandle) ->
nif_error(?LINE). nif_error(?LINE).
-spec library_version() -> {integer, integer, integer}.
library_version() ->
nif_error(?LINE).
nif_error(Line) -> nif_error(Line) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}). erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).