[tbb-commits] [rbm/master] Bug 33283: Add caching for the exec template function
sysrqb at torproject.org
sysrqb at torproject.org
Wed Feb 19 17:49:43 UTC 2020
commit ce6b9136fc9e006536b34844946d67aa92cc0c21
Author: Nicolas Vigier <boklm at torproject.org>
Date: Wed Feb 12 11:16:22 2020 +0100
Bug 33283: Add caching for the exec template function
---
lib/RBM.pm | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/RBM.pm b/lib/RBM.pm
index 4db951a..f419c24 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -475,10 +475,14 @@ sub run_script {
sub execute {
my ($project, $cmd, $options) = @_;
+ CORE::state %cache;
+ my $res_name;
my $old_cwd = getcwd;
if (project_config($project, 'git_url', $options)) {
my $git_hash = project_config($project, 'git_hash', $options)
|| exit_error "No git_hash specified for project $project";
+ $res_name = "git-$git_hash-$cmd";
+ return $cache{$res_name} if exists $cache{$res_name};
git_clone_fetch_chdir($project, $options);
my ($stdout, $stderr, $success, $exit_code)
= capture_exec('git', 'checkout', $git_hash);
@@ -494,6 +498,8 @@ sub execute {
} elsif (project_config($project, 'hg_url', $options)) {
my $hg_hash = project_config($project, 'hg_hash', $options)
|| exit_error "No hg_hash specified for project $project";
+ $res_name = "hg-$hg_hash-$cmd";
+ return $cache{$res_name} if exists $cache{$res_name};
hg_clone_fetch_chdir($project, $options);
my ($stdout, $stderr, $success, $exit_code)
= capture_exec('hg', 'update', '-C', $hg_hash);
@@ -503,7 +509,8 @@ sub execute {
= run_script($project, $cmd, \&capture_exec);
chdir($old_cwd);
chomp $stdout;
- return $success ? $stdout : undef;
+ $cache{$res_name} = $success ? $stdout : undef;
+ return $cache{$res_name};
}
sub gpg_id {
More information about the tbb-commits
mailing list