From fe1652e13718889b3e561aea5f688ab58a696774 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Thu, 19 Jan 2012 13:49:42 -0800 Subject: Cache vsn info to avoid expensive vcs cmd calls --- src/rebar.erl | 3 +++ src/rebar_core.erl | 3 +++ src/rebar_utils.erl | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/rebar.erl b/src/rebar.erl index 7ce409c..b7d977f 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -96,6 +96,9 @@ run_aux(Commands) -> %% Initialize logging system rebar_log:init(), + %% Initialize vsn cache + _VsnCacheTab = ets:new(rebar_vsn_cache,[named_table, public]), + %% Convert command strings to atoms CommandAtoms = [list_to_atom(C) || C <- Commands], diff --git a/src/rebar_core.erl b/src/rebar_core.erl index ceb3d3c..63e6d50 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -90,6 +90,9 @@ process_commands([Command | Rest], ParentConfig) -> _ -> ok end, + %% Wipe out vsn cache to avoid invalid hits when + %% dependencies are updated + ets:delete_all_objects(rebar_vsn_cache), process_commands(Rest, ParentConfig). diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 72e6efa..afb8c00 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -189,6 +189,17 @@ expand_env_variable(InStr, VarName, RawVarValue) -> end. vcs_vsn(Vcs, Dir) -> + Key = {Vcs, Dir}, + case ets:lookup(rebar_vsn_cache, Key) of + [{Key, VsnString}] -> + VsnString; + [] -> + VsnString = vcs_vsn_1(Vcs, Dir), + ets:insert(rebar_vsn_cache, {Key, VsnString}), + VsnString + end. + +vcs_vsn_1(Vcs, Dir) -> case vcs_vsn_cmd(Vcs) of {unknown, VsnString} -> ?DEBUG("vcs_vsn: Unknown VCS atom in vsn field: ~p\n", [Vcs]), -- cgit v1.1