Skip to content

Commit

Permalink
better solution for latest tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas hadin committed Nov 4, 2014
1 parent e9b5b1f commit 35648d9
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions src/component_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ handle_get(Req, _State=#state{}) ->
end,
{ok, Req4}.

expand_tag(<<"*">>, Tags) -> find_latest_tag(Tags);
expand_tag(<<"*">>, _Tags) -> <<"HEAD">>;
expand_tag(Tag, Tags) ->
case lists:member(Tag, Tags) of
true ->
Expand All @@ -86,29 +86,6 @@ handle_post(Req, _State=#state{}) ->
end,
{ok, Req3}.


find_latest_tag([]) ->
<<"">>;
find_latest_tag(Tags) ->
NumericTags = lists:filter(fun(X) ->
case re:run(X, "^\\d+(\\.\\d+){0,2}$") of
nomatch -> false; _ -> true
end
end, Tags),
case NumericTags of
[] -> <<"HEAD">>;
_ ->
SortFun = fun(Tag1, Tag2) ->
Tag1Parts = binary:split(Tag1, <<".">>, [global]),
Tag2Parts = binary:split(Tag2, <<".">>, [global]),
lists:all(fun({Tag1Part, Tag2Part}) ->
binary_to_integer(Tag1Part) =< binary_to_integer(Tag2Part) end,
lists:zip(Tag1Parts, Tag2Parts))
end,
Sorted = lists:sort(SortFun, NumericTags),
lists:last(Sorted)
end.

find_latest_patch(PrefixTag, Tags) ->
lists:foldl(fun(Tag, LatestPatch) ->
case binary:longest_common_prefix([Tag, PrefixTag])of
Expand Down

0 comments on commit 35648d9

Please sign in to comment.