From e9c88783cee0d30b411d10224db6fb7caf82d6c0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 5 Dec 2011 15:13:31 +0100 Subject: [PATCH] Pass additional attributes for Git inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ‘revCount’ attribute is the number of commits in the history of the revision. This is useful if you need a monotonically increasing version number. The ‘gitTag’ attribute is the output of ‘git describe’, e.g. ‘v1.0.4-14-g2414721’ to indicate that the current revision is 14 commits after the tag ‘v1.0.4’. --- src/lib/Hydra/Helper/AddBuilds.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index e1f48bea..3a7e9e6c 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -382,11 +382,11 @@ sub fetchInputGit { # http://thread.gmane.org/gmane.linux.distributions.nixos/3569 # for a discussion. $ENV{"NIX_PREFETCH_GIT_DEEP_CLONE"} = "1"; - + (my $res, $stdout, $stderr) = captureStdoutStderr(600, ("nix-prefetch-git", $clonePath, $revision)); die "Cannot check out Git repository branch '$branch' at `$uri':\n$stderr" unless $res; - + ($sha256, $storePath) = split ' ', $stdout; txn_do($db, sub { @@ -400,11 +400,21 @@ sub fetchInputGit { }); } + # For convenience in producing readable version names, pass the + # number of commits in the history of this revision (‘revCount‘) + # and the output of git-describe (‘gitTag’). + 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; + return { uri => $uri , storePath => $storePath , sha256hash => $sha256 , revision => $revision + , revCount => int($revCount) + , gitTag => $gitTag }; } @@ -619,6 +629,8 @@ sub inputsToArgs { push @res, "--arg", $input, ( "{ outPath = builtins.storePath " . $alt->{storePath} . "" . (defined $alt->{revision} ? "; rev = \"" . $alt->{revision} . "\"" : "") . + (defined $alt->{revCount} ? "; revCount = " . $alt->{revCount} . "" : "") . + (defined $alt->{gitTag} ? "; gitTag = \"" . $alt->{gitTag} . "\"" : "") . (defined $alt->{version} ? "; version = \"" . $alt->{version} . "\"" : "") . ";}" );