Allow getting a tree entry

This commit is contained in:
Carlos Martín Nieto
2013-03-02 02:56:58 +01:00
parent 1807ba4374
commit b5b68cce8b
8 changed files with 125 additions and 6 deletions

28
src/geef_tree.erl Normal file
View File

@@ -0,0 +1,28 @@
-module(geef_tree).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
-export([bypath/2]).
-include("geef_records.hrl").
bypath(#object{type=tree,handle=Handle}, Path) ->
case geef:tree_bypath(Handle, Path) of
{ok, Mode, Type, Id, Name} ->
{ok, #tree_entry{mode=Mode, type=Type, id=geef_oid:parse(Id), name=Name}};
other ->
other
end.
-ifdef(TEST).
%% This is somewhat hacky, assuming that this is running under .eunit,
%% but it's good enough for now
bypath_test() ->
{ok, Repo} = geef_repo:open(".."),
{ok, Tree} = geef_object:lookup(Repo, geef_oid:parse("395e1c39cb203640b78da8458a42afdb92bef7aa")),
{ok, #tree_entry{type=blob, name= <<"README.md">>}} = geef_tree:bypath(Tree, "README.md").
-endif.