Add geef:oid_fmt(Oid)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "erl_nif.h"
|
#include "erl_nif.h"
|
||||||
#include "repository.h"
|
#include "repository.h"
|
||||||
#include "reference.h"
|
#include "reference.h"
|
||||||
|
#include "oid.h"
|
||||||
#include "geef.h"
|
#include "geef.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -78,6 +79,7 @@ static ErlNifFunc geef_funcs[] =
|
|||||||
{"reference_lookup", 2, geef_reference_lookup},
|
{"reference_lookup", 2, geef_reference_lookup},
|
||||||
{"reference_resolve", 1, geef_reference_resolve},
|
{"reference_resolve", 1, geef_reference_resolve},
|
||||||
{"reference_id", 1, geef_reference_id},
|
{"reference_id", 1, geef_reference_id},
|
||||||
|
{"oid_fmt", 1, geef_oid_fmt},
|
||||||
};
|
};
|
||||||
|
|
||||||
ERL_NIF_INIT(geef, geef_funcs, load, NULL, NULL, unload)
|
ERL_NIF_INIT(geef, geef_funcs, load, NULL, NULL, unload)
|
||||||
|
|||||||
24
c_src/oid.c
Normal file
24
c_src/oid.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <git2.h>
|
||||||
|
#include "geef.h"
|
||||||
|
#include "oid.h"
|
||||||
|
|
||||||
|
ERL_NIF_TERM
|
||||||
|
geef_oid_fmt(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);
|
||||||
|
|
||||||
|
if (bin.size < GIT_OID_RAWSZ)
|
||||||
|
return enif_make_badarg(env);
|
||||||
|
|
||||||
|
if (!enif_alloc_binary(GIT_OID_HEXSZ, &bin_out))
|
||||||
|
return atoms.error;
|
||||||
|
|
||||||
|
git_oid_fromraw(&id, bin.data);
|
||||||
|
git_oid_fmt((char *)bin_out.data, &id);
|
||||||
|
|
||||||
|
return enif_make_binary(env, &bin_out);
|
||||||
|
}
|
||||||
9
c_src/oid.h
Normal file
9
c_src/oid.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef GEEF_OID_H
|
||||||
|
#define GEEF_OID_H
|
||||||
|
|
||||||
|
#include "erl_nif.h"
|
||||||
|
#include <git2.h>
|
||||||
|
|
||||||
|
ERL_NIF_TERM geef_oid_fmt(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
-export([hex_to_raw/1, repository/1, repository_get_path/1, repository_get_odb/1,
|
-export([hex_to_raw/1, repository/1, repository_get_path/1, repository_get_odb/1,
|
||||||
repository_init/2, repository_is_bare/1, repository_get_workdir/1, reference_list/1,
|
repository_init/2, repository_is_bare/1, repository_get_workdir/1, reference_list/1,
|
||||||
reference_to_id/2, reference_glob/2, reference_lookup/2, reference_resolve/1,
|
reference_to_id/2, reference_glob/2, reference_lookup/2, reference_resolve/1,
|
||||||
reference_id/1, odb_object_exists/2]).
|
reference_id/1, odb_object_exists/2, oid_fmt/1]).
|
||||||
-on_load(load_enif/0).
|
-on_load(load_enif/0).
|
||||||
|
|
||||||
hex_to_raw(_Val) ->
|
hex_to_raw(_Val) ->
|
||||||
@@ -55,6 +55,9 @@ repository(Path) ->
|
|||||||
odb_object_exists(_Val, _Val) ->
|
odb_object_exists(_Val, _Val) ->
|
||||||
nif_error(?LINE).
|
nif_error(?LINE).
|
||||||
|
|
||||||
|
oid_fmt(_Oid) ->
|
||||||
|
nif_error(?LINE).
|
||||||
|
|
||||||
nif_error(Line) ->
|
nif_error(Line) ->
|
||||||
exit({nif_not_loaded,module,?MODULE,line,Line}).
|
exit({nif_not_loaded,module,?MODULE,line,Line}).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user