summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYurii Rashkovskii <yrashk@spawngrid.com>2012-01-19 13:49:42 -0800
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-02-02 21:54:15 +0100
commitfe1652e13718889b3e561aea5f688ab58a696774 (patch)
treea495899c7df81d45c4f68f819b19e1862aa05a83 /src
parent0f3e5f8813eb9c900e95cd74c60e0ea4c8fba5dd (diff)
Cache vsn info to avoid expensive vcs cmd calls
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl3
-rw-r--r--src/rebar_core.erl3
-rw-r--r--src/rebar_utils.erl11
3 files changed, 17 insertions, 0 deletions
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]),