Add geef_commit:tree_id
This commit is contained in:
24
c_src/commit.c
Normal file
24
c_src/commit.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "geef.h"
|
||||
#include "repository.h"
|
||||
#include "object.h"
|
||||
#include "oid.h"
|
||||
#include <string.h>
|
||||
#include <git2.h>
|
||||
|
||||
ERL_NIF_TERM
|
||||
geef_commit_tree_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
const git_oid *id;
|
||||
geef_object *obj;
|
||||
ErlNifBinary bin;
|
||||
|
||||
if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
id = git_commit_tree_id((git_commit *) obj->obj);
|
||||
|
||||
if (geef_oid_bin(&bin, id) < 0)
|
||||
return atoms.error;
|
||||
|
||||
return enif_make_binary(env, &bin);
|
||||
}
|
||||
6
c_src/commit.h
Normal file
6
c_src/commit.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef GEEF_COMMIT_H
|
||||
#define GEEF_COMMIT_H
|
||||
|
||||
ERL_NIF_TERM geef_commit_tree_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "reference.h"
|
||||
#include "oid.h"
|
||||
#include "object.h"
|
||||
#include "commit.h"
|
||||
#include "geef.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -97,6 +98,7 @@ static ErlNifFunc geef_funcs[] =
|
||||
{"oid_fmt", 1, geef_oid_fmt},
|
||||
{"oid_parse", 1, geef_oid_parse},
|
||||
{"object_lookup", 2, geef_object_lookup},
|
||||
{"commit_tree_id", 1, geef_commit_tree_id},
|
||||
};
|
||||
|
||||
ERL_NIF_INIT(geef, geef_funcs, load, NULL, NULL, unload)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
-export([oid_fmt/1, oid_parse/1]).
|
||||
|
||||
% objects
|
||||
-export([object_lookup/2]).
|
||||
-export([object_lookup/2, commit_tree_id/1]).
|
||||
|
||||
-on_load(load_enif/0).
|
||||
|
||||
@@ -74,6 +74,10 @@ oid_parse(_Sha) ->
|
||||
object_lookup(_Repo, _Oid) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
-spec commit_tree_id(term) -> binary().
|
||||
commit_tree_id(_Handle) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
nif_error(Line) ->
|
||||
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
|
||||
|
||||
|
||||
9
src/geef_commit.erl
Normal file
9
src/geef_commit.erl
Normal file
@@ -0,0 +1,9 @@
|
||||
-module(geef_commit).
|
||||
-export([tree_id/1]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
-spec tree_id(object()) -> oid().
|
||||
tree_id(#object{type=commit,handle=Handle}) ->
|
||||
Oid = geef:commit_tree_id(Handle),
|
||||
#oid{oid=Oid}.
|
||||
@@ -8,7 +8,7 @@
|
||||
lookup(#repo{handle=Repo}, #oid{oid=Oid}) ->
|
||||
case geef:object_lookup(Repo, Oid) of
|
||||
{ok, Type, Handle} ->
|
||||
#object{type=Type, handle=Handle};
|
||||
{ok, #object{type=Type, handle=Handle}};
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user