Correct the signature output from the reflog
The function to convert signatures into erlang terms was returning ok with the rest of the tuple which geef_sig expects. We do not want the ok there, so let that function give us the four terms and decide what to do in each case. The signature functions still want to return with ok before it, but the reflog wants them together with the other parameters.
This commit is contained in:
@@ -73,7 +73,7 @@ reference_dwim(_Handle, _Name) ->
|
||||
reference_has_log(_Handle, _Name) ->
|
||||
?NIF_FN.
|
||||
|
||||
-spec reflog_read(term(), iolist()) -> {ok, geef_reflog:reflog()} | {error, term()}.
|
||||
-spec reflog_read(term(), iolist()) -> {ok, binary(), binary(), non_neg_integer(), non_neg_integer()} | {error, term()}.
|
||||
reflog_read(_Handle, _Name) ->
|
||||
?NIF_FN.
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
-module(geef_reflog).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-type entry() :: #geef_reflog_entry{}.
|
||||
-export_type([entry/0]).
|
||||
@@ -10,7 +11,16 @@
|
||||
%% API
|
||||
-export([read/2]).
|
||||
|
||||
to_entry({Name, Email, Timestamp, Offset, IdOld, IdNew, Message}) ->
|
||||
Sig = geef_sig:convert(Name, Email, Timestamp, Offset),
|
||||
#geef_reflog_entry{committer=Sig, id_old=IdOld, id_new=IdNew, message=Message}.
|
||||
|
||||
%% @doc Read in a reflog
|
||||
-spec read(pid(), iolist()) -> {ok, [entry()]} | {error, term()}.
|
||||
read(Repo, Name) ->
|
||||
geef_repo:reflog_read(Repo, Name).
|
||||
case geef_repo:reflog_read(Repo, Name) of
|
||||
{ok, List} ->
|
||||
{ok, lists:map(fun to_entry/1, List)};
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
-export_type([time/0, signature/0]).
|
||||
|
||||
-export([default/1, now/2]).
|
||||
-export([convert/4]).
|
||||
|
||||
%% @doc Create a signature for the repository's configured username and
|
||||
%% email, with a timestamp of now.
|
||||
@@ -15,9 +16,7 @@ default(Repo) ->
|
||||
RepoHandle = geef_repo:handle(Repo),
|
||||
case geef_nif:signature_default(RepoHandle) of
|
||||
{ok, Name, Email, Timestamp, Offset} ->
|
||||
Time = {{Timestamp div 1000000, Timestamp rem 1000000, 0}, Offset},
|
||||
Sig = #geef_signature{name=Name, email=Email, time=Time},
|
||||
{ok, Sig};
|
||||
{ok, convert(Name, Email, Timestamp, Offset)};
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end.
|
||||
@@ -32,3 +31,10 @@ now(Name, Email) ->
|
||||
UTC = calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time(Now)),
|
||||
Offset = (Local - UTC) div 60,
|
||||
#geef_signature{name=Name, email=Email, time={Now, Offset}}.
|
||||
|
||||
%% @private
|
||||
%% @doc convert the return from the NIF to a signature
|
||||
-spec convert(binary(), binary(), non_neg_integer(), non_neg_integer()) -> signature().
|
||||
convert(Name, Email, Timestamp, Offset) ->
|
||||
Time = {{Timestamp div 1000000, Timestamp rem 1000000, 0}, Offset},
|
||||
#geef_signature{name=Name, email=Email, time=Time}.
|
||||
|
||||
Reference in New Issue
Block a user