Add the #oid{} record to differentiate from a formatted hash

This commit is contained in:
Carlos Martín Nieto
2013-01-29 01:38:15 +01:00
parent 5a58abc4a0
commit 8a96f4732e
3 changed files with 14 additions and 7 deletions

View File

@@ -1,12 +1,14 @@
-module(geef_oid).
-include("geef_records.hlr").
-export([parse/1, fmt/1]).
-spec fmt(binary()) -> binary().
fmt(Oid) ->
-spec fmt(oid()) -> binary().
fmt(#oid{oid=Oid}) ->
geef:oid_fmt(Oid).
-spec parse(binary()) -> binary().
-spec parse(binary()) -> oid().
parse(Sha) ->
geef:oid_parse(Sha).
Oid = geef:oid_parse(Sha),
#oid{oid=Oid}.

View File

@@ -1,7 +1,9 @@
-record(ref, {handle, type :: atom()}).
-record(repo, {handle}).
-record(odb, {handle}).
-record(oid, {oid}).
-type ref() :: #ref{}.
-type repo() :: #repo{}.
-type odb() :: #odb{}.
-type oid() :: #oid{}.

View File

@@ -27,6 +27,9 @@ resolve(#ref{handle=Handle}) ->
Other
end.
-spec target(ref()) -> binary().
target(#ref{handle=Handle}) ->
geef:reference_target(Handle).
-spec target(ref()) -> binary() | oid().
target(#ref{handle=Handle,type=symbolic}) ->
geef:reference_target(Handle);
target(#ref{handle=Handle,type=oid}) ->
Oid = geef:reference_target(Handle),
#oid{oid=Oid}.