GitInput.pm: Don't do a chdir to the Git clone

[?]
Aug 12, 2013, 3:25 PM
3BTJRSU3VWCTVRL7Y2SARN2BZMECUIIVFAJPCPBRIRYCGLXHCBJQC

Dependencies

  • [2] NB2VOKIR Include names of committers in HipChat notifications
  • [3] BDSD2JLV * Speed up manifest generation.
  • [4] 6ZB4CIW6 Security: Improve checking of build products
  • [5] JAH3UPWA Support revision control systems via plugins
  • [*] 2GK5DOU7 * Downloading closures.
  • [*] AFTXA575 * $HYDRA_DATA environment variable.

Change contents

  • replacement in src/lib/Hydra/Helper/Nix.pm at line 23
    [3.1545][3.1545:1571]()
    captureStdoutStderr);
    [3.1545]
    [3.77]
    captureStdoutStderr run grab);
  • edit in src/lib/Hydra/Helper/Nix.pm at line 471
    [3.2123]
    [3.2123]
    }
    }
    sub run {
    my (%args) = @_;
    my $res = { stdout => "", stderr => "" };
    my $stdin = "";
    eval {
    local $SIG{ALRM} = sub { die "timeout\n" }; # NB: \n required
    alarm $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;
  • edit in src/lib/Hydra/Helper/Nix.pm at line 498
    [3.2129]
    [3.2129]
    return $res;
  • edit in src/lib/Hydra/Helper/Nix.pm at line 503
    [3.2133]
    [8.850]
    sub grab {
    my (%args) = @_;
    my $res = run(%args, grabStderr => 0);
    die "command `@{$args{cmd}}' failed with exit status $res->{status}" if $res->{status};
    return $res->{stdout};
    }
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 23
    [3.5546][3.5546:5593]()
    my $stdout = ""; my $stderr = ""; my $res;
    [3.5546]
    [3.5593]
    my $res;
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 27
    [3.5775][3.5775:5957]()
    ($res, $stdout, $stderr) = captureStdoutStderr(600, "git", "clone", "--branch", $branch, $uri, $clonePath);
    die "error cloning git repo at `$uri':\n$stderr" if $res;
    [3.5775]
    [3.5957]
    $res = run(cmd => ["git", "clone", "--branch", $branch, $uri, $clonePath], timeout => 600);
    die "error cloning git repo at `$uri':\n$res->{stderr}" if $res->{status};
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 30
    [3.5963][3.5963:6029]()
    chdir $clonePath or die $!; # !!! urgh, shouldn't do a chdir
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 34
    [3.6238][3.6238:6544]()
    ($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;
    [3.6238]
    [3.6544]
    $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};
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 43
    [3.7173][3.7173:7347]()
    ($res, $stdout, $stderr) = captureStdoutStderr(600, "git", "checkout", "$branch");
    die "error checking out Git branch '$branch' at `$uri':\n$stderr" if $res;
    [3.7173]
    [3.7347]
    $res = run(cmd => ["git", "checkout", "$branch"], dir => $clonePath);
    die "error checking out Git branch '$branch' at `$uri':\n$res->{stderr}" if $res->{status};
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 49
    [3.7509][3.7509:7722]()
    ($res, $stdout, $stderr) = captureStdoutStderr(600,
    "tg", "remote", "--populate", "origin");
    print STDERR "warning: `tg remote --populate origin' failed:\n$stderr" if $res;
    [3.7509]
    [3.7722]
    $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};
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 62
    [2.513][2.513:514]()
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 76
    [2.802][2.802:997]()
    my ($res, $stdout, $stderr) = captureStdoutStderr(600,
    ("git", "rev-parse", "$branch"));
    die "error getting revision number of Git branch '$branch' at `$uri':\n$stderr" if $res;
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 77
    [2.998][2.998:1140]()
    my ($revision) = split /\n/, $stdout;
    die "error getting a well-formated revision number of Git branch '$branch' at `$uri':\n$stdout"
    [2.998]
    [2.1140]
    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'"
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 80
    [2.1186][3.7738:7739](),[3.7738][3.7738:7739](),[3.7739][2.1187:1223]()
    my $ref = "refs/heads/$branch";
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 83
    [3.7885][3.7885:7907]()
    my $cachedInput ;
    [3.7885]
    [3.7907]
    my $cachedInput;
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 114
    [3.9235][3.9235:9484]()
    ($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;
    [3.9235]
    [3.9484]
    ($sha256, $storePath) = split ' ', grab(cmd => ["nix-prefetch-git", $clonePath, $revision], chomp => 1);
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 131
    [3.10066][3.10066:10401]()
    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;
    [3.10066]
    [3.10401]
    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);
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 157
    [2.1543][2.1543:1706]()
    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: $?";
    [2.1543]
    [2.1706]
    my $out = grab(cmd => ["git", "log", "--pretty=format:%H%x09%an%x09%ae%x09%at", "$rev1..$rev2"], dir => $clonePath);