From bd75f32309dbaed6f4266056f186c34d3d19d8f9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 28 May 2015 21:52:43 +0200 Subject: Add tool for diffing channel generations --- nix-script-channel-diff-generations.sh | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 nix-script-channel-diff-generations.sh (limited to 'nix-script-channel-diff-generations.sh') diff --git a/nix-script-channel-diff-generations.sh b/nix-script-channel-diff-generations.sh new file mode 100755 index 0000000..5e65397 --- /dev/null +++ b/nix-script-channel-diff-generations.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh + +usage() { + cat <&2 + $(help_synopsis "${BASH_SOURCE[0]}" "[-g ] [-w ] [-n ] [-h]") + + -g | Use this command instead of 'diff --name-only' (currently no support for multi-word args) + -w | Path to working-copy of nixpkgs git repo, default: $RC_NIXPKGS + -n | Generations to show diff in form a..b + -h | Show this help and exit + +$(help_end) +EOS +} + +GEN_A= +GEN_B= +WC=$RC_NIXPKGS +GIT="diff --name-only" + +explain() { + stdout $* + $* +} + +while getopts "g:w:n:h" OPTION +do + case $OPTION in + g) + GIT=$OPTARG + dbg "GIT = $GIT" + ;; + + w) + WC=$OPTARG + dbg "WC = $WC" + ;; + + n) + GEN_A=$(echo $OPTARG | cut -d "." -f 1) + GEN_B=$(echo $OPTARG | cut -d "." -f 3) + + [[ -z "$GEN_A" || -z "$GEN_B" ]] && \ + stderr "Parsing error for '$OPTARG'" && usage && exit 1 + + dbg "GEN_A = $GEN_A" + dbg "GEN_B = $GEN_B" + ;; + + h) + usage + exit 1 + ;; + esac +done + +[[ -z "$GEN_A" || -z "$GEN_B" ]] && \ + stderr "No generation information" && usage && exit 1 + +pathof() { + echo "/nix/var/nix/profiles/per-user/root/channels-$1-link/nixos/nixpkgs/.version-suffix" +} + +version_string() { + local path=$(pathof $1) + local version=$(cat $path) + + [[ -z "$version" ]] && \ + stderr "No commit version information for generation $1" && exit 1 + + echo $version + +} + +commit_for() { + echo $(version_string $1) | cut -d . -f 2 +} + +__git() { + explain git --git-dir="$WC/.git" --work-tree="$WC" $* +} + +A=$(commit_for $GEN_A) +B=$(commit_for $GEN_B) + +stdout "A = $A" +stdout "B = $B" + +[[ "$A" -eq "$B" ]] && \ + echo "Same hash for both generations. There won't be a diff" && exit 1 + +if [[ -z "$WC" ]] +then + echo "$A..$B" +else + __git $GIT "$A..$B" +fi + +stdout "Ready" + -- cgit v1.2.3