boklm pushed to branch main at The Tor Project / Applications / RBM
Commits: f18daa3f by Nicolas Vigier at 2024-10-27T17:22:45+01:00 Bug 40006: Add option to avoid doing a git checkout when using the exec template function
The `exec_noco` option can be used to disable git or hg checkout when using the exec template function.
We start using this option in the `abbrev` and `timestamp` options, which are running git and hg commands which don't need a checkout.
- - - - -
3 changed files:
- doc/rbm_templates.asc - lib/RBM.pm - lib/RBM/DefaultConfig.pm
Changes:
===================================== doc/rbm_templates.asc ===================================== @@ -107,9 +107,11 @@ exec:: considered to be a script, which will be written to a temporary file and executed. The second argument of the exec function is an optional $options hash, used to override values of 'git_url', - 'hg_url', 'fetch', 'git_hash' or 'hg_hash'. If neither 'git_url' - nor 'hg_url' is set, the command is executed from the directory - where the 'rbm.conf' file is located. + 'hg_url', 'fetch', 'git_hash' or 'hg_hash'. Before running the + command a checkout of 'git_hash' or 'hg_hash' is done, unless + 'exec_noco' is set to true. If neither 'git_url' nor 'hg_url' + is set, the command is executed from the directory where the + 'rbm.conf' file is located.
path:: A function to return an absolute path. It takes a path as first
===================================== lib/RBM.pm ===================================== @@ -551,15 +551,18 @@ sub execute { CORE::state %cache; my $res_name = ''; my $old_cwd = getcwd; + my $exec_noco = ref $options eq 'HASH' && $options->{exec_noco}; 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-$project-/-$git_hash-/-$cmd"; return $cache{$res_name} if exists $cache{$res_name}; git_clone_fetch_chdir($project, $options); - my ($stdout, $stderr, $success, $exit_code) + if (!$exec_noco) { + my ($stdout, $stderr, $success, $exit_code) = capture_exec('git', 'checkout', $git_hash); - exit_error "Cannot checkout $git_hash:\n$stderr" unless $success; + exit_error "Cannot checkout $git_hash:\n$stderr" unless $success; + } git_submodule_init_sync_update() if project_config($project, 'git_submodule', $options); } elsif (project_config($project, 'hg_url', $options)) { @@ -568,9 +571,11 @@ sub execute { $res_name = "hg-$project-/-$hg_hash-/-$cmd"; return $cache{$res_name} if exists $cache{$res_name}; hg_clone_fetch_chdir($project, $options); - my ($stdout, $stderr, $success, $exit_code) + if (!$exec_noco) { + my ($stdout, $stderr, $success, $exit_code) = capture_exec('hg', 'update', '-C', $hg_hash); - exit_error "Cannot checkout $hg_hash:\n$stderr" unless $success; + exit_error "Cannot checkout $hg_hash:\n$stderr" unless $success; + } } else { chdir($config->{basedir}); }
===================================== lib/RBM/DefaultConfig.pm ===================================== @@ -126,9 +126,9 @@ our %default_config = ( abbrev_length => '12', abbrev => '[% IF c("git_url"); - exec("git log -1 --abbrev=" _ c("abbrev_length") _ " --format=%h " _ c("git_hash")); + exec("git log -1 --abbrev=" _ c("abbrev_length") _ " --format=%h " _ c("git_hash"), { exec_noco => 1 }); ELSE; - exec(c("hg") _ " id -i -r " _ c("hg_hash")); + exec(c("hg") _ " id -i -r " _ c("hg_hash"), { exec_noco => 1 }); END; %]', timestamp => sub { @@ -136,12 +136,14 @@ our %default_config = ( if (RBM::project_config($project, 'git_url', $options)) { my $git_hash = RBM::project_config($project, 'git_hash', $options); return RBM::execute($project, - "git show -s --format=format:%ct ${git_hash}^{commit}", $options); + "git show -s --format=format:%ct ${git_hash}^{commit}", + { %$options, exec_noco => 1 }); } elsif (RBM::project_config($project, 'hg_url', $options)) { my $hg = RBM::project_config($project, 'hg', $options); my $hg_hash = RBM::project_config($project, 'hg_hash', $options); my $changeset = RBM::execute($project, - "$hg export --noninteractive -r $hg_hash", $options); + "$hg export --noninteractive -r $hg_hash", + { %$options, exec_noco => 1 }); foreach my $line (split "\n", $changeset) { return $1 if ($line =~ m/^# Date (\d+) \d+/); }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/rbm/-/commit/f18daa3f93d1aec6...
tbb-commits@lists.torproject.org