anchor.diff:                    sets:set(binary()), rebar_state:t()) -> boolean().
   maybe_fetch(AppInfo, Upgrade, Seen, State) ->
       AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)),
  -    Apps = rebar_app_discover:find_apps(["_checkouts"], all),
  -    case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of
  -        {ok, _} ->
  -            %% Don't fetch dep if it exists in the _checkouts dir
  +    %% Don't fetch dep if it exists in the _checkouts dir
  +    case in_checkouts(AppInfo) of
  +        true ->
               false;
  -        error ->
  +        false ->
               case not app_exists(AppDir) of
                   true ->
                       fetch_app(AppInfo, AppDir, State);
  
positive.code:             {error, Error} ->
                  {error, Error};
              no_cycle ->
                  case rebar_digraph:compile_order(Source) of
                      {ok, Sort} ->
                          {ok, rebar_state:deps_to_build(State1,
                                                      lists:dropwhile(fun rebar_app_info:valid/1,
                                                                      Sort -- ProjectApps))};
                      {error, Error} ->
                          {error, Error}
                  end
  
negative.code: %% Internal functions
  %% ===================================================================
  
  deps_per_profile(Profile, {Apps, State}) ->
      Locks = rebar_state:get(State, {locks, Profile}, []),
      ProfileDeps = rebar_state:get(State, {deps, Profile}, []),
      {ok, NewApps, NewState} = handle_deps(Profile, State, ProfileDeps, Locks),
      {NewApps++Apps, NewState}.
  
  find_cycles(Apps) ->
      case rebar_digraph:compile_order(Apps) of
          {error, {cycles, Cycles}} -> {cycles, Cycles};
          {error, Error} -> {error, Error};
          {ok, _} -> no_cycle
      end.
  
  compile_order(Source, ProjectApps) ->
      case rebar_digraph:compile_order(Source) of
          {ok, Sort} ->
              %% Valid apps are compiled and good
              {ok, lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps)};
          {error, Error} ->
              {error, Error}
      end.
  
  update_pkg_deps(Profile, Packages, PkgDeps, Graph, Upgrade, Seen, State) ->
      case PkgDeps of
          [] -> %% No pkg deps
              {[], State};
          PkgDeps ->
              %% Find pkg deps needed
              S = case rebar_digraph:cull_deps(Graph, PkgDeps) of
                  {ok, [], _} ->
                      throw({rebar_digraph, no_solution});
                  {ok, Solution, []} ->
                      Solution;
                  {ok, Solution, Discarded} ->
                      [warn_skip_pkg(Pkg) || Pkg <- Discarded],
                      Solution
              end,
              update_pkg_deps(Profile, S, Packages, Upgrade, Seen, State)
      end.
  
  update_pkg_deps(Profile, Pkgs, Packages, Upgrade, Seen, State) ->
      %% Create app_info record for each pkg dep
      DepsDir = rebar_dir:deps_dir(State),
      {Solved, _, State1}
          = lists:foldl(fun(Pkg, {Acc, SeenAcc, StateAcc}) ->
                          handle_pkg_dep(Profile, Pkg, Packages, Upgrade, DepsDir, Acc, SeenAcc, StateAcc)
                        end, {[], Seen, State}, Pkgs),
      {Solved, State1}.
  
  handle_pkg_dep(Profile, Pkg, Packages, Upgrade, DepsDir, Fetched, Seen, State) ->
      AppInfo = package_to_app(DepsDir, Packages, Pkg),
      {NewSeen, NewState} = maybe_lock(Profile, AppInfo, Seen, State, 0),
      case maybe_fetch(AppInfo, Upgrade, NewSeen, NewState) of
          true ->
              {[AppInfo | Fetched], NewSeen, NewState};
          false ->
              {Fetched, NewSeen, NewState}
      end.
  
  
  maybe_lock(Profile, AppInfo, Seen, State, Level) ->
      case Profile of
          default ->
              Name = rebar_app_info:name(AppInfo),
              case sets:is_element(Name, Seen) of
                  false ->
                      Locks = rebar_state:lock(State),
                      case lists:any(fun(App) -> rebar_app_info:name(App) =:= Name end, Locks) of
                          true ->
                              {sets:add_element(Name, Seen), State};
                          false ->
  