From 3985dde04ee0eb5d6a2e6778b1ade9aaacbe9d45 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 18 Feb 2022 08:12:44 +0100 Subject: [PATCH] unstableGitUpdater: Use single derivation for all branches This will reduce the number of build when updating a large number of packages at the same time (e.g. when updating all packages of a maintainer). --- pkgs/common-updater/unstable-updater.nix | 42 +++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/pkgs/common-updater/unstable-updater.nix b/pkgs/common-updater/unstable-updater.nix index ded31e1ddb9c..966834093711 100644 --- a/pkgs/common-updater/unstable-updater.nix +++ b/pkgs/common-updater/unstable-updater.nix @@ -16,7 +16,25 @@ let updateScript = writeShellScript "unstable-update-script.sh" '' set -ex - url="$1" + url="" + branch="" + + while (( $# > 0 )); do + flag="$1" + shift 1 + case "$flag" in + --url=*) + url="''${flag#*=}" + ;; + --branch=*) + branch="''${flag#*=}" + ;; + *) + echo "$0: unknown option ‘''${flag}’" + exit 1 + ;; + esac + done # By default we set url to src.url if [[ -z "$url" ]]; then @@ -27,9 +45,18 @@ let # Get info about HEAD from a shallow git clone tmpdir="$(${coreutils}/bin/mktemp -d)" - ${git}/bin/git clone --bare --depth=1 \ - ${lib.optionalString (branch != null) "--branch ${branch}"} \ - "$url" "$tmpdir" + + cloneArgs=( + --bare + --depth=1 + ) + + if [[ -n "$branch" ]]; then + cloneArgs+=(--branch="$branch") + fi + + ${git}/bin/git clone "''${cloneArgs[@]}" "$url" "$tmpdir" + pushd "$tmpdir" commit_date="$(${git}/bin/git show -s --pretty='format:%cs')" commit_sha="$(${git}/bin/git show -s --pretty='format:%H')" @@ -43,5 +70,10 @@ let --rev="$commit_sha" ''; -in [ updateScript url ] +in [ + updateScript + "--url=${builtins.toString url}" +] ++ lib.optionals (branch != null) [ + "--branch=${branch}" +]