Unverified Commit d10c3cc5 authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

Merge: more compatibility for git* fetchers

They're additional commits from #26877.
Changing names of the fetched stuff was changing very many hashes,
and I think it's better to avoid that for the moment to reduce work
needed by nixpkgs users.  The fetchers are expected to be commonly
used even outside nixpkgs, and the current naming wasn't that bad
usually.
parents f5364122 ab8dd33e
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
{stdenv, git, cacert, gitRepoToName}:
{stdenv, git, cacert}: let
  urlToName = url: rev: let
    inherit (stdenv.lib) removeSuffix splitString last;
    base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));

    matched = builtins.match "(.*).git" base;

    short = builtins.substring 0 7 rev;

    appendShort = if (builtins.match "[a-f0-9]*" rev) != null
      then "-${short}"
      else "";
  in "${if matched == null then base else builtins.head matched}${appendShort}";
in
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
, fetchSubmodules ? true, deepClone ? false
, branchName ? null
, name ? gitRepoToName url rev
, name ? urlToName url rev
, # Shell code executed after the file has been fetched
  # successfully. This can do things like check or transform the file.
  postFetch ? ""
+16 −11
Original line number Diff line number Diff line
{ lib }:

urlOrRepo: rev: let
  inherit (lib) removeSuffix splitString last;
  base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo)));
let
  inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem;

  matched = builtins.match "(.*).git" base;

  short = builtins.substring 0 7 rev;

  appendShort = if (builtins.match "[a-f0-9]*" rev) != null
    then "-${short}"
    else "";
in "${if matched == null then base else builtins.head matched}${appendShort}"
 No newline at end of file
  allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?=";
  sanitizeStoreName = s:
    let
      s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s);
      s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s';
    in
      s'';
in
  urlOrRepo: rev:
    let
      repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo))));
      rev' = baseNameOf rev;
    in
     "${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src"