-
Notifications
You must be signed in to change notification settings - Fork 279
Code Cleanup Procedure
This is a guide for fixing your branches after the large code cleanup patch that was merged into MPICH.
This is going to tell you to use the most dangerous command in all of Git: git filter-branch
. This command can wreck your Git metadata if you do it wrong, so I'd highly recommend that you make a copy of your local Git repository and work there, instead of your usual working directory.
You will also want to closely verify the results of this work to make sure they were successful.
You'll need to go through this process for each of your branches, so here's the short version of the commands. Details after this section.
git rebase -i 596c4f47efea
- Rebase onto
596c4f47efea
touch DELETE_ME && git add DELETE_ME && git commit -m 'DELETE ME'
git rebase -i 596c4f47efea
- Move your dummy commit to the beginning of your branch
git filter-branch -f --tree-filter "maint/code-cleanup.sh --all --recursive" -- 596c4f47efea..HEAD
git rebase -i mpich/master
- Remove the dummy commit from before
- Resolve conflicts
This procedure is going to happen in a two basic steps (with lots of smaller steps):
- Fix all of the whitespace in your existing branch
- Rebase your branch onto the latest
master
branch.
This entire procedure is a lot easier if you rebase your branch to the commit before the whitespace cleanup (596c4f47efea
). This is because there are a few commits just before that patch that help the code cleanup script generate good output. You will need to resolve any conflicts to get to this point on your own.
After you've rebased your branch onto the commit before the whitespace cleanup (596c4f47efea
), you are ready to cleanup your existing branch.
- Create a dummy commit to "absorb" the whitespace changes.
touch DELETE_ME && git add DELETE_ME && git commit -m 'DELETE ME'
This commit will "absorb" all of the whitespace changes and be removed at the end of the process. For now, we're going to stick it at the beginning of your branch.
- Move the dummy commit to the beginning of your branch.
git rebase -i 596c4f47efea
If you're not familiar with interactive rebasing, I'm not going to cover it all here. For now, what you need to know is that you need to move the last commit to be the first commit. So remove the last line in the list of patches you see in your editor and move it to the beginning of the list of patches. So you should now see something like this:
pick a1b2c3d4 DELETE ME
pick e5f6g7h8 Your next patch
...more patches here...
# Rebase 12345678..23456798 onto 596c4f47efea
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Save and close the file and let Git do it's work. Now if you look at the log (or git graph
if you have that alias set up), you should see DELETE ME
just before all of your patches, which are sitting on top of 596c4f47efea mpi: Add brackets to help indent script
.
- Run the command to clean up the whitespace
git filter-branch -f --tree-filter "maint/code-cleanup.sh --all --recursive" -- 596c4f47efea..HEAD
This is the big command that's going to take a while. Go get lunch/dinner/drinks/watch a movie. This will take about 3-4 minutes per commit in your branch. This will run the code cleanup script on every patch in your branch without resolving merge conflicts. This is important because otherwise every patch would conflict with the one before it. When you're done, your branch will be converted to have all of the formatting compliant with the code cleanup script. You will also have an old reference sitting around that git filter-branch
keeps as a backup called refs/original/refs/heads/<your_branch_here>
. Ignore that one for now (you can clean it up later) and let's focus on the new one. At this point, you can check your branch to make sure everything looks like you think it should.
Time to move to phase two...
Now that the whitespace is cleaned up in your branch, the number of conflicts your branch will have when rebased back onto master
will be much less. I say less and not none because you will still see two types of conflicts. 1) Normal conflicts for anything that has changed on master
since the initial code cleanup patch, and 2) Whitespace conflicts with manual fixes done in the code cleanup patch. The code cleanup patch was more than just running the code cleanup script. It also contained some manual whitespace fixes that the code cleanup script missed and would only need to be done once. If you conflict with these changes (mostly inside macros, but also some other places), you may still have to fix those manually. Unfortunately there isn't a shortcut for that, but the number of places that comes up is much lower.
- Interactive rebase onto master and drop the dummy patch
git rebase -i mpich/master
For this command, I assume that your local name for https://github.com/pmodels/mpich.git
is mpich
. If that's not what you call it, change mpich
to your name (for me, it's actually argonne
). When you do this, you'll want to drop the dummy patch we created earlier. To do that, just delete that line from the editor that pops up when you run the command so your editor should only show patches that were originally in your branch.
- Resolve conflicts
It's possible that you'll run into conflicts during this rebase. Fix them as they come up. If you don't know how to fix rebase conflicts, use git status
for hints and ask a friend/the Internet.
- Celebrate
At this point, your branch should look correct. Your branch should not contain a bunch of formatting fixes, but should look pretty much like they did before. Make sure all of that is true before pushing your branch to any remote and overwriting previous work.