Skip to content

Instantly share code, notes, and snippets.

@divergentdave
Last active December 4, 2020 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divergentdave/bbf2d9f347e70499e3a5c58bf4a4ab17 to your computer and use it in GitHub Desktop.
Save divergentdave/bbf2d9f347e70499e3a5c58bf4a4ab17 to your computer and use it in GitHub Desktop.
Diff between two crate versions
#!/usr/bin/env bash
set -e
CRATES_IO_REGISTRY="$HOME/.cargo/registry/src/github.com-1ecc6299db9ec823"
display_usage() {
echo "Usage: crate-diff.sh CRATE_NAME OLD_VERSION NEW_VERSION"
}
if [ $# -ne 3 ]
then
display_usage
exit 1
fi
if [[ ( $# == "--help" ) || ( $# == "-h" ) ]]
then
display_usage
exit 0
fi
TMPDIR="$(mktemp -d)"
if [[ ! "$TMPDIR" || ! -d "$TMPDIR" ]]
then
echo "Couldn't create temporary directory"
exit 1
fi
function cleanup {
rm -rf "$TMPDIR"
}
trap cleanup EXIT
download_crate_version(){
cd "$TMPDIR"
mkdir -p src
touch src/lib.rs
cat <<EOF >Cargo.toml
[package]
name = "cargo-fetch-stub"
version = "0.0.1"
[dependencies]
EOF
echo "$1 = \"$2\"" >>Cargo.toml
cargo fetch
cd - >/dev/null
}
download_if_needed(){
if [[ ! -d "$CRATES_IO_REGISTRY/$1-$2/" ]]
then
download_crate_version "$1" "$2"
fi
}
download_if_needed "$1" "$2"
download_if_needed "$1" "$3"
diff -r -u --color=auto "$CRATES_IO_REGISTRY/$1-$2/" "$CRATES_IO_REGISTRY/$1-$3/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment