summaryrefslogtreecommitdiff
path: root/src/rebar_digraph.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-02-23 19:17:36 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-02-23 19:17:36 -0500
commita0e85721caaeedbc66b4a56adf00ac89228a07d3 (patch)
tree2e6c88fa2a42b18f3970b6f2bd8807b3f5ff1a9d /src/rebar_digraph.erl
parente05f483043e770c2abdd8b4e6292d231b25cbc25 (diff)
parent6ccef538913e90e33f2ac53956cbbb1e85d5f2e4 (diff)
Merge pull request #179 from ferd/upgrade-pkg
Upgrade pkg
Diffstat (limited to 'src/rebar_digraph.erl')
-rw-r--r--src/rebar_digraph.erl33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/rebar_digraph.erl b/src/rebar_digraph.erl
index 3f942ef..129ea35 100644
--- a/src/rebar_digraph.erl
+++ b/src/rebar_digraph.erl
@@ -71,29 +71,36 @@ restore_graph({Vs, Es}) ->
cull_deps(Graph, Vertices) ->
cull_deps(Graph,
Vertices,
+ 1,
+ lists:foldl(fun({Key, _}, Levels) -> dict:store(Key, 0, Levels) end,
+ dict:new(), Vertices),
lists:foldl(fun({Key, _}=N, Solution) -> dict:store(Key, N, Solution) end,
dict:new(), Vertices),
[]).
-cull_deps(_Graph, [], Solution, Discarded) ->
+cull_deps(_Graph, [], _Level, Levels, Solution, Discarded) ->
{_, Vertices} = lists:unzip(dict:to_list(Solution)),
- {ok, Vertices, Discarded};
-cull_deps(Graph, Vertices, Solution, Discarded) ->
- {NV, NS, DS} =
- lists:foldl(fun(V, {NewVertices, SolutionAcc, DiscardedAcc}) ->
- OutNeighbors = digraph:out_neighbours(Graph, V),
- lists:foldl(fun({Key, _}=N, {NewVertices1, SolutionAcc1, DiscardedAcc1}) ->
+ LvlVertices = [{App,Vsn,dict:fetch(App,Levels)} || {App,Vsn} <- Vertices],
+ {ok, LvlVertices, Discarded};
+cull_deps(Graph, Vertices, Level, Levels, Solution, Discarded) ->
+ {NV, NS, LS, DS} =
+ lists:foldl(fun(V, {NewVertices, SolutionAcc, LevelsAcc, DiscardedAcc}) ->
+ OutNeighbors = lists:keysort(1, digraph:out_neighbours(Graph, V)),
+ lists:foldl(fun({Key, _}=N, {NewVertices1, SolutionAcc1, LevelsAcc1, DiscardedAcc1}) ->
case dict:find(Key, SolutionAcc1) of
{ok, N} -> % already seen
- {NewVertices1, SolutionAcc1, DiscardedAcc1};
+ {NewVertices1, SolutionAcc1, LevelsAcc, DiscardedAcc1};
{ok, _} -> % conflict resolution!
- {NewVertices1, SolutionAcc1, [N|DiscardedAcc1]};
+ {NewVertices1, SolutionAcc1, LevelsAcc, [N|DiscardedAcc1]};
error ->
- {[N | NewVertices1], dict:store(Key, N, SolutionAcc1), DiscardedAcc1}
+ {[N | NewVertices1],
+ dict:store(Key, N, SolutionAcc1),
+ dict:store(Key, Level, LevelsAcc1),
+ DiscardedAcc1}
end
- end, {NewVertices, SolutionAcc, DiscardedAcc}, OutNeighbors)
- end, {[], Solution, Discarded}, lists:sort(Vertices)),
- cull_deps(Graph, NV, NS, DS).
+ end, {NewVertices, SolutionAcc, LevelsAcc, DiscardedAcc}, OutNeighbors)
+ end, {[], Solution, Levels, Discarded}, lists:keysort(1, Vertices)),
+ cull_deps(Graph, NV, Level+1, LS, NS, DS).
subgraph(Graph, Vertices) ->
digraph_utils:subgraph(Graph, Vertices).