How Subversion Externals can help you
Most of us have, when we go to design a new website, a way we configure the working environment. For example, I like to have a “setenv.inc” file to set up a database connection and create a smarty object, I like to have Smarty templating and the Pear/DB class in my /libs directory.
It’s kind of a pain to copy over the last website’s configuration, clean out the cruft I don’t need for the new one, and restructure it for a new website. So here’s what I did.
First, I copied over the last website’s configuration and cleaned out the cruft, at first without any other tools; just my stuff ( no database, no smarty, et cetera ). I created a subversion repository and imported this, then checked it out, giving myself a working directory.
svnadmin create /home/svn/repos/rgh_libs/
svn import . /home/svn/repos/rgh_libs/
cd ..
rm -rf blankdir
svn co /home/svn/repos/rgh_libs blankdir/
Then, because Smarty makes available a subversion repository (and look, it’s unstable for the trunk branch. Don’t panic if it breaks
), I went into the blank directory and set up an externals definition:
cd blankdir
svn propedit svn:externals . (note that it's applying to the blank dir, which I'm in; there's a period on the end of the line. )
(edit file to look like:)
libs/smarty http://smarty-php.googlecode.com/svn/trunk/
(save and exit )
svn up
That last svn up will bring in the smarty libraries to your libs/smarty directory. And look, it’s the entire package. We don’t need the entire branch, we just need the libs. Remove the libs/smarty dir, edit the svn properties, and reupdate
rm -rf libs/smarty
(edit file to look like)
libs/smarty http://smarty-php.googlecode.com/svn/trunk/libs/
svn propedit svn:externals .
(save an exit )
svn up
I also like using the blueprint CSS(link) (Cascading Style Sheets), the pear DB package, magpierss and simplepie. Unfortunately, those packages don’t currently have a subversion repo, so I have to download them and add them to the repository. On the plus side, they’re smaller than the smarty package.
I add them, and then commit my changes with a tag.
When I start a new website, I can do a “svn export /home/svn/repos/rgh_libs newsite/” and I’ll get the current version of smarty (and whatever other packages I saved ). But I didn’t have to update the smarty version and I didn’t have to store multiple copies of smarty in my repository.
