Cache vsn info to avoid expensive vcs cmd calls

This commit is contained in:
Yurii Rashkovskii 2012-01-19 13:49:42 -08:00 committed by Tuncer Ayaz
parent 0f3e5f8813
commit fe1652e137
3 changed files with 17 additions and 0 deletions

View file

@ -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],

View file

@ -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).

View file

@ -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]),