Archive for the ‘PHP and web development’ Category

Generating empty/padding revisions in an SVN dump

Monday, September 12th, 2011

I’ve previously had an SVN repository filled with a mixture of projects that I’m now splitting out into separate repositories, so am in the process of creating various scripts based on “svnadmin dump”/”svnadmin load” to process repositories.
Along the way, I had a need to dump only selected revisions from a repository, using a command such as:

svnadmin dump -r 1234:HEAD /path/to/repo > repo.dump

However, when this is loaded back into a new repository (“svnadmin load mynewrepo < repo.dump”), the revisions are renumbered starting at 1, so that what was revision 1234 becomes revision 1. This is undesirable, as I have existing bugs and changelogs referring to SVN revision numbers, so I created a small script (svn-generate-empty-revisions) to create a number of empty revisions.

In use, it’s most useful to splice its output into the start of an SVN dump, for example:

svnadmin dump -r 1234:HEAD /path/to/repo > repo.dump
# Extract the first few lines of the dump, which contain metadata
head -n 4 repo.dump > repo-padded.dump
# Splice in some empty "padding" revisions to preserve revision numbering
# Note that the first revision is 1234, so we want 1233 empty revisions at start
./svn-generate-empty-revisions.sh 1233 >> repo-padded.dump
# Add the rest of the original repository dump to the file
tail -n +4 repo.dump >> repo-padded.dump

Error and exception handling in PHP

Wednesday, June 23rd, 2010

For as long as I’ve been developing PHP, I’ve always cared about code quality and wanted robust error handling, to fix root cause issues. Back in 2001, I wrote a class for PHPOF called XError, which did a pretty decent job of handling errors gracefully and reporting (via e-mail or rate-limited log) a backtrace with (usually) enough information to fix the problem.

With the advent of PHP 5 and proper exceptions (at last!), I cleaned up and substantially re-wrote that class to form a new one, which has actually been on my PEAR channel for several years and is in use across many live systems at work, but which I’ve never written up. It’s called Exception_DefaultHandler and is, well, a great class to throw in any project to use as a default error/exception handler. It’s lightweight, should work anywhere really, and is a major help with root cause analysis. It’s often still helpful to use higher level exception handling in your application, but even then you might want to pass the exception down to Exception_DefaultHandler::handleExceptionManual() to take advantage of its convenient reporting functions.