Add object id lookup
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
-export([oid_fmt/1, oid_parse/1]).
|
||||
|
||||
% objects
|
||||
-export([object_lookup/2, commit_tree_id/1, commit_tree/1, tree_bypath/2]).
|
||||
-export([object_lookup/2, object_id/1, commit_tree_id/1, commit_tree/1, tree_bypath/2]).
|
||||
|
||||
-on_load(load_enif/0).
|
||||
|
||||
@@ -74,6 +74,9 @@ oid_parse(_Sha) ->
|
||||
object_lookup(_Repo, _Oid) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
object_id(_Handle) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
-spec commit_tree_id(term) -> binary().
|
||||
commit_tree_id(_Handle) ->
|
||||
nif_error(?LINE).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(geef_commit).
|
||||
-export([tree_id/1, tree/1]).
|
||||
-export([tree_id/1, tree/1, id/1]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
@@ -15,3 +15,6 @@ tree(#object{type=commit,handle=Handle}) ->
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
id(Obj = #object{type=commit}) ->
|
||||
geef_object:id(Obj).
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
-export([lookup/2]).
|
||||
-export([lookup/2, id/1]).
|
||||
|
||||
-spec lookup(repo(), oid() | iolist()) -> object().
|
||||
lookup(#repo{handle=RepoHandle}, #oid{oid=Oid}) ->
|
||||
@@ -19,6 +19,14 @@ lookup(#repo{handle=RepoHandle}, #oid{oid=Oid}) ->
|
||||
lookup(Repo = #repo{}, Id) ->
|
||||
lookup(Repo, geef_oid:parse(Id)).
|
||||
|
||||
id(#object{handle=Handle}) ->
|
||||
case geef:object_id(Handle) of
|
||||
{ok, Oid} ->
|
||||
#oid{oid=Oid};
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
-ifdef(TEST).
|
||||
|
||||
lookup_test() ->
|
||||
@@ -28,4 +36,11 @@ lookup_test() ->
|
||||
{ok, #object{type=commit}} = lookup(Repo, ["b5b68cce8b92ca0e7", "bd48430617ac10c0f2c2923"]),
|
||||
{ok, #object{type=commit}} = lookup(Repo, <<"b5b68cce8b92ca0e7bd48430617ac10c0f2c2923">>).
|
||||
|
||||
id_test() ->
|
||||
{ok, Repo} = geef_repo:open(".."),
|
||||
Sha = <<"b5b68cce8b92ca0e7bd48430617ac10c0f2c2923">>,
|
||||
Id = geef_oid:parse(Sha),
|
||||
{ok, Commit = #object{type=commit}} = lookup(Repo, Sha),
|
||||
Id = id(Commit).
|
||||
|
||||
-endif.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
-export([bypath/2]).
|
||||
-export([bypath/2, id/1]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
@@ -16,6 +16,9 @@ bypath(#object{type=tree,handle=Handle}, Path) ->
|
||||
Other
|
||||
end.
|
||||
|
||||
id(Obj = #object{type=tree}) ->
|
||||
geef_object:id(Obj).
|
||||
|
||||
-ifdef(TEST).
|
||||
|
||||
%% This is somewhat hacky, assuming that this is running under .eunit,
|
||||
|
||||
Reference in New Issue
Block a user