[OPEN-ILS-DEV] Whitespace Fixup Plan for m1

Dan Wells dbw2 at calvin.edu
Thu Jun 6 11:06:48 EDT 2013


Hello fellow devs,

I've been experimenting with different ideas for conquering the whitespace beast, and am trying to keep things as simple as possible.  After a few iterations, here is what I have for the main cleanup command (to be run from Open-ILS/src/perlmods/lib):

find . -name "*.pm" \
-exec sh -c 'sed "/<</s/\t/    /g" < {} \
| expand -t 4 > {}.fixed ; \
cp --no-preserve=mode,ownership {}.fixed {}; \
rm {}.fixed' \;

Here is the thinking behind each line:
1. Find all the Perl module files (I thought we might have some .pl files in there, but we do not).  This might miss a strangely named file or two, but in the interest of simplicity, I think that is fine.
2. Replace tabs used in heredoc starting statements with a constant 4 spaces (expand is too smart and preserves actual spacing, which in this case gives us a good chance of *not* matching the closing heredoc marker).  We don't care about the closing marker, since those always start at the beginning of the line, so expand works fine for those.
3. Use the 'expand' command to turn all tabs into the equivalent number of spaces with a tabstop of 4.  This does go beyond the initial goal of fixing initial tabs only, but in testing, expand seemed to do everything right, so we should take advantage of the opportunity.
4. cp the 'fixed' files over the originals.  We are using cp instead of mv here so that we can preserve the attributes of the *original* file (at least one file would otherwise lose its executable bits).  It seems like '--no-preserve=mode' is the default cp behavior when overwriting, but it doesn't hurt to be explicit.
5. Remove the now extra 'fixed' files.

This results in a pretty big change, somewhere around 30,000 lines.  This is about 27% of the total lines in the .pm files.  Nevertheless, I encountered no problems in brief testing.  More testing is *highly* encouraged.

As for dealing with this change for later merges, I've had good luck doing the following:

1. Rebase the to-be-merged branch to the origin/master (post whitespace fix) using the --ignore-whitespace option.  This is not compatible with --interactive, so do that separately, if needed.
2. Run the "fix" command set again.  This will find and clean up any whitespace issues being re-introduced in the new/updated lines from the merge.
3. Tack on a whitespace-only commit with whatever the "fix" fixes.

Again, more testing is welcome.

While it is simple to generate the changes yourself, I have pushed a branch here:

http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/dbwells/whitespace_fixup_m1

My intention is to push the whitespace commit after the cutoff tomorrow afternoon.  If you see or run into any issues, please speak up!  I would also be happy to get a sign-off or two, but please be aware that you are really signing off on the process, not the actual commit, as the "fix" will only be effective if it is re-run to catch any changes to master between now and then.

Thanks as always,
Dan



More information about the Open-ils-dev mailing list