anchor.diff:  -spec list_building_revs(State :: record()) -> {ok, [rev_def()]}.
   list_building_revs(State) ->
       {ok, [RevDef || {_Pid, RevDef} <- State#state.workers, RevDef /= none]}.
  +
   -spec number_free_workers(State :: record()) -> {ok, non_neg_integer()}.
   number_free_workers(State) ->
       {ok, lists:foldl(
  
positive.code: %% Internal Function Definitions
  %% ------------------------------------------------------------------
  
  -spec schedule_build(State :: record()) -> {ok, NewState :: record()}.
  schedule_build(State) when State#state.next_to_build == none ->
      get_build_candidate(State);
  schedule_build(State) ->
      {ok, State}.
  
  -spec get_build_candidate(State :: record()) -> {ok, NewState :: record()}.
  get_build_candidate(State) ->
      case {
              queue:is_empty(State#state.wait_queue),
              queue:is_empty(State#state.main_queue)} of
          {true, true} ->
              {ok, State};
          _Other -> %%TODO
              {ok, State}
      end.
  
  -spec create_workers(WorkerNumber :: non_neg_integer()) -> 
      {ok, [{Pid :: pid(), none}]}.
  create_workers(WorkerNumber) ->
  
negative.code:                 ({_Pid, _Other}, Cnt) ->
                      Cnt
              end, State#state.workers)}.
  
  
  %% Scheduling section
  %% ------------------------------------------------------------------
  
  -spec schedule_build(State :: record()) -> {ok, NewState :: record()}.
  schedule_build(State) when State#state.next_to_build == none ->
      get_build_candidate(State);
  schedule_build(State) ->
      {ok, State}.
  
  -spec get_build_candidate(State :: record()) -> {ok, NewState :: record()}.
  get_build_candidate(State) ->
      case {
              queue:is_empty(State#state.wait_queue),
              queue:is_empty(State#state.main_queue)} of
          {true, true} ->
              {ok, State};
          {true, false} ->
              get_build_candidate(main_queue, State);
          {false, true} ->
              get_build_candidate(wait_queue, State);
          {false, false} ->
              get_build_candidate(both, State)
      end.
  
  get_build_candidate(main_queue, State) ->
      {{value, Candidate}, MainQueue} = queue:out(State#state.main_queue),
      case check_build_deps(Candidate, State) of
          true -> %% independent
              {ok, State#state{main_queue=MainQueue, next_to_build=Candidate}};
          false ->
              WaitQueue = queue:in(Candidate, State#state.wait_queue),
              get_build_candidate(
                  State#state{main_queue=MainQueue, wait_queue=WaitQueue})
      end;
  get_build_candidate(wait_queue, State) ->
      {{value, Candidate}, WaitQueue} = queue:out(State#state.wait_queue),
      case check_build_deps(Candidate, State) of
          true -> %% independent
              {ok, State#state{wait_queue=WaitQueue, next_to_build=Candidate}};
          false ->
              WaitQueue = queue:in(Candidate, State#state.wait_queue),
              get_build_candidate(
                  State#state{wait_queue=WaitQueue})
      end;
  get_build_candidate(both, State) ->
      {{value, Candidate}, WaitQueue} = queue:out(State#state.wait_queue),
      case check_build_deps(Candidate, State) of
          true -> %% independent
              {ok, State#state{wait_queue=WaitQueue, next_to_build=Candidate}};
          false ->
              WaitQueue = queue:in(Candidate, State#state.wait_queue),
              get_build_candidate(main_queue,
                  State#state{wait_queue=WaitQueue})
      end.
  
  
  %% External communication section
  %% ------------------------------------------------------------------
  
  -spec init_plugins(VCSPlugins :: [plugin_def()]) -> [Pid :: pid()].
  init_plugins(VCSPlugins) ->
      lists:map(
          fun({Plugin, PluginSettings}) -> 
                  {ok, Pid} = Plugin:start(PluginSettings),
                  erlang:monitor(Pid),
                  Pid 
          end, VCSPlugins).
  
  %% @doc true when candidate is independent from building packages
  -spec check_build_deps(Candidate :: rev_def(), State :: record()) -> true|false.
  check_build_deps(Candidate, State) ->
      {ok, NowBuilding} = list_building_revs(State),
      case caterpillar_dependencies:check_list(
              State#state.deps,
              Candidate,
              NowBuilding
          ) of
          {ok, [{depends, []}, {is_dependencie, []}]} ->
              true;
          _Other ->
              false
      end.
  