CAPI-32 Fix protocol violation (#13)

This commit is contained in:
Artem Ocheredko 2016-10-18 23:04:09 +03:00 committed by Igor Savchuk
parent db64a67215
commit f3c72168d9
2 changed files with 8 additions and 1 deletions

View File

@ -14,3 +14,4 @@
* Encode machine events and responses with a schema-aware protocol * Encode machine events and responses with a schema-aware protocol
* Thrift / compact protocol? * Thrift / compact protocol?
* Fix potential race when a `Repository` request getting processed earlier than the start machine request being issued. * Fix potential race when a `Repository` request getting processed earlier than the start machine request being issued.
* Don't go to the cache for getting `Head` reference

View File

@ -50,10 +50,11 @@ get_prev_commit(N) ->
get_history(Context) -> get_history(Context) ->
get_history(undefined, undefined, Context). get_history(undefined, undefined, Context).
%% TODO: change this interface to accept dmt:version only
-spec get_history(dmt:version() | undefined, pos_integer() | undefined, context()) -> -spec get_history(dmt:version() | undefined, pos_integer() | undefined, context()) ->
{dmt:history() | {error, version_not_found}, context()}. {dmt:history() | {error, version_not_found}, context()}.
get_history(After, Limit, Context) -> get_history(After, Limit, Context) ->
Range = #'HistoryRange'{'after' = After, 'limit' = Limit}, Range = #'HistoryRange'{'after' = prepare_event_id(After), 'limit' = Limit},
try dmt_api_context:map(call('GetHistory', [?REF, Range], Context), fun read_history/1) catch try dmt_api_context:map(call('GetHistory', [?REF, Range], Context), fun read_history/1) catch
{{exception, #'EventNotFound'{}}, Context1} -> {{exception, #'EventNotFound'{}}, Context1} ->
{{error, version_not_found}, Context1} {{error, version_not_found}, Context1}
@ -92,3 +93,8 @@ read_history([], History) ->
History; History;
read_history([#'Event'{id = Id, event_payload = BinaryPayload} | Rest], History) -> read_history([#'Event'{id = Id, event_payload = BinaryPayload} | Rest], History) ->
read_history(Rest, History#{Id => binary_to_term(BinaryPayload)}). read_history(Rest, History#{Id => binary_to_term(BinaryPayload)}).
prepare_event_id(ID) when is_integer(ID) andalso ID > 0 ->
ID;
prepare_event_id(_) ->
undefined.