Doing a chdir in the parent is evil. For instance, we had Hydra core dumps ending up in the cloned directory. Therefore, the function ‘run’ allows doing a chdir in the child. The function ‘grab’ returns the child's stdout and throws an exception if the child fails.
3BTJRSU3VWCTVRL7Y2SARN2BZMECUIIVFAJPCPBRIRYCGLXHCBJQC }}sub run {my (%args) = @_;my $res = { stdout => "", stderr => "" };my $stdin = "";eval {local $SIG{ALRM} = sub { die "timeout\n" }; # NB: \n requiredalarm $args{timeout} if defined $args{timeout};my @x = ($args{cmd}, \$stdin, \$res->{stdout});push @x, \$res->{stderr} if $args{grabStderr} // 1;IPC::Run::run(@x,init => sub { chdir $args{dir} or die "changing to $args{dir}" if defined $args{dir}; });alarm 0;};if ($@) {die unless $@ eq "timeout\n"; # propagate unexpected errors$res->{status} = -1;$res->{stderr} = "timeout\n";} else {$res->{status} = $?;chomp $res->{stdout} if $args{chomp} // 0;
($res, $stdout, $stderr) = captureStdoutStderr(600, "git", "clone", "--branch", $branch, $uri, $clonePath);die "error cloning git repo at `$uri':\n$stderr" if $res;
$res = run(cmd => ["git", "clone", "--branch", $branch, $uri, $clonePath], timeout => 600);die "error cloning git repo at `$uri':\n$res->{stderr}" if $res->{status};
($res, $stdout, $stderr) = captureStdoutStderr(600,"git", "fetch", "-fu", "origin", "+$branch:$branch");($res, $stdout, $stderr) = captureStdoutStderr(600,"git", "fetch", "-fu", "origin") if $res;die "error fetching latest change from git repo at `$uri':\n$stderr" if $res;
$res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$branch"], dir => $clonePath, timeout => 600);$res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => 600) if $res->{status};die "error fetching latest change from git repo at `$uri':\n$res->{stderr}" if $res->{status};
($res, $stdout, $stderr) = captureStdoutStderr(600, "git", "checkout", "$branch");die "error checking out Git branch '$branch' at `$uri':\n$stderr" if $res;
$res = run(cmd => ["git", "checkout", "$branch"], dir => $clonePath);die "error checking out Git branch '$branch' at `$uri':\n$res->{stderr}" if $res->{status};
($res, $stdout, $stderr) = captureStdoutStderr(600,"tg", "remote", "--populate", "origin");print STDERR "warning: `tg remote --populate origin' failed:\n$stderr" if $res;
$res = run(cmd => ["tg", "remote", "--populate", "origin"], dir => $clonePath, timeout => 600);print STDERR "warning: `tg remote --populate origin' failed:\n$res->{stderr}" if $res->{status};
my ($revision) = split /\n/, $stdout;die "error getting a well-formated revision number of Git branch '$branch' at `$uri':\n$stdout"
my $revision = grab(cmd => ["git", "rev-parse", "$branch"], dir => $clonePath, chomp => 1);die "did not get a well-formated revision number of Git branch '$branch' at `$uri'"
($res, $stdout, $stderr) = captureStdoutStderr(600, "nix-prefetch-git", $clonePath, $revision);die "cannot check out Git repository branch '$branch' at `$uri':\n$stderr" if $res;($sha256, $storePath) = split ' ', $stdout;
($sha256, $storePath) = split ' ', grab(cmd => ["nix-prefetch-git", $clonePath, $revision], chomp => 1);
my $revCount = `git rev-list $revision | wc -l`; chomp $revCount;die "git rev-list failed" if $? != 0;my $gitTag = `git describe --always $revision`; chomp $gitTag;die "git describe failed" if $? != 0;my $shortRev = `git rev-parse --short $revision`; chomp $shortRev;die "git rev-parse failed" if $? != 0;
my $revCount = scalar(split '\n', grab(cmd => ["git", "rev-list", "$revision"], dir => $clonePath));my $gitTag = grab(cmd => ["git", "describe", "--always", "$revision"], dir => $clonePath, chomp => 1);my $shortRev = grab(cmd => ["git", "rev-parse", "--short", "$revision"], dir => $clonePath, chomp => 1);
my $out;IPC::Run::run(["git", "log", "--pretty=format:%H%x09%an%x09%ae%x09%at", "$rev1..$rev2"], \undef, \$out)or die "cannot get git logs: $?";
my $out = grab(cmd => ["git", "log", "--pretty=format:%H%x09%an%x09%ae%x09%at", "$rev1..$rev2"], dir => $clonePath);