Wrap commit creation

This commit is contained in:
Carlos Martín Nieto
2013-10-18 22:25:08 +02:00
parent fd390306b3
commit 3110f37ff7
8 changed files with 228 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
-module(geef_commit).
-export([tree_id/1, tree/1, lookup/2]).
-export([create/5, create/6, create/7]).
-include("geef_records.hrl").
@@ -22,3 +23,29 @@ tree(#geef_object{type=commit,handle=Handle}) ->
-spec lookup(pid(), geef_oid:oid()) -> {ok, commit()} | {error, term()}.
lookup(Repo, Id) ->
geef_obj:lookup(Repo, Id, commit).
%% Full version, accepts all paremeters
-spec create(pid(), iolist(), geef_sig:signature(), geef_sig:signature(),
iolist(), iolist(), geef_oid:oid(), [geef_oid:oid()]) -> {ok, geef_oid:oid()} | {error, term()}.
create(Repo, Ref, Author = #geef_signature{}, Committer = #geef_signature{}, Encoding, Message, Tree, Parents)
when is_list(Parents) ->
Handle = geef_repo:handle(Repo),
geef_nif:commit_create(Handle, Ref, Author, Committer, Encoding, Message, Tree, Parents).
% Common version, accepts ref and encoding as options
create(Repo, Author = #geef_signature{}, Committer = #geef_signature{}, Message, Tree, Parents, Opts) ->
Ref = proplists:get_value(update_ref, Opts, undefined),
Encoding = proplists:get_value(encoding, Opts, undefined),
create(Repo, Ref, Author, Committer, Encoding, Message, Tree, Parents).
create(Repo, Author = #geef_signature{}, Committer = #geef_signature{}, Message, Tree, Parents) ->
create(Repo, Author, Committer, Message, Tree, Parents, []);
% Version with both the same
%% @doc Create a new commit. Person will be used for both author and commiter.
create(Repo, Person = #geef_signature{}, Message, Tree, Parents, Opts) ->
create(Repo, Person, Person, Message, Tree, Parents, Opts).
create(Repo, Person = #geef_signature{}, Message, Tree, Parents) ->
create(Repo, Person, Person, Message, Tree, Parents, []).

View File

@@ -96,6 +96,9 @@ commit_tree_id(_Handle) ->
commit_tree(_Handle) ->
nif_error(?LINE).
commit_create(_RepoHandle, _Ref, _Author, _Committer, _Encoding, _Message, _Tree, _Parents) ->
?NIF_FN.
-spec tree_bypath(term, iolist()) -> term().
tree_bypath(_TreeHandle, _Path) ->
nif_error(?LINE).