Add lookup/2 to the specific types
They proxy to geef_object:lookup/3 which looks up the object and asserts the type.
This commit is contained in:
@@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
-spec lookup(repo(), oid() | iolist()) -> object().
|
-spec lookup(repo(), oid() | iolist()) -> object().
|
||||||
lookup(Repo, Id) ->
|
lookup(Repo, Id) ->
|
||||||
{ok, Obj = #object{type=blob}} = geef_object:lookup(Repo, Id),
|
geef_object:lookup(Repo, Id, blob).
|
||||||
Obj.
|
|
||||||
|
|
||||||
-spec id(object()) -> oid().
|
-spec id(object()) -> oid().
|
||||||
id(Obj = #object{type=blob}) ->
|
id(Obj = #object{type=blob}) ->
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-module(geef_commit).
|
-module(geef_commit).
|
||||||
-export([tree_id/1, tree/1, id/1]).
|
-export([tree_id/1, tree/1, id/1, lookup/2]).
|
||||||
|
|
||||||
-include("geef_records.hrl").
|
-include("geef_records.hrl").
|
||||||
|
|
||||||
@@ -16,5 +16,9 @@ tree(#object{type=commit,handle=Handle}) ->
|
|||||||
Other
|
Other
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec lookup(repo(), oid() | iolist()) -> object().
|
||||||
|
lookup(Repo, Id) ->
|
||||||
|
geef_object:lookup(Repo, Id, commit).
|
||||||
|
|
||||||
id(Obj = #object{type=commit}) ->
|
id(Obj = #object{type=commit}) ->
|
||||||
geef_object:id(Obj).
|
geef_object:id(Obj).
|
||||||
|
|||||||
@@ -6,19 +6,29 @@
|
|||||||
|
|
||||||
-include("geef_records.hrl").
|
-include("geef_records.hrl").
|
||||||
|
|
||||||
-export([lookup/2, id/1]).
|
-export([lookup/2, lookup/3, id/1]).
|
||||||
|
|
||||||
-spec lookup(pid(), oid() | iolist()) -> object().
|
-spec lookup(pid(), oid() | iolist()) -> {ok, object()} | {error, term()}.
|
||||||
lookup(Repo, #oid{oid=Oid}) ->
|
lookup(Repo, #oid{oid=Oid}) ->
|
||||||
case geef_repo:lookup_object(Repo, Oid) of
|
case geef_repo:lookup_object(Repo, Oid) of
|
||||||
{ok, Type, Handle} ->
|
{ok, Type, Handle} ->
|
||||||
{ok, #object{type=Type, handle=Handle}};
|
{ok, #object{type=Type, handle=Handle}};
|
||||||
Other ->
|
{error, Err} ->
|
||||||
Other
|
{error, Err}
|
||||||
end;
|
end;
|
||||||
lookup(Repo, Id) ->
|
lookup(Repo, Id) ->
|
||||||
lookup(Repo, geef_oid:parse(Id)).
|
lookup(Repo, geef_oid:parse(Id)).
|
||||||
|
|
||||||
|
%% As lookup/2, but it asserts that the type is correct
|
||||||
|
-spec lookup(pid(), oid() | iolist(), atom()) -> {ok, object()} | {error, term()}.
|
||||||
|
lookup(Repo, Id, Type) ->
|
||||||
|
case lookup(Repo, Id) of
|
||||||
|
{ok, Obj = #object{type=Type}} ->
|
||||||
|
{ok, Obj};
|
||||||
|
{error, Err} ->
|
||||||
|
{error, Err}
|
||||||
|
end.
|
||||||
|
|
||||||
id(#object{handle=Handle}) ->
|
id(#object{handle=Handle}) ->
|
||||||
case geef:object_id(Handle) of
|
case geef:object_id(Handle) of
|
||||||
{ok, Oid} ->
|
{ok, Oid} ->
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
-export([bypath/2, id/1]).
|
-export([bypath/2, id/1, lookup/2]).
|
||||||
|
|
||||||
-include("geef_records.hrl").
|
-include("geef_records.hrl").
|
||||||
|
|
||||||
@@ -19,6 +19,10 @@ bypath(#object{type=tree,handle=Handle}, Path) ->
|
|||||||
id(Obj = #object{type=tree}) ->
|
id(Obj = #object{type=tree}) ->
|
||||||
geef_object:id(Obj).
|
geef_object:id(Obj).
|
||||||
|
|
||||||
|
-spec lookup(repo(), oid() | iolist()) -> {ok, object()} | {error, term()}.
|
||||||
|
lookup(Repo, Id) ->
|
||||||
|
geef_object:lookup(Repo, Id, tree).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
|
|
||||||
%% This is somewhat hacky, assuming that this is running under .eunit,
|
%% This is somewhat hacky, assuming that this is running under .eunit,
|
||||||
|
|||||||
Reference in New Issue
Block a user