Skip to content

Commit

Permalink
nix-prefetch-git: Include the date in the machine-readable output on
Browse files Browse the repository at this point in the history
stdout, in strict ISO 8601 format.

This will be helpful for automatically updating fetchgit expressions
and the dates in version numbers associated with them.
  • Loading branch information
DavidEGrayson authored and zimbatm committed Jul 3, 2016
1 parent 77ea161 commit f56ab9e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkgs/build-support/fetchgit/nix-prefetch-git
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ http_proxy=${http_proxy:-}
fullRev=
humanReadableRev=
commitDate=
commitDateStrict8601=

if test -n "$deepClone"; then
deepClone=true
Expand Down Expand Up @@ -287,9 +288,12 @@ _clone_user_rev() {
fi;;
esac

fullRev="$(cd "$dir" && (git rev-parse "$rev" 2> /dev/null || git rev-parse "refs/heads/$branchName") | tail -n1)"
humanReadableRev="$(cd "$dir" && (git describe "$fullRev" 2> /dev/null || git describe --tags "$fullRev" 2> /dev/null || echo -- none --))"
commitDate="$(cd "$dir" && git show --no-patch --pretty=%ci "$fullRev")"
pushd "$dir"
fullRev=$( (git rev-parse "$rev" 2>/dev/null || git rev-parse "refs/heads/$branchName") | tail -n1)
humanReadableRev=$(git describe "$fullRev" 2> /dev/null || git describe --tags "$fullRev" 2> /dev/null || echo -- none --)
commitDate=$(git show --no-patch --pretty=%ci "$fullRev")
commitDateStrict8601=$(git show --no-patch --pretty=%cI "$fullRev")
popd

# Allow doing additional processing before .git removal
eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK"
Expand Down Expand Up @@ -337,6 +341,7 @@ print_results() {
echo "{"
echo " \"url\": \"$url\","
echo " \"rev\": \"$fullRev\","
echo " \"date\": \"$commitDateStrict8601\","
echo -n " \"$hashType\": \"$hash\""
if test -n "$fetchSubmodules"; then
echo ","
Expand Down

3 comments on commit f56ab9e

@clhodapp
Copy link
Contributor

@clhodapp clhodapp commented on f56ab9e Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is kind of obnoxious because it causes the format of nix-prefetch-git to deviate from the format of fetchgit, so you can't just plug the one into the other with a builtins.parseJSON anymore. I'm thinking about issuing a PR to take it back out or else to make the fetchgit in nixpkgs accept (but ignore) extra arguments...

@zimbatm
Copy link
Member

@zimbatm zimbatm commented on f56ab9e Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a short term fix you could extend fetchgit to accept an optional date argument. This could also be used to set the version part in the name=${pname}-${version} attribute if none is provided.

Longer term it might make sense for all fetchers to accept an optional meta attribute that we can use to stuff that kind of meta-data, and which would be re-exported on the derivation.

@clhodapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand, it seems like only one of those can be the "active" solution to this problem at a time: for fetchgit in particular, either date is read and used to inform the version or else date moves to this new meta object and does not inform the version. If that is correct, I think it would be a better idea to implement the meta field in all fetchers, as described, as an unrelated feature to this issue. This issue would then be solved (in the long term) by recognizing the date field in fetchgit so that we get the desirable version-effecting property.

Please sign in to comment.