-fi
-
-## Determine command and toolchain.
-COMMAND="$1"
-[ $# -gt 0 ] && shift
-# Doing this *after* auto-toolchain logic above, since that might change the toolchain.
-TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
-
-## Handle some commands early, since they should *not* alter the environment.
-case "$COMMAND" in
+ echo "$FETCH_COMMIT" > rust-version # do this *before* merging as merging will fail in case of conflicts
+ git merge FETCH_HEAD --no-ff -m "Merge from rustc"
+ git commit rust-version --amend -m "Merge from rustc"
+ exit 0
+ ;;
+rustc-push)
+ USER="$1"
+ BRANCH="$2"
+ if [ -z "$USER" ] || [ -z "$BRANCH" ]; then
+ echo "Usage: $0 rustc-push <github user> <branch>"
+ exit 1
+ fi
+ if [ -n "$RUSTC_GIT" ]; then
+ # Use an existing fork for the branch updates.
+ cd "$RUSTC_GIT"
+ else
+ # Do this in the local Miri repo.
+ echo "This will pull a copy of the rust-lang/rust history into this Miri checkout, growing it by about 1GB."
+ read -r -p "To avoid that, abort now and set the RUSTC_GIT environment variable to an existing rustc checkout. Proceed? [y/N] "
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ exit 1
+ fi
+ cd "$MIRIDIR"
+ fi
+ # Prepare the branch. Pushing works much better if we use as base exactly
+ # the commit that we pulled from last time, so we use the `rust-version`
+ # file as a good approximation of that.
+ BASE=$(cat "$MIRIDIR/rust-version")
+ echo "Preparing $USER/rust (base: $BASE)..."
+ if git fetch "https://github.com/$USER/rust" "$BRANCH" &>/dev/null; then
+ echo "The branch '$BRANCH' seems to already exist in 'https://github.com/$USER/rust'. Please delete it and try again."
+ exit 1
+ fi
+ git fetch https://github.com/rust-lang/rust $BASE
+ git push https://github.com/$USER/rust $BASE:refs/heads/$BRANCH -f
+ # Do the actual push.
+ cd "$MIRIDIR"
+ echo "Pushing Miri changes..."
+ git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH
+ exit 0
+ ;;