tiding subversion Perl repo with PerlTidy?
I would like to clean up an existing subversion repository containing badly formatted Perl code. Since I am not sure if some comparisons with fairly开发者_Go百科 old code will be necessary, ideally I would like to have the same formatting for all revisions.
On the other hand creating a new repo by checking out all old revisions, reformatting with perltidy and checking in will have to keep the original log messages.
Are there any tools/recipes to do it?
For the future, I'd recommend an svn pre-commit hook to a script running Test::PerlTidy to force everyone to keep their code tidy.
Rather than trying to change all previous commits, you might consider a custom svn diff
command for when you want to make comparisons to old versions. Something like:
#!/bin/bash
# tidydiff.sh for tidying code before diffing
perltidy "$1" > "/tmp/$1"
perltidy "$2" > "/tmp/$2"
diff "$1" "$2"
rm "/tmp/$1" "/tmp/$2"
and then using svn diff --diff-cmd=tidydiff.sh
when you want to look at old versions.
What exactly do you want to do? Clean up all the old revisions?
Don't do it. You'll destroy your history, and even though you should be generating the same Perl script (just now tidied up), you could end up funking up some previously released revision. Besides it isn't worth the effort.
I would recommend that you checkout your current revisions, run Perl Tidy, and then check in your changes. You won't change your old code, but it will give you clean stuff to work with from now on.
Of course, if your Perl code is so poorly formatted that you want to run the whole thing with Perl tidy, you have more issues. What prevents someone from making a mess of the code again?
I would also recommend you look at Jenkins as part of a continuous build process. You don't compile Perl code, but you could use Jenkins to run tests to make sure any new Perl scripts and any modifications to your Perl scripts have been tidied up. If a Perl script has bad formatting, you'll Fail the build and email yourself and the developer.
Developers will quickly learn to use Perl Tidy before checking in new Perl code of face the public embarrassment of having a failed build.
By the way, does the rest of your development team support your effort? If not, the first thing you have to do is convince them that good Perl formatting can help reduce bugs, and give them tools that will help automate their formatting efforts.
精彩评论