Skip to content

Commit f649e15

Browse files
committed
Move commit shortening into a shared function (only implemented in Benchable and Committable for now)
1 parent fbf968b commit f649e15

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Benchable.p6

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ method process($message, $config, $code is copy) {
143143
for @commits -> $commit {
144144
# convert to real ids so we can look up the builds
145145
my $full-commit = self.to-full-commit($commit);
146-
my $short-commit = $commit.substr(0, 7);
146+
my $short-commit = self.get-short-commit($commit);
147147
if not defined $full-commit {
148148
%times{$short-commit}<err> = Cannot find this revision;
149149
} elsif not self.build-exists($full-commit) {
@@ -178,7 +178,7 @@ Z: loop (my int $x = 0; $x < @commits - 1; $x++) {
178178
if abs(%times{@commits[$x]}<min> - %times{@commits[$x + 1]}<min>) >= %times{@commits[$x]}<min>*0.1 {
179179
my ($new-commit, $exit-status, $exit-signal, $time) = self.get-output('git', 'rev-list', '--bisect', '--no-merges', @commits[$x] ~ '^..' ~ @commits[$x + 1]);
180180
if $exit-status == 0 and $new-commit.defined and $new-commit ne '' {
181-
my $short-commit = $new-commit.substr(0, 7);
181+
my $short-commit = self.get-short-commit($new-commit);
182182
if not self.build-exists($new-commit) {
183183
%times{$short-commit}<err> = No build for this commit;
184184
} elsif %times{$short-commit}:!exists and $short-commit ne @commits[$x] and $short-commit ne @commits[$x + 1] { # actually run the code
@@ -191,7 +191,7 @@ Z: loop (my int $x = 0; $x < @commits - 1; $x++) {
191191
}
192192
}
193193

194-
@commits .= map(*.substr(0, 7));
194+
@commits .= map({ self.get-short-commit($_) });
195195

196196
if @commits >= ITERATIONS {
197197
my $pfilename = 'plot.svg';

Committable.p6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ method process($message, $config, $code is copy) {
8888
$output ~= «exit signal = {Signal($signal)} ($signal if $signal != 0;
8989
}
9090
}
91-
my $short-commit = $commit.substr(0, 7);
91+
my $short-commit = self.get-short-commit($commit);
9292

9393
# Code below keeps results in order. Example state:
9494
# @result = [ { commits => [‘A’, ‘B’], output => ‘42‘ },

Whateverable.pm6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ multi method irc-privmsg-me($msg) {
7777

7878
method help($message) { See {SOURCE} } # override this in your bot
7979

80+
method get-short-commit($original-commit) {
81+
$original-commit ~~ /^ <xdigit> ** 7..40 $/ ?? $original-commit.substr(0, 7) !! $original-commit;
82+
}
83+
8084
method get-output(*@run-args, :$timeout = $!timeout, :$stdin) {
8185
my $out = Channel.new; # TODO switch to some Proc :merge thing once it is implemented
8286
my $proc = Proc::Async.new(|@run-args, :w(defined $stdin));

0 commit comments

Comments
 (0)