mirror of
https://github.com/correl/rebar.git
synced 2024-11-15 03:00:18 +00:00
Cache vsn info to avoid expensive vcs cmd calls
This commit is contained in:
parent
0f3e5f8813
commit
fe1652e137
3 changed files with 17 additions and 0 deletions
|
@ -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],
|
||||
|
||||
|
|
|
@ -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).
|
||||
|
||||
|
||||
|
|
|
@ -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]),
|
||||
|
|
Loading…
Reference in a new issue