Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchgit: add tag argument #50492

Closed
wants to merge 4 commits into from
Closed

fetchgit: add tag argument #50492

wants to merge 4 commits into from

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Nov 17, 2018

Motivation for this change

While it is possible to pass rev = tag to fetchgit, it may result in ambiguity when here is a branch with the same name as the tag. To be sure, we need to use rev = "refs/tags/${tag}".

Since that is quite ugly, this commit introduces a shortcut, allowing us to just inherit tag.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

Copy link
Member

@timokau timokau left a comment

Choose a reason for hiding this comment

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

Good idea! This should probably be documented somewhere right? Will this also indirectly affect fetchFromGitHub?

pkgs/build-support/fetchgit/default.nix Outdated Show resolved Hide resolved
While it is possible to pass `rev = tag` to fetchgit, it may result in ambiguity
when here is a branch with the same name as the tag. To be sure, we need to use
`rev = "refs/tags/${tag}"`.

Since that is quite ugly, this commit introduces a shortcut, allowing us to just
`inherit tag`.
@jtojnar
Copy link
Contributor Author

jtojnar commented Nov 17, 2018

I did not find any place where fetchgit is documented.

This will have no effect on fetchFromGit{Hub,Lab}; they require the rev attribute.

@timokau
Copy link
Member

timokau commented Nov 17, 2018

Well thats one upside of not having documentation I guess. Nothing to update.

Should we then do the same thing with fetchFrom...? Would be good for consistency and I feel like those are used more often than fetchgit (although a grep through the repository tells me otherwise).

@jtojnar
Copy link
Contributor Author

jtojnar commented Nov 17, 2018

Added the argument to fetchFromGit{Hub,Lab}.

Needed to escape the rev in fetchFromGitLab to avoid errors like:

building '/nix/store/cxfkh2lgfbhhpgcphsh8wkn2j25y50hn-source.drv'...

trying https://gitlab.gnome.org/api/v4/projects/gnumdk%2Flollypop-portal/repository/archive.tar.gz?sha=refs/tags/0.9.7
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15537  100 15537    0     0  15011      0  0:00:01  0:00:01 --:--:-- 15011
unpacking source archive /build/0.9.7
do not know how to unpack source archive /build/0.9.7
builder for '/nix/store/cxfkh2lgfbhhpgcphsh8wkn2j25y50hn-source.drv' failed with exit code 1

Also I am not sure about what should the rev introduced with #9273 and #15139 be. I used refs/tags/${tag} for now.

then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; }
else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs)
then { inherit rev tag fetchSubmodules; url = "${baseUrl}.git"; }
else ({ url = "${baseUrl}/archive/${revOrTag}.tar.gz"; } // privateAttrs)
Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to escape here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub does not seem to need escaping. GitLab does not need it either but fetchzip does, in order to be able to extract the file.

Copy link
Member

Choose a reason for hiding this comment

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

Oh nevermind I see the difference. Isn't there still some escaping necessary, just not of the /?

@marsam
Copy link
Contributor

marsam commented Nov 26, 2018

While it is possible to pass rev = tag to fetchgit, it may result in ambiguity when here is a branch with the same name as the tag. To be sure, we need to use rev = "refs/tags/${tag}".

AFAIK tags have precedence over a branch refs https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions, i.e. rev = "refs/tags/${tag}" should not be necessary

@jtojnar
Copy link
Contributor Author

jtojnar commented Nov 26, 2018

Then I do not understand why refs/tags/${version} is so frequent in nixpkgs.

escapeUriSegment "foo/bar?baz=qux&quux=quuz#corge"
=> "foo%2Fbar%3Fbaz%3Dqux%26quux%3Dquuz%23corge"
*/
escapeUriSegment = arg:
Copy link
Member

Choose a reason for hiding this comment

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

This sort of thing should not be done in Nix code because it's slow. You can also do escaping in the builder.

@edolstra
Copy link
Member

Not really in favor of this because it makes fetchgit even more complex, and adds another inconsistency with builtins.fetchGit.

@jtojnar jtojnar closed this Nov 26, 2018
@jtojnar jtojnar deleted the fetchgit-tag branch December 1, 2018 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants