Add support for darcs repositories.

[?]
Feb 5, 2013, 6:50 PM
Q5HZWFCYP7E7CZB24WXHZP43M334SFL4GIZLOIAQS2OOVV4RR2WQC

Dependencies

  • [2] A43SLRSH Fix handling of IPC::Run::run exit status
  • [3] 5EQYVRWE Add a plugin mechanism
  • [4] WZ7PXAIT Doh
  • [5] 4HPT4SDD Revert "Remove now-unused SystemTypes table"
  • [6] JAH3UPWA Support revision control systems via plugins
  • [7] KW3M6NSR hydra: run nix-prefetch-git on local clone of git repo
  • [8] E7FID72S Remove the BuildMachines and BuildMachinesSystemTypes tables
  • [9] FDHQ2OLB Forgot to commit
  • [10] G2ZB6464 first test, not yet in buildprocess
  • [11] WWUOQ7V4 * hydra: indentation and fixed duplicate key in cachedgitinputs bug
  • [12] JTRG7RDQ add support for git as jobinput
  • [13] YDW2NUIW Fix "make check"
  • [14] 5SMQ2PLK Fix tests
  • [15] FANTYCR7 Materialize the number of finished builds
  • [16] P43FHUUV there are 43 tests
  • [17] D6EL7KR6 Fix broken test
  • [18] AK66K4KY Fix the test
  • [19] JD7AWXQG Remove now-unused SystemTypes table
  • [20] 4FWDVNWA Pass additional attributes for Git inputs
  • [21] KQS7DSKJ * Clean up indentation.
  • [22] DES4PSRL add basic query tests for JobStatus/LatestSucceeded/ActiveJobs
  • [23] CHQEG6WY Hydra/29: Added timeout to svn/git checkouts, job evaluation
  • [24] 3XM2QEGW Fix query-all-tables test count, there are more tables now
  • [*] OOQ2D3KC * Refactoring: move fetchInput out of hydra_scheduler into a separate
  • [*] D5QIOJGP * Move everything up one directory.
  • [*] N22GPKYT * Put info about logs / build products in the DB.
  • [*] O25D52TA initial support for mercurial

Change contents

  • edit in src/lib/Hydra/Helper/AddBuilds.pm at line 152
    [2.1617][5.2:3](),[5.7625][5.2:3]()
  • file addition: DarcsInput.pm (----------)
    [3.1]
    package Hydra::Plugin::DarcsInput;
    use strict;
    use parent 'Hydra::Plugin';
    use Digest::SHA qw(sha256_hex);
    use File::Path;
    use Hydra::Helper::Nix;
    use Nix::Store;
    sub supportedInputTypes {
    my ($self, $inputTypes) = @_;
    $inputTypes->{'darcs'} = 'Darcs checkout';
    }
    sub fetchInput {
    my ($self, $type, $name, $uri) = @_;
    return undef if $type ne "darcs";
    my $timestamp = time;
    my $sha256;
    my $storePath;
    my $revCount;
    my $cacheDir = getSCMCacheDir . "/git";
    mkpath($cacheDir);
    my $clonePath = $cacheDir . "/" . sha256_hex($uri);
    $uri =~ s|^file://||; # darcs wants paths, not file:// uris
    chdir $ENV{"TMPDIR"}; # sigh. darcs needs a writeable working directory
    my $stdout = ""; my $stderr = ""; my $res;
    if (! -d $clonePath) {
    # Clone the repository.
    ($res, $stdout, $stderr) = captureStdoutStderr(600,
    ("darcs", "get", "--lazy", $uri, $clonePath));
    die "Error getting darcs repo at `$uri':\n$stderr" if $res;
    }
    # Update the repository to match $uri.
    ($res, $stdout, $stderr) = captureStdoutStderr(600,
    ("darcs", "pull", "-a", "--repodir", $clonePath, "$uri"));
    die "Error fetching latest change from darcs repo at `$uri':\n$stderr" if $res;
    ($res, $stdout, $stderr) = captureStdoutStderr(600,
    ("darcs", "changes", "--last", "1", "--xml", "--repodir", $clonePath));
    die "Error getting revision ID of darcs repo at `$uri':\n$stderr" if $res;
    $stdout =~ /^<patch.*hash='([0-9a-fA-F-]+)'/sm; # sigh.
    my $revision = $1;
    die "Error obtaining revision from output: $stdout\nstderr = $stderr)" unless $revision =~ /^[0-9a-fA-F-]+$/;
    die "Error getting a revision identifier at `$uri':\n$stderr" if $res;
    # Some simple caching: don't check a uri/revision more than once.
    my $cachedInput ;
    ($cachedInput) = $self->{db}->resultset('CachedDarcsInputs')->search(
    {uri => $uri, revision => $revision},
    {rows => 1});
    if (defined $cachedInput && isValidPath($cachedInput->storepath)) {
    $storePath = $cachedInput->storepath;
    $sha256 = $cachedInput->sha256hash;
    $revision = $cachedInput->revision;
    $revCount = $cachedInput->revcount;
    } else {
    # Then download this revision into the store.
    print STDERR "checking out darcs repo $uri\n";
    my $tmpDir = File::Temp->newdir("hydra-darcs-export.XXXXXX", CLEANUP => 1, TMPDIR => 1) or die;
    (system "darcs", "get", "--lazy", $clonePath, "$tmpDir/export", "--quiet",
    "--to-match", "hash $revision") == 0
    or die "darcs export failed";
    $revCount = `darcs changes --count --repodir $tmpDir/export`; chomp $revCount;
    die "darcs changes --count failed" if $? != 0;
    system "rm", "-rf", "$tmpDir/export/_darcs";
    $storePath = addToStore("$tmpDir/export", 1, "sha256");
    $sha256 = queryPathHash($storePath);
    $sha256 =~ s/sha256://;
    txn_do($self->{db}, sub {
    $self->{db}->resultset('CachedDarcsInputs')->update_or_create(
    { uri => $uri
    , revision => $revision
    , revcount => $revCount
    , sha256hash => $sha256
    , storepath => $storePath
    });
    });
    }
    $revision =~ /^([0-9]+)/;
    my $shortRev = $1;
    return
    { uri => $uri
    , storePath => $storePath
    , sha256hash => $sha256
    , revision => $revision
    , revCount => int($revCount)
    , shortRev => $shortRev
    };
    }
    1;
  • file addition: CachedDarcsInputs.pm (----------)
    [27.477]
    use utf8;
    package Hydra::Schema::CachedDarcsInputs;
    # Created by DBIx::Class::Schema::Loader
    # DO NOT MODIFY THE FIRST PART OF THIS FILE
    =head1 NAME
    Hydra::Schema::CachedDarcsInputs
    =cut
    use strict;
    use warnings;
    use base 'DBIx::Class::Core';
    =head1 TABLE: C<CachedDarcsInputs>
    =cut
    __PACKAGE__->table("CachedDarcsInputs");
    =head1 ACCESSORS
    =head2 uri
    data_type: 'text'
    is_nullable: 0
    =head2 branch
    data_type: 'text'
    is_nullable: 0
    =head2 revision
    data_type: 'text'
    is_nullable: 0
    =head2 sha256hash
    data_type: 'text'
    is_nullable: 0
    =head2 storepath
    data_type: 'text'
    is_nullable: 0
    =cut
    __PACKAGE__->add_columns(
    "uri",
    { data_type => "text", is_nullable => 0 },
    "revision",
    { data_type => "text", is_nullable => 0 },
    "revcount",
    { data_type => "integer", is_nullable => 0 },
    "sha256hash",
    { data_type => "text", is_nullable => 0 },
    "storepath",
    { data_type => "text", is_nullable => 0 },
    );
    =head1 PRIMARY KEY
    =over 4
    =item * L</uri>
    =item * L</branch>
    =item * L</revision>
    =back
    =cut
    __PACKAGE__->set_primary_key("uri", "revision");
    # Created by DBIx::Class::Schema::Loader v0.07014 @ 2011-12-05 14:15:43
    # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fx3yosWMmJ+MnvL/dSWtFA
    1;
  • edit in src/sql/hydra.sql at line 325
    [29.2816]
    [29.2816]
    create table CachedDarcsInputs (
    uri text not null,
    revision text not null,
    sha256hash text not null,
    storePath text not null,
    revCount integer not null,
    primary key (uri, revision)
    );
  • file addition: upgrade-darcs.sql (----------)
    [27.3004]
    create table CachedDarcsInputs (
    uri text not null,
    revision text not null,
    sha256hash text not null,
    storePath text not null,
    revCount integer not null,
    primary key (uri, revision)
    );
  • replacement in tests/query-all-tables.pl at line 10
    [5.497][4.0:30]()
    use Test::Simple tests => 41;
    [5.497]
    [5.527]
    use Test::Simple tests => 45;