anchor.diff:  
   -export([preprocess/2,
            distclean/2]).
  -
  --define(HG_VERSION,  "1.4").
   
   %% ===================================================================
   %% Public API
  
positive.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)).
  
  
  %% ===================================================================
  %% Source helper functions
  %% ===================================================================
  
  source_engine_avail({hg, _, _}) ->
      Path = os:find_executable("hg"),
      ?DEBUG("which hg = ~p\n", [Path]),
      case Path of
          false ->
              false;
          _ ->
              ensure_required_scm_client(hg, Path)
      end;
  source_engine_avail(_) ->
      false.
  
  %% We expect the initial part of the version string to be of the form:
  %% "Mercurial Distributed SCM (version 1.4.1+20091201)". Rebar
  %% requires version 1.4 or higher.
  ensure_required_scm_client(hg, Path) ->
      Info = os:cmd(Path ++ " --version"),
      case re:run(Info, "version (\\d*\.\\d*\.\\d*)", [{capture, all_but_first, list}]) of
          {match, [Vsn]} ->
              case Vsn >= ?HG_VERSION of
                  true ->
                      true;
                  false ->
                      ?ABORT("Rebar requires version ~p or higher of hg (~p)~n",
                          [?HG_VERSION, Path])
              end;
          _ ->
              false
      end.
  
negative.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
              AppDir = filename:join(Dir, App),
              use_source(AppDir, App, VsnRegex, Source),
              process_deps(Rest, [AppDir | Acc], Dir)
  