Skip to content

Instantly share code, notes, and snippets.

@cognominal
Last active March 25, 2021 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognominal/9899069d8798862671554a87ae76c45a to your computer and use it in GitHub Desktop.
Save cognominal/9899069d8798862671554a87ae76c45a to your computer and use it in GitHub Desktop.
bisect using a raku oneliner #raku
#! /usr/bin/env raku
=begin pod
rk-bisect is given three arguments.
A file path, a raku one liner, and a sha1 (5 chars min).
A each stage of the bisection, $_ is set to
the string content of the file. The one liner
is executed and the commit is considered good if
the oneliner value is truthy.
Eventually rk-bisect print the sha1 of the first bad commit.
Below, the "bad" commit introduces a ♥ in the tested file.
That's a nice string delimiter though
$ git clone https://github.com/rakudo/rakudo
$ cd rakudo
$ rk-bisect src/Perl6/Compiler.nqp '!/♥/' b2971
"/Users/cog/rakudo".IO
Bisecting: 6048 revisions left to test after this (roughly 13 steps)
[59556c70b4f7d153096e7b674c168709c6d70eba] Addititonal fixes to slurpies on `if`
..............
87dc51f5147e9f9cf76fc46305d9490d91e022c6 is the first bad commit
=end pod
use MONKEY-SEE-NO-EVAL;
sub is-sha1($_) { m:i/ ^ <[0..9a..f]> ** 5..* $ / }
sub MAIN($file, $test, $last-known-good
# where { is-sha1($_)},
# $first-known-bad? where { is-sha1($_) }
) {
say $*CWD;
die "no such file '$file'" unless $file.IO ~~ :f;
sub test {
$_ = slurp $file;
EVAL $test;
}
sub r(*@s) {
print '.';
my $proc = run @s, :out;
$_ = $proc.out.slurp :close;
return m:i:s/(<[0..9a..f]>+) is the first bad commit/;
}
run <git bisect start>;
run <git bisect bad>;
run << git bisect good $last-known-good >>;
repeat {
if $_ = r 'git', 'bisect', test() ?? 'good' !! 'bad' {
say "\n$_";
last;
}
} while 1;
run <git bisect reset>, :err, :out;
CATCH {
say qq|error catched; run <git bisect reset> to reset state|;
run <git bisect reset>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment