Skip to content

Commit 673f9f2

Browse files
Update formatting script per consultation with Santiago
1 parent 9f47c3b commit 673f9f2

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

posts/inside-rust/2019-12-23-formatting-the-compiler.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,39 @@ speed of formatting the entire codebase.
3939
If you have an ongoing branch, you're likely to have merge conflicts. The following should help you
4040
resolve them:
4141

42+
```bash
43+
#!/bin/bash
44+
45+
set -xeo pipefail
46+
47+
if [ "$1" = "from-rebase" ] ; then
48+
git rev-parse HEAD > /tmp/commit
49+
git rev-parse HEAD >> /tmp/old.shas
50+
./x.py fmt
51+
git commit -a --amend --no-edit
52+
git rev-parse HEAD >> /tmp/new.shas
53+
git reset --hard $(cat /tmp/commit)
54+
else
55+
rm -f /tmp/old.shas /tmp/commit /tmp/new.shas
56+
git rebase 8eb7c58dbb7 --exec '../format.sh from-rebase'
57+
branch=$(git rev-parse --abbrev-ref HEAD) # get branch name
58+
git reset --hard 8eb7c58dbb7
59+
for sha in $(cat /tmp/new.shas); do
60+
git cherry-pick $sha -Xtheirs
61+
done
62+
git branch -f $branch HEAD
63+
# put yourself atop the format the world PR
64+
git rebase -Xtheirs a916ac22b9f7f1f0f7aba0a41a789b3ecd765018
65+
fi
4266
```
43-
# This should be the name of the remote for rust-lang/rust
44-
git fetch upstream
45-
# This rebases up to the bors merge right before formatting landed;
46-
# it needs to be done manually.
47-
git rebase -i 9b98af84c4aa66392236fff59c86da2130d46d46
48-
# This rebases onto the formatting PR (given the previous command, only that).
49-
# We tell git to resolve all conflicts in favor of your code (`-Xtheirs`),
50-
# and the `--exec` command specifies that after each commit lands, it will be formatted.
51-
# This command will fail if your PR has intermediary commits with syntax conflicts.
52-
git rebase -i a916ac22b9f7f1f0f7aba0a41a789b3ecd765018 \
53-
--exec './x.py fmt && git add -u && git commit --amend' \
54-
# This exec is optional, and won't work if your intermediate commits don't build,
55-
# but it helps make sure that the formatting resolution didn't introduce any errors.
56-
# It's recommended to run it afterwards before pushing at least.
57-
--exec './x.py check' \
58-
-Xtheirs
59-
```
67+
68+
This script should be saved to `format.sh` in the parent directory of your Rust
69+
checkout, and then run `git fetch upstream && ../format.sh`. `upstream` should
70+
be the name of the rust-lang/rust remote.
71+
72+
Once the script runs, you will be based on the `a916ac22b9f7f` commit. You
73+
likely want to then run `git rebase -i upstream/master` or so to finish, but the
74+
script above gets you past the formatting PR at least.
6075

6176
This should mostly resolve conflicts correctly, but occasionally if you've edited something in
6277
imports (a common case I've encountered) or otherwise this will not resolve quite right. Usually

0 commit comments

Comments
 (0)