anchor.diff:  
   -export([preprocess/2,
            distclean/2]).
  -
  --define(HG_VERSION,  "1.4").
   
   %% ===================================================================
   %% Public API
  
positive.code:             %% App may not be on the code path, or the version that is doesn't
              %% match our regex. Either way, we want to pull our revision into
              %% the deps dir and try to use that
              require_source_engine(Source),
              AppDir = filename:join(Dir, App),
              use_source(AppDir, App, VsnRegex, Source),
              process_deps(Rest, [AppDir | Acc], Dir)
  
negative.code: download_source(AppDir, {hg, Url, Rev}) ->
      ok = filelib:ensure_dir(AppDir),
      Cmd = ?FMT("hg clone -u ~s ~s", [Rev, Url]),
      rebar_utils:sh(Cmd, [], filename:dirname(AppDir));
  download_source(AppDir, {git, Url, Rev}) ->
      ok = filelib:ensure_dir(AppDir),
      rebar_utils:sh(?FMT("git clone -n ~s", [Url]), [], filename:dirname(AppDir)),
      rebar_utils:sh(?FMT("git checkout ~s", [Rev]), [], AppDir).
  
  
  
  %% ===================================================================
  %% Source helper functions
  %% ===================================================================
  
  source_engine_avail({Name, _, _}) when Name == hg; Name == git ->
      case scm_client_vsn(Name) >= required_scm_client_vsn(Name) of
          true ->
              true;
          false ->
              ?ABORT("Rebar requires version ~p or higher of ~s\n",
                     [required_scm_client_vsn(Name), Name])
      end.
  
  scm_client_vsn(false, _VsnArg, _VsnRegex) ->
      false;
  scm_client_vsn(Path, VsnArg, VsnRegex) ->
      Info = os:cmd(Path ++ VsnArg),
      case re:run(Info, VsnRegex, [{capture, all_but_first, list}]) of
          {match, Match} ->
              list_to_tuple([list_to_integer(S) || S <- Match]);
          _ ->
              false
      end.
  
  required_scm_client_vsn(hg)  -> {1, 4};
  required_scm_client_vsn(git) -> {1, 6}.
  
  scm_client_vsn(hg) ->
      scm_client_vsn(os:find_executable(hg), " --version", "version (\\d+).(\\d+)");
  scm_client_vsn(git) ->
      scm_client_vsn(os:find_executable(git), " --version", "git version (\\d+).(\\d+)");
  scm_client_vsn(_) ->
      undefined.
  