summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>2020-05-07 11:54:14 +0200
committerDaniel Smith <Daniel.Smith@qt.io>2020-05-15 07:39:38 +0000
commitc6aa7debde5fa010fc43023b41c94de64634a58f (patch)
tree6b4526cb808b80eebe5d5f0755a5e19af56568f5
parent44bdb4b8d3d43f15b70d819a6d391b62c554b6b5 (diff)
downloadqtrepotools-c6aa7debde5fa010fc43023b41c94de64634a58f.tar.gz
make gerrit-bot pass the branch name to sanitize-commit
guessing the target branch with the help of git-merge-base is unreliable when the user does a cross-branch push or the commit has simply an old base. therefore, explicitly pass in the branch if we already know it, which is the case on the server. Fixes: QTQAINFRA-3322 Started-by: Daniel Smith <daniel.smith@qt.io> Change-Id: I5fd1e827b9e169f4aa2eb3590bc4f252037d6ba0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Daniel Smith <Daniel.Smith@qt.io>
-rwxr-xr-xgit-hooks/gerrit-bot2
-rwxr-xr-xgit-hooks/sanitize-commit41
2 files changed, 25 insertions, 18 deletions
diff --git a/git-hooks/gerrit-bot b/git-hooks/gerrit-bot
index 287ad98..c65f262 100755
--- a/git-hooks/gerrit-bot
+++ b/git-hooks/gerrit-bot
@@ -45,6 +45,7 @@ use Gerrit::REST;
# (note that these entries are NOT namespaced with the instance).
# The magic string @SHA1@ is replaced by the commit to be checked;
# @PROJ@ by the gerrit project the worker is run for.
+# @BRANCH@ is the branch the change was submitted to.
# It is expected to dump a Gerrit ReviewInput JSON entity to stdout.
# The output from all workers is merged.
# excluded (optional)
@@ -194,6 +195,7 @@ sub process_commit($$$$$)
die "workers.$worker not set.\n" if (!defined($worker));
$worker =~ s/\@PROJ\@/$project/g;
$worker =~ s/\@SHA1\@/$rev/g;
+ $worker =~ s/\@BRANCH\@/$branch/g;
my $output;
open VERDICT, $worker." 2>&1 |" or die "cannot run worker '$w': ".$!;
{
diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit
index 020fb94..724b483 100755
--- a/git-hooks/sanitize-commit
+++ b/git-hooks/sanitize-commit
@@ -13,16 +13,17 @@ use Config;
use Cwd;
use Encode;
use File::Spec qw(path);
-use List::Util qw(first);
+use List::Util qw(first any);
-if ($#ARGV < 0 or $#ARGV > 2 or ($#ARGV >= 1 && $ARGV[1] !~ /^(easy|strict|gerrit-rest)$/)) {
- print STDERR "Usage: $0 <sha1> [{easy|strict|gerrit-rest} [instance]]\n";
+if ($#ARGV < 0 or $#ARGV > 3 or ($#ARGV >= 1 && $ARGV[1] !~ /^(easy|strict|gerrit-rest)$/)) {
+ print STDERR "Usage: $0 <sha1> [{easy|strict|gerrit-rest} [<instance> [<branch>]]]\n";
exit 2;
}
my $sha1 = $ARGV[0];
my $gerrit_rest = ($#ARGV >= 1 && $ARGV[1] eq "gerrit-rest");
my $strict = $gerrit_rest || ($#ARGV >= 1 && $ARGV[1] eq "strict");
-my $instance = ($#ARGV == 2) ? $ARGV[2] : "default";
+my $instance = ($#ARGV >= 2) ? $ARGV[2] : "default";
+my $target = $#ARGV == 3 && $ARGV[3];
my $repo = getcwd();
$repo =~ s,/?\.git$,,;
@@ -336,20 +337,24 @@ my $handleLts = 0;
my $ltsForSha1 = '';
if ($foundDev && $foundLts) {
$handleLts = 1;
- my $refPfx = ($seenOrigin ? "refs/remotes/origin" : "refs/heads");
- chomp(my $sha1Base = `git merge-base $sha1 $refPfx/dev`);
- foreach my $lts (@LTS) {
- next if (!defined($nonDevHeads{$lts}));
- my $key = "cached-lts-$lts-fork";
- $key =~ s/\./-/g; # so the dot in $lts isn't a section name boundary in the key
- my $diverge = $config{$key};
- if (!$diverge) {
- chomp($diverge = `git merge-base $refPfx/dev $refPfx/$lts`);
- system("git config sanity.$instance.$key $diverge");
- }
- if ($sha1Base eq $diverge) {
- $ltsForSha1 = $lts;
- last;
+ if (defined($target)) {
+ $ltsForSha1 = $1 if ($target =~ /^(\d+\.\d+)/ && any { $1 eq $_ } @LTS);
+ } else {
+ my $refPfx = ($seenOrigin ? "refs/remotes/origin" : "refs/heads");
+ chomp(my $sha1Base = `git merge-base $sha1 $refPfx/dev`);
+ foreach my $lts (@LTS) {
+ next if (!defined($nonDevHeads{$lts}));
+ my $key = "cached-lts-$lts-fork";
+ $key =~ s/\./-/g; # so the dot in $lts isn't a section name boundary in the key
+ my $diverge = $config{$key};
+ if (!$diverge) {
+ chomp($diverge = `git merge-base $refPfx/dev $refPfx/$lts`);
+ system("git config sanity.$instance.$key $diverge");
+ }
+ if ($sha1Base eq $diverge) {
+ $ltsForSha1 = $lts;
+ last;
+ }
}
}
}