Rename the ref record to geef_reference
Remove the access hacks for elixir and make :geef_reference an elixir macro as well.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
defrecord :geef_reference, Record.extract(:geef_reference, from: "src/geef_records.hrl")
|
||||||
|
|
||||||
defmodule Geef.Reference do
|
defmodule Geef.Reference do
|
||||||
alias Geef.Repository
|
alias Geef.Repository
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-record(geef_ref, {handle, name :: binary(), type :: atom(), target :: binary() | geef_oid()}).
|
-record(geef_reference, {handle, name :: binary(), type :: atom(), target :: binary() | geef_oid()}).
|
||||||
-record(geef_oid, {oid}).
|
-record(geef_oid, {oid}).
|
||||||
-record(geef_object, {type :: atom(), handle}).
|
-record(geef_object, {type :: atom(), handle}).
|
||||||
-record(geef_index_entry,
|
-record(geef_index_entry,
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
-record(geef_request, {service :: atom, path :: binary(), host :: binary()}).
|
-record(geef_request, {service :: atom, path :: binary(), host :: binary()}).
|
||||||
|
|
||||||
-type geef_ref() :: #geef_ref{}.
|
-type geef_reference() :: #geef_reference{}.
|
||||||
-type geef_oid() :: #geef_oid{}.
|
-type geef_oid() :: #geef_oid{}.
|
||||||
-type geef_object() :: #geef_object{}.
|
-type geef_object() :: #geef_object{}.
|
||||||
-type geef_index_entry() :: #geef_index_entry{}.
|
-type geef_index_entry() :: #geef_index_entry{}.
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
-module(geef_ref).
|
-module(geef_ref).
|
||||||
|
|
||||||
-export([lookup/2, resolve/1, create/4, name/1, type/1, target/1]).
|
-export([lookup/2, resolve/1, create/4]).
|
||||||
|
|
||||||
-include("geef_records.hrl").
|
-include("geef_records.hrl").
|
||||||
|
|
||||||
-spec new(binary(), term()) -> geef_ref().
|
-spec new(binary(), term()) -> geef_reference().
|
||||||
new(Name, Handle) ->
|
new(Name, Handle) ->
|
||||||
Type = geef_nif:reference_type(Handle),
|
Type = geef_nif:reference_type(Handle),
|
||||||
Bin = geef_nif:reference_target(Handle),
|
Bin = geef_nif:reference_target(Handle),
|
||||||
@@ -14,15 +14,14 @@ new(Name, Handle) ->
|
|||||||
oid ->
|
oid ->
|
||||||
#geef_oid{oid=Bin}
|
#geef_oid{oid=Bin}
|
||||||
end,
|
end,
|
||||||
#geef_ref{handle=Handle, name=Name, type=Type, target=Target}.
|
#geef_reference{handle=Handle, name=Name, type=Type, target=Target}.
|
||||||
|
|
||||||
-spec create(pid(), iolist(), geef_oid() | binary(), boolean()) -> {ok, geef_ref()} | {error, term()}
|
-spec create(pid(), iolist(), geef_oid() | binary(), boolean()) -> {ok, geef_reference()} | {error, term()}.
|
||||||
.
|
|
||||||
create(Repo, Refname, Target, Force) ->
|
create(Repo, Refname, Target, Force) ->
|
||||||
{ok, Ref} = geef_repo:create_reference(Repo, Refname, Target, Force),
|
{ok, Ref} = geef_repo:create_reference(Repo, Refname, Target, Force),
|
||||||
{ok, new(Refname, Ref)}.
|
{ok, new(Refname, Ref)}.
|
||||||
|
|
||||||
-spec lookup(pid(), iolist()) -> {ok, geef_ref()} | {error, term()}.
|
-spec lookup(pid(), iolist()) -> {ok, geef_reference()} | {error, term()}.
|
||||||
lookup(Repo, Refname) ->
|
lookup(Repo, Refname) ->
|
||||||
Name = iolist_to_binary(Refname),
|
Name = iolist_to_binary(Refname),
|
||||||
case geef_repo:lookup_reference(Repo, Name) of
|
case geef_repo:lookup_reference(Repo, Name) of
|
||||||
@@ -32,10 +31,10 @@ lookup(Repo, Refname) ->
|
|||||||
Other
|
Other
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec resolve(geef_ref()) -> {ok, geef_ref()} | {error, term()}.
|
-spec resolve(geef_reference()) -> {ok, geef_reference()} | {error, term()}.
|
||||||
resolve(Ref = #geef_ref{type=oid}) ->
|
resolve(Ref = #geef_reference{type=oid}) ->
|
||||||
{ok, Ref}; % resolving an oid ref is a no-op, skip going into the NIF
|
{ok, Ref}; % resolving an oid ref is a no-op, skip going into the NIF
|
||||||
resolve(#geef_ref{handle=Handle}) ->
|
resolve(#geef_reference{handle=Handle}) ->
|
||||||
case geef_nif:reference_resolve(Handle) of
|
case geef_nif:reference_resolve(Handle) of
|
||||||
{ok, Ref} ->
|
{ok, Ref} ->
|
||||||
{ok, Name} = geef_nif:reference_name(Ref),
|
{ok, Name} = geef_nif:reference_name(Ref),
|
||||||
@@ -43,15 +42,3 @@ resolve(#geef_ref{handle=Handle}) ->
|
|||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec target(geef_ref()) -> {geef_oid(), binary()}.
|
|
||||||
target(#geef_ref{target=Target}) ->
|
|
||||||
Target.
|
|
||||||
|
|
||||||
-spec type(geef_ref()) -> symbolic | oid.
|
|
||||||
type(#geef_ref{type=Type}) ->
|
|
||||||
Type.
|
|
||||||
|
|
||||||
-spec name(geef_ref()) -> binary().
|
|
||||||
name(#geef_ref{name=Name}) ->
|
|
||||||
Name.
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ create_ref_test(Repo) ->
|
|||||||
{ok, _} = geef_ref:create(Repo, "refs/heads/other", "refs/heads/branch", true),
|
{ok, _} = geef_ref:create(Repo, "refs/heads/other", "refs/heads/branch", true),
|
||||||
{ok, Ref0} = geef_ref:lookup(Repo, "refs/heads/branch"),
|
{ok, Ref0} = geef_ref:lookup(Repo, "refs/heads/branch"),
|
||||||
{ok, Ref1} = geef_ref:lookup(Repo, "refs/heads/other"),
|
{ok, Ref1} = geef_ref:lookup(Repo, "refs/heads/other"),
|
||||||
[?_assertEqual(Ref0#geef_ref.target, Id),
|
[?_assertEqual(Ref0#geef_reference.target, Id),
|
||||||
?_assertEqual(Ref1#geef_ref.target, <<"refs/heads/branch">>)].
|
?_assertEqual(Ref1#geef_reference.target, <<"refs/heads/branch">>)].
|
||||||
|
|
||||||
rm_r(Path) ->
|
rm_r(Path) ->
|
||||||
case filelib:is_dir(Path) of
|
case filelib:is_dir(Path) of
|
||||||
|
|||||||
Reference in New Issue
Block a user