Just a heads-up that tomorrow evening (CET) I plan...
# development
g
Just a heads-up that tomorrow evening (CET) I plan to do the big PRs for reformatting the codebase, which should hopefully get merged quite quickly to avoid issues. There'll be two commits in a single PR that have to be merged without squashing for the helper script (🧵) to work. The script I'll put in a gist, as anyone that needs it won't be on a commit that has it. We can then refer users to it in PRs if need be. I'll do similar PRs for all old versions that have seen commits this year, should be minimal extra work. However, I will not make the script work for those branches, as PRs that get merged into main and then backported will already have the correct formatting applied. I'll also have a short blurb (🧵) to let users know how to proceed. Any thoughts/questions/concerns?
Hello and thanks for the pull request!
We have recently (#PR_NO) removed our custom formatting for Rust to follow the rest of the community. Unfortunately your PR got caught in-between, and needs some extra work to be mergeable. We have a helper script (ADD LINK) you can copy to the repository root which will hopefully make it a bit easier and safer (
reformat-helper.sh sync
to get started). You can of course also use your preferred method of rebase/merge get updated.
Feel free to ping ping @tgolsson/Tom Solberg on Slack for assistance.
❤️ 2
Copy code
# CONSTANTS, known once PR is merged
WITH_NEW_SETTINGS_COMMIT=364d675f20a558f7ba4670addc4adc09d3190c66
WITH_NEW_FORMAT_COMMIT=d9bdd80810b0384de455b955d3fa530d936d9f93


if [ "$#" -ne 1 ]; then
    echo "Error: Expected a single command, 'sync' or 'reformat'"
	exit 1
fi

if [ "$1" != "sync" ] && [ "$1" != "reformat" ]; then
	echo "Error: Expected 'sync' or 'reformat', found '$1'"
	exit 1
fi

if [ "$1" = "sync" ]; then
    echo "This script will update the current branch to the last commit before the Pants codebase was reformatted. This script uses \`git rebase\`, which can be hard to debug and recover from if things go wrong."
	while true; do
		read -p "Do you wish to proceed?" yn
		case $yn in
			[Yy]* ) make install; break;;
			[Nn]* ) exit;;
			* ) echo "Please answer yes or no.";;
		esac
	done

	branch_name=$(git branch --show-current)
	git branch "$branch_name-backup" "$branch_name"

	git fetch <https://github.com/pantsbuild/pants> main
	BASE_SHA=$(git merge-base HEAD $WITH_NEW_SETTINGS_COMMIT)

	git rebase --onto "$WITH_NEW_SETTINGS_COMMIT" "$BASE_SHA"
	echo "Rebased '$branch_name' on last pre-format main '$WITH_NEW_SETTINGS_COMMIT'."
	echo "The old state is backed up as '$branch_name-backup'."
	echo "If your \`git status\` is OK, you can proceed directly with \`$0 reformat\`."
	echo "Otherwise, finish the rebase and commit as usual, before continuing with the \`reformat\` step."

	exit 0
fi

if [ "$1" = "reformat" ]; then
    echo "This script will update the current branch to the commit after the Pants codebase was reformatted. This step similarly uses \`git rebase\`, with the same caveats. Note that this step is likely to break if you have not first run \`$0 sync\`."
	while true; do
		read -p "Do you wish to proceed?" yn
		case $yn in
			[Yy]* ) break;;
			[Nn]* ) exit;;
			* ) echo "Please answer yes or no.";;
		esac
	done

	# Since Pants doesn't use a workspace; this is a hacky way to hopefully catch most code.
	git rebase \
		--strategy-option theirs \
		--empty=drop \
		--exec 'cargo fmt --all --manifest-path src/rust/engine/Cargo.toml || echo "failed formatting but continuing"; cargo fmt --all --manifest-path src/rust/engine/client/Cargo.toml || echo "failed formatting but continuing" ; cargo fmt --all --manifest-path src/rust/engine/fs/brfs/Cargo.toml || echo "failed formatting but continuing" ; cargo fmt --all --manifest-path src/rust/engine/fs/fs_util/Cargo.toml || echo "failed formatting but continuing" ; cargo fmt --all --manifest-path src/rust/engine/process_executor/Cargo.toml || echo "failed formatting but continuing" ; cargo fmt --all --manifest-path src/rust/engine/testutil/local_cas/Cargo.toml || echo "failed formatting but continuing" ; cargo fmt --all --manifest-path src/rust/engine/testutil/local_execution_server/Cargo.toml || echo "failed formatting but continuing" ; git add src/rust && git commit --amend --no-verify --no-edit' \
		--onto $WITH_NEW_FORMAT_COMMIT $WITH_NEW_SETTINGS_COMMIT;

	echo "Reformatting done. Please push your branch with \`--force-with-lease\` and re-request reviews."

	exit 0
fi
h
Yay standardized formatting!
b
Typo at the end of your script: "ping" is duplicated
Otherwise, godspeed and thank you
❤️ 1
Don't forget to add to .git-blame-ignore-revs 😁
g
Thanks! Yeah. Will do the
.git-blame-ignore-revs
as a follow-up, so the PR doesn't depend on the sha of one of its own commits.
1