From e9b5b1ffa3b351d55007e4879def2d9a2dafd38b Mon Sep 17 00:00:00 2001 From: jonas hadin Date: Fri, 31 Oct 2014 10:35:23 +0100 Subject: [PATCH 1/2] fixed sorting issue --- src/component_handler.erl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/component_handler.erl b/src/component_handler.erl index d1469eb..125203a 100644 --- a/src/component_handler.erl +++ b/src/component_handler.erl @@ -91,7 +91,7 @@ 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), @@ -99,11 +99,14 @@ find_latest_tag(Tags) -> [] -> <<"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) -> From 35648d920ab925450c4da5bc25e2748c9505eea8 Mon Sep 17 00:00:00 2001 From: jonas hadin Date: Tue, 4 Nov 2014 12:28:19 +0100 Subject: [PATCH 2/2] better solution for latest tag --- src/component_handler.erl | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/component_handler.erl b/src/component_handler.erl index 125203a..4c856c3 100644 --- a/src/component_handler.erl +++ b/src/component_handler.erl @@ -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 -> @@ -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