From 06dc6d8f865dba6e67f95403cd7c2f3652664684 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Thu, 19 Nov 2009 08:15:49 +0000 Subject: [PATCH] * for git inputs, check latest revision of branch (defaults to master for now), if there is change, only use input if last checkout was > hour ago. --- src/lib/Hydra/Helper/AddBuilds.pm | 37 +++++++++++++++++++------ src/lib/Hydra/Schema/CachedGitInputs.pm | 20 +++++++++++-- src/sql/hydra.sql | 4 ++- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 9df15dd1..6765f28b 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -223,15 +223,33 @@ sub fetchInputGit { my $sha256; my $storePath; - # Some simple caching: don't check a path more than once every N seconds. - (my $cachedInput) = $db->resultset('CachedGitInputs')->search( - {uri => $uri, lastseen => {">", $timestamp - 3600}}, - {rows => 1, order_by => "lastseen DESC"}); + my $branch = "master"; + + # First figure out the last-modified revision of the URI. + my $stdout; my $stderr; + (my $res, $stdout, $stderr) = captureStdoutStderr( + "git", "ls-remote", $uri, $branch); + die "Cannot get head revision of Git branch '$branch' at `$uri':\n$stderr" unless $res; + + (my $revision, my $ref) = split ' ', $stdout; + die unless $revision =~ /^[0-9a-fA-F]+$/; + + # Some simple caching: don't check a uri/branch more than once every hour, but prefer exact match on uri/branch/revision. + my $cachedInput ; + ($cachedInput) = $db->resultset('CachedGitInputs')->search( + {uri => $uri, branch => $branch, revision => $revision}, + {rows => 1}); + if (! defined $cachedInput ) { + ($cachedInput) = $db->resultset('CachedGitInputs')->search( + {uri => $uri, branch => $branch, lastseen => {">", $timestamp - 3600}}, + {rows => 1, order_by => "lastseen DESC"}); + } if (defined $cachedInput && isValidPath($cachedInput->storepath)) { $storePath = $cachedInput->storepath; $sha256 = $cachedInput->sha256hash; $timestamp = $cachedInput->timestamp; + $revision = $cachedInput->revision; } else { # Then download this revision into the store. @@ -244,19 +262,20 @@ sub fetchInputGit { # script. Thus, we leave `.git' in there. $ENV{"NIX_PREFETCH_GIT_LEAVE_DOT_GIT"} = "1"; - my $stdout; my $stderr; (my $res, $stdout, $stderr) = captureStdoutStderr( - "nix-prefetch-git", $uri); - die "Cannot check out Git repository `$uri':\n$stderr" unless $res; + "nix-prefetch-git", $uri, $revision); + die "Cannot check out Git repository branch '$branch' at `$uri':\n$stderr" unless $res; ($sha256, $storePath) = split ' ', $stdout; ($cachedInput) = $db->resultset('CachedGitInputs')->search( - {uri => $uri, sha256hash => $sha256}); + {uri => $uri, branch => $branch, sha256hash => $sha256}); if (!defined $cachedInput) { txn_do($db, sub { $db->resultset('CachedGitInputs')->create( { uri => $uri + , branch => $branch + , revision => $revision , timestamp => $timestamp , lastseen => $timestamp , sha256hash => $sha256 @@ -276,7 +295,7 @@ sub fetchInputGit { , uri => $uri , storePath => $storePath , sha256hash => $sha256 - , revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) + , revision => $revision }; } diff --git a/src/lib/Hydra/Schema/CachedGitInputs.pm b/src/lib/Hydra/Schema/CachedGitInputs.pm index 3768ede7..ceb460b5 100644 --- a/src/lib/Hydra/Schema/CachedGitInputs.pm +++ b/src/lib/Hydra/Schema/CachedGitInputs.pm @@ -18,6 +18,20 @@ __PACKAGE__->add_columns( is_nullable => 0, size => undef, }, + "branch", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "revision", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, "timestamp", { data_type => "integer", @@ -47,11 +61,11 @@ __PACKAGE__->add_columns( size => undef, }, ); -__PACKAGE__->set_primary_key("uri", "sha256hash"); +__PACKAGE__->set_primary_key("uri", "branch", "revision"); -# Created by DBIx::Class::Schema::Loader v0.04999_09 @ 2009-11-17 16:04:13 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WzfB4qf6XqvIll/gPFZE6Q +# Created by DBIx::Class::Schema::Loader v0.04999_09 @ 2009-11-18 21:46:00 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K9P4pi33P54ZB8D/6WzAYw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 361b55e5..3e3d6c9b 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -294,11 +294,13 @@ create table CachedSubversionInputs ( create table CachedGitInputs ( uri text not null, + branch text not null, + revision text not null, timestamp integer not null, -- when we first saw this hash lastSeen integer not null, -- when we last saw this hash sha256hash text not null, storePath text not null, - primary key (uri, sha256hash) + primary key (uri, branch, revision) ); create table CachedCVSInputs (