This is an automated email from the git hooks/post-receive script.
boklm pushed a commit to branch main in repository builders/rbm.
commit a6ccc103fe59f6b520777308af92bf98113e2c90 Author: Nicolas Vigier boklm@torproject.org AuthorDate: Tue Nov 1 18:22:58 2022 +0100
Bug 40048: Add a hg_clone_subdir option --- doc/rbm_config.asc | 7 +++++++ lib/RBM.pm | 21 ++++++++++++++------- lib/RBM/DefaultConfig.pm | 1 + 3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/doc/rbm_config.asc b/doc/rbm_config.asc index dc045e2..226ccae 100644 --- a/doc/rbm_config.asc +++ b/doc/rbm_config.asc @@ -145,6 +145,13 @@ hg_clone_dir:: The directory used to store clones of mercurial repositories. The default value is +hg_clones+.
+hg_clone_subdir:: + If this option is set, the repository is cloned in a + subdirectory with that name. This is useful if a single project + requires clones of multiple mercurial repositories, for example + using a different +hg_url+ in each +targets+ or +steps+. + The default value is +.+, which means that no subdirectory is used. + hg_opt:: This option contains options that should be passed on the mercurial command line. This can for instance be useful if you diff --git a/lib/RBM.pm b/lib/RBM.pm index 86d9a9d..2209890 100644 --- a/lib/RBM.pm +++ b/lib/RBM.pm @@ -476,8 +476,8 @@ sub git_clone_fetch_chdir { }
sub hg_need_fetch { - my ($project, $options) = @_; - return 0 if $config->{_rbm}{fetched_projects}{$project}; + my ($project, $subdir, $options) = @_; + return 0 if $config->{_rbm}{hg_fetched_projects}{$project}{$subdir}; my $fetch = project_config($project, 'fetch', $options); if ($fetch eq 'if_needed') { my $hg_hash = project_config($project, 'hg_hash', $options) @@ -495,18 +495,25 @@ sub hg_clone_fetch_chdir { 'hg_clone_dir', $options))); my $hg_url = shell_quote(project_config($project, 'hg_url', $options)) || exit_error "hg_url is undefined"; - my $sq_project = shell_quote($project); - if (!chdir rbm_path("$clonedir/$project")) { + my $subdir = project_config($project, 'hg_clone_subdir', $options); + exit_error "hg_clone_subdir ($subdir) cannot be '..'" if $subdir eq '..'; + exit_error "hg_clone_subdir ($subdir) cannot include / or \" + if $subdir =~ m|[\/]|; + my $destdir = $subdir eq '.' ? $project : "$project/$subdir"; + my $sq_destdir = shell_quote($destdir); + if (!chdir rbm_path("$clonedir/$destdir")) { chdir $clonedir || exit_error "Can't enter directory $clonedir: $!"; - if (system("$hg clone -q $hg_url $sq_project") != 0) { + mkdir $project if $subdir ne '.'; + if (system("$hg clone -q $hg_url $sq_destdir") != 0) { exit_error "Error cloning $hg_url"; } - chdir($project) || exit_error "Error entering $project directory"; + chdir($destdir) || exit_error "Error entering $destdir directory"; } - if (hg_need_fetch($project, $options)) { + if (hg_need_fetch($project, $subdir, $options)) { system("$hg pull -q $hg_url") == 0 || exit_error "Error pulling changes from $hg_url"; } + $config->{_rbm}{hg_fetched_projects}{$project}{$subdir} = 1; }
sub run_script { diff --git a/lib/RBM/DefaultConfig.pm b/lib/RBM/DefaultConfig.pm index b60d5c2..32072c4 100644 --- a/lib/RBM/DefaultConfig.pm +++ b/lib/RBM/DefaultConfig.pm @@ -116,6 +116,7 @@ our %default_config = ( output_dir => 'out', git_clone_dir => 'git_clones', hg_clone_dir => 'hg_clones', + hg_clone_subdir => '.', fetch => 'if_needed', pkg_type => 'build', build => '[% INCLUDE build -%]',