Pass additional attributes for Git inputs

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’.
This commit is contained in:
Eelco Dolstra 2011-12-05 15:13:31 +01:00
parent 9032c55aa6
commit e9c88783ce

View file

@ -382,11 +382,11 @@ sub fetchInputGit {
# http://thread.gmane.org/gmane.linux.distributions.nixos/3569 # http://thread.gmane.org/gmane.linux.distributions.nixos/3569
# for a discussion. # for a discussion.
$ENV{"NIX_PREFETCH_GIT_DEEP_CLONE"} = "1"; $ENV{"NIX_PREFETCH_GIT_DEEP_CLONE"} = "1";
(my $res, $stdout, $stderr) = captureStdoutStderr(600, (my $res, $stdout, $stderr) = captureStdoutStderr(600,
("nix-prefetch-git", $clonePath, $revision)); ("nix-prefetch-git", $clonePath, $revision));
die "Cannot check out Git repository branch '$branch' at `$uri':\n$stderr" unless $res; die "Cannot check out Git repository branch '$branch' at `$uri':\n$stderr" unless $res;
($sha256, $storePath) = split ' ', $stdout; ($sha256, $storePath) = split ' ', $stdout;
txn_do($db, sub { 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 return
{ uri => $uri { uri => $uri
, storePath => $storePath , storePath => $storePath
, sha256hash => $sha256 , sha256hash => $sha256
, revision => $revision , revision => $revision
, revCount => int($revCount)
, gitTag => $gitTag
}; };
} }
@ -619,6 +629,8 @@ sub inputsToArgs {
push @res, "--arg", $input, ( push @res, "--arg", $input, (
"{ outPath = builtins.storePath " . $alt->{storePath} . "" . "{ outPath = builtins.storePath " . $alt->{storePath} . "" .
(defined $alt->{revision} ? "; rev = \"" . $alt->{revision} . "\"" : "") . (defined $alt->{revision} ? "; rev = \"" . $alt->{revision} . "\"" : "") .
(defined $alt->{revCount} ? "; revCount = " . $alt->{revCount} . "" : "") .
(defined $alt->{gitTag} ? "; gitTag = \"" . $alt->{gitTag} . "\"" : "") .
(defined $alt->{version} ? "; version = \"" . $alt->{version} . "\"" : "") . (defined $alt->{version} ? "; version = \"" . $alt->{version} . "\"" : "") .
";}" ";}"
); );