Skip to content

Commit

Permalink
fixed sorting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas hadin committed Oct 31, 2014
1 parent a921c5e commit e9b5b1f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/component_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,22 @@ find_latest_tag([]) ->
<<"">>;
find_latest_tag(Tags) ->
NumericTags = lists:filter(fun(X) ->
case re:run(X, "^\\d+(\\.\\d){0,2}$") of
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, <<".">>),
Tag2Parts = binary:split(Tag2, <<".">>),
lists:all(fun({Tag1Part, Tag2Part}) -> Tag1Part =< Tag2Part end, lists:zip(Tag1Parts, Tag2Parts))
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,
lists:last(lists:sort(SortFun, NumericTags))
Sorted = lists:sort(SortFun, NumericTags),
lists:last(Sorted)
end.

find_latest_patch(PrefixTag, Tags) ->
Expand Down

0 comments on commit e9b5b1f

Please sign in to comment.