summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-02-14 16:06:22 +0100
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-06-12 10:18:14 +0000
commit62648ad92d13d29b924fa9dc2419cfb5e812846c (patch)
treea9685a637e49159bc096c84b36a728248dc00dd3
parent6e9bf2c01ed61840fde531a6d8d01a8493a0d151 (diff)
rewrite watch handling
fundamentally change how the data is queried from git. this has some marginal unnecessary cost for the case where no applicable watches are actually present, but the code is clearer this way. Change-Id: I0a89401a9f199b69da7471ca551178f5d89b8a4f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rwxr-xr-xgit-hooks/gerrit-bot-extras32
1 files changed, 12 insertions, 20 deletions
diff --git a/git-hooks/gerrit-bot-extras b/git-hooks/gerrit-bot-extras
index 32e38c4..5b8dd5a 100755
--- a/git-hooks/gerrit-bot-extras
+++ b/git-hooks/gerrit-bot-extras
@@ -65,34 +65,26 @@ for my $w (split(/\s+/, getcfg('watches', ""))) {
next if (defined($p) && $project !~ qr/^$p$/);
my $f = $config{'watches.'.$w.'.files'};
die "watches.$w.files not set.\n" if (!defined($f));
- $watch_files{$w} = qr/^$f$/;
+ $watch_files{$w} = qr/^$f$/m;
$watch_messages{$w} = $config{'watches.'.$w.'.message'};
my $i = $config{'watches.'.$w.'.invite'};
$watch_invites{$w} = defined($i) ? [ split(/\s+/, $i) ] : [];
push @watches, $w;
}
-my $subject;
-
-if (@watches) {
- my @touched = `git show --pretty=\%s --name-only --ignore-submodules -C $rev`;
- chop(@touched);
- $subject = shift @touched;
- shift @touched; # empty line
- for my $w (@watches) {
- for my $file (@touched) {
- if ($file =~ $watch_files{$w}) {
- push @messages, $watch_messages{$w} if (defined($watch_messages{$w}));
- push @invite, @{$watch_invites{$w}};
- last;
- }
- }
- }
+my ($subject, $files);
+{
+ local $/;
+ my $output = `git show --pretty=\%s\%x00 --name-only --ignore-submodules -C $rev`;
+ ($subject, $files) = split(/\x00/, $output);
}
-if (!defined($subject)) {
- $subject = `git show --pretty=\%s -s $rev`;
- chop($subject);
+for my $w (@watches) {
+ if ($files =~ /$watch_files{$w}/) {
+ push @messages, $watch_messages{$w} if (defined($watch_messages{$w}));
+ push @invite, @{$watch_invites{$w}};
+ last;
+ }
}
my $cr = 0;