From 954d9953941d6c94abb5d2d549bd18486d0b27ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 8 Oct 2016 19:07:20 +0200 Subject: [PATCH 1/2] nix-prefetch-git: escape string fields properly json requires certain characters to be escaped in strings. --- pkgs/build-support/fetchgit/nix-prefetch-git | 32 +++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 705d84c648b..54945d203af 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -322,6 +322,18 @@ clone_user_rev() { fi } +json_escape() { + local s="$1" + s="${s//\\/\\\\}" # \ + s="${s//\"/\\\"}" # " + s="${s//^H/\\\b}" # \b (backspace) + s="${s//^L/\\\f}" # \f (form feed) + s="${s// +/\\\n}" # \n (newline) + s="${s//^M/\\\r}" # \r (carriage return) + s="${s// /\\t}" # \t (tab) + echo "$s" +} print_results() { hash="$1" @@ -338,17 +350,15 @@ print_results() { fi fi if test -n "$hash"; then - echo "{" - echo " \"url\": \"$url\"," - echo " \"rev\": \"$fullRev\"," - echo " \"date\": \"$commitDateStrict8601\"," - echo -n " \"$hashType\": \"$hash\"" - if test -n "$fetchSubmodules"; then - echo "," - echo -n " \"fetchSubmodules\": true" - fi - echo "" - echo "}" + cat < Date: Sat, 8 Oct 2016 19:05:45 +0200 Subject: [PATCH 2/2] nix-prefetch-git: fix date field in some cases `git show` include tag information in the output this is suppressed by the parameter '-1' --- pkgs/build-support/fetchgit/nix-prefetch-git | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 54945d203af..f71d9ac55bc 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -291,8 +291,8 @@ _clone_user_rev() { pushd "$dir" >/dev/null 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") + commitDate=$(git show -1 --no-patch --pretty=%ci "$fullRev") + commitDateStrict8601=$(git show -1 --no-patch --pretty=%cI "$fullRev") popd >/dev/null # Allow doing additional processing before .git removal