anchor.diff:  %%%-------------------------------------------------------------------
   %%% @author Joe Armstrong
   %%% @author Eric Merritt
  +%%% @author Konstantin Tcepliaev
   %%% @doc
   %%%  This is a pretty simple topological sort for erlang. It was
   %%%  originally written for ermake by Joe Armstrong back in '98. It
   %%%  has been pretty heavily modified by Eric Merritt since '06 and modified again for Relx.
  +%%%  Konstantin Tcepliaev rewrote the algorithm in 2017.
   %%%
   %%%  A partial order on the set S is a set of pairs {Xi,Xj} such that
   %%%  some relation between Xi and Xj is obeyed.
  
positive.code: %%%  A topological sort of a partial order is a sequence of elements
  %%%  [X1, X2, X3 ...] such that if whenever {Xi, Xj} is in the partial
  %%%  order i &lt; j
  %%% @end
  %%%-------------------------------------------------------------------
  -module(rlx_topo).
  
  -export([sort/1,
           sort_apps/1,
           format_error/1]).
  
  -include("relx.hrl").
  
  %%====================================================================
  %% Types
  %%====================================================================
  -type pair() :: {DependentApp::atom(), PrimaryApp::atom()}.
  -type name() :: AppName::atom().
  -type element() :: name() | pair().
  
  %%====================================================================
  %% API
  
negative.code:                     rlx_app_info:new(kernel, "0.1", "/no-dir", [], []),
                      rlx_app_info:new(zapp2, "0.1", "/no-dir", [], [])]],
      {ok, Sorted} = sort_apps(Apps),
      ?assertMatch([kernel, app3, app2, zapp2, zapp1, stdlib, app1],
                   [rlx_app_info:name(App) || App <- Sorted]).
  
  topo_apps_1_test() ->
      Apps = [App ||
                 {ok, App} <-
                     [rlx_app_info:new(app0, "0.1", "/no-dir", [], [stdlib, dep1, dep2, dep3]),
                      rlx_app_info:new(app1, "0.1", "/no-dir", [], [stdlib, kernel]),
                      rlx_app_info:new(dep1, "0.1", "/no-dir", [], []),
                      rlx_app_info:new(dep2, "0.1", "/no-dir", [], []),
                      rlx_app_info:new(dep3, "0.1", "/no-dir", [], []),
                      rlx_app_info:new(stdlib, "0.1", "/no-dir", [], []),
                      rlx_app_info:new(kernel, "0.1", "/no-dir", [], [])]],
      {ok, Sorted} = sort_apps(Apps),
      ?assertMatch([stdlib, dep1, dep2, dep3, app0, kernel, app1],
                   [rlx_app_info:name(App) || App <- Sorted]).
  
  topo_apps_2_test() ->
  