More complete ref bindings

This commit is contained in:
Carlos Martín Nieto
2013-01-24 23:55:42 +01:00
parent 468695adb5
commit 7d76f18a55
5 changed files with 22 additions and 13 deletions

View File

@@ -1,3 +1,3 @@
-record(ref, {handle}).
-record(ref, {handle, type}).
-record(repo, {handle}).
-record(odb, {handle}).

View File

@@ -1,17 +1,30 @@
-module(geef_ref).
-export([resolve/1, target/1]).
-export([lookup/2, resolve/1, target/1]).
-include("geef_records.hlr").
new(Handle) ->
Type = geef:reference_type(Handle),
#ref{handle=Handle, type=Type}.
-spec lookup(term(), iolist()) -> term().
lookup(#repo{handle=Handle}, Refname) ->
case geef:reference_lookup(Handle, Refname) of
{ok, Ref} ->
{ok, new(Ref)};
Other ->
Other
end.
resolve(#ref{handle=Handle}) ->
case geef:reference_resolve(Handle) of
{ok, Ref} ->
{ok, #ref{handle=Handle}};
{ok, new(Ref)};
Other ->
Other
end.
-spec target(term()) -> binary().
target(#ref{handle=Handle}) ->
target(#ref{handle=Handle, type=oid}) ->
geef:reference_target(Handle).

View File

@@ -1,5 +0,0 @@
-module(odb, [Handle]).
-export([exists/1]).
exists(Sha) ->
geef:odb_object_exists(Handle, Sha).