Allow creation of refs

This commit is contained in:
Carlos Martín Nieto
2013-05-02 06:24:15 +02:00
parent 9d7139d604
commit 0aa11d8532
7 changed files with 92 additions and 4 deletions

View File

@@ -16,7 +16,7 @@
%% API
-export([open/1, init/2, path/1, workdir/1, odb/1, is_bare/1, references/1, discover/1,
lookup_object/2, lookup_reference/2, revwalk/1, stop/1, handle/1]).
lookup_object/2, lookup_reference/2, create_reference/4, revwalk/1, stop/1, handle/1]).
-include("geef_records.hrl").
-record(state, {handle}).
@@ -85,6 +85,10 @@ lookup_object(Pid, Oid) ->
lookup_reference(Pid, Name) ->
gen_server:call(Pid, {lookup_reference, Name}).
%% @private
create_reference(Pid, Name, Target, Force) ->
gen_server:call(Pid, {create_reference, Name, Target, Force}).
%% @doc Create a revision walker for the given repository.
revwalk(Pid) ->
gen_server:call(Pid, revwalk).
@@ -127,6 +131,9 @@ handle_call({lookup_object, Oid}, _From, State = #state{handle=Handle}) ->
handle_call({lookup_reference, Name}, _From, State = #state{handle=Handle}) ->
Reply = geef_nif:reference_lookup(Handle, Name),
{reply, Reply, State};
handle_call({create_reference, Name, Target, Force}, _From, State = #state{handle=Handle}) ->
Reply = handle_create_reference(Handle, Name, Target, Force),
{reply, Reply, State};
handle_call(stop, _From, State) ->
{stop, normal, ok, State};
handle_call(revwalk, _From, State = #state{handle=Handle}) ->
@@ -182,3 +189,8 @@ handle_revwalk(Handle) ->
Error ->
Error
end.
handle_create_reference(Repo, Refname, #oid{oid=Oid}, Force) ->
geef_nif:reference_create(Repo, Refname, oid, Oid, Force);
handle_create_reference(Repo, Refname, Target, Force) ->
geef_nif:reference_create(Repo, Refname, symbolic, Target, Force).