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). -module(geef_oid).
-include("geef_records.hlr").
-export([parse/1, fmt/1]). -export([parse/1, fmt/1]).
-spec fmt(binary()) -> binary(). -spec fmt(oid()) -> binary().
fmt(Oid) -> fmt(#oid{oid=Oid}) ->
geef:oid_fmt(Oid). geef:oid_fmt(Oid).
-spec parse(binary()) -> binary(). -spec parse(binary()) -> oid().
parse(Sha) -> 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(ref, {handle, type :: atom()}).
-record(repo, {handle}). -record(repo, {handle}).
-record(odb, {handle}). -record(odb, {handle}).
-record(oid, {oid}).
-type ref() :: #ref{}. -type ref() :: #ref{}.
-type repo() :: #repo{}. -type repo() :: #repo{}.
-type odb() :: #odb{}. -type odb() :: #odb{}.
-type oid() :: #oid{}.

View File

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