Merge pull request #19369 from Mic92/nix-prefetch-git
nix-prefetch-git: fix json output.
This commit is contained in:
commit
f90d632fb4
|
@ -291,8 +291,8 @@ _clone_user_rev() {
|
||||||
pushd "$dir" >/dev/null
|
pushd "$dir" >/dev/null
|
||||||
fullRev=$( (git rev-parse "$rev" 2>/dev/null || git rev-parse "refs/heads/$branchName") | tail -n1)
|
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 --)
|
humanReadableRev=$(git describe "$fullRev" 2> /dev/null || git describe --tags "$fullRev" 2> /dev/null || echo -- none --)
|
||||||
commitDate=$(git show --no-patch --pretty=%ci "$fullRev")
|
commitDate=$(git show -1 --no-patch --pretty=%ci "$fullRev")
|
||||||
commitDateStrict8601=$(git show --no-patch --pretty=%cI "$fullRev")
|
commitDateStrict8601=$(git show -1 --no-patch --pretty=%cI "$fullRev")
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
# Allow doing additional processing before .git removal
|
# Allow doing additional processing before .git removal
|
||||||
|
@ -322,6 +322,18 @@ clone_user_rev() {
|
||||||
fi
|
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() {
|
print_results() {
|
||||||
hash="$1"
|
hash="$1"
|
||||||
|
@ -338,17 +350,15 @@ print_results() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test -n "$hash"; then
|
if test -n "$hash"; then
|
||||||
echo "{"
|
cat <<EOF
|
||||||
echo " \"url\": \"$url\","
|
{
|
||||||
echo " \"rev\": \"$fullRev\","
|
"url": "$(json_escape "$url")",
|
||||||
echo " \"date\": \"$commitDateStrict8601\","
|
"rev": "$(json_escape "$fullRev")",
|
||||||
echo -n " \"$hashType\": \"$hash\""
|
"date": "$(json_escape "$commitDateStrict8601")",
|
||||||
if test -n "$fetchSubmodules"; then
|
"$(json_escape "$hashType")": "$(json_escape "$hash")",
|
||||||
echo ","
|
"fetchSubmodules": $([[ -n "fetchSubmodules" ]] && echo true || echo false)
|
||||||
echo -n " \"fetchSubmodules\": true"
|
}
|
||||||
fi
|
EOF
|
||||||
echo ""
|
|
||||||
echo "}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue