Using SVN post-commit hook to update only files that have been committed

TheKeys picture TheKeys · Jan 15, 2009 · Viewed 29.4k times · Source

I am using an SVN repository for my web development work. I have a development site set up which holds a checkout of the repository.

I have set up an SVN post-commit hook so that whenever a commit is made to the repository the development site is updated:

cd /home/www/dev_ssl
/usr/bin/svn up

This works fine but due to the size of the repository the updates take a long time (approx. 3 minutes) which is rather frustrating when making regular commits. What I'd like is to change the post-commit hook to only update those files/directories that have been committed but I don't know how to go about doing this. Updating the "lowest common directory" would probably be the best solution, e.g.

If committing the follow files:

  • /branches/feature_x/images/logo.jpg
  • /branches/feature_x/css/screen.css

It would update the directory: /branches/feature_x/

Can anyone help me create a solution that achieves this?

Update:

  • The repository and development site are located on the same server so network issues shouldn't be involved.
  • CPU usage is very low, and I/O should be ok (it's running on hi-spec dedicated server)
  • The development site is approx. 7.5GB in size and contains approx. 600,000 items, this is mainly due to having multiple branches/tags

Answer

Jonathan Lonowski picture Jonathan Lonowski · Jan 15, 2009

You might use svnlook dirs-changed and svn up -N to update only the contents of each folder changed:

cd /home/www/dev_ssl
svnlook dirs-changed [REPOS] -r [REV] | xargs /usr/bin/svn up -N

Or, if per-file might be better for you (using sed to strip action characters):

svnlook changed [REPOS] -r [REV] | sed "s/^....//" | xargs /usr/bin/svn up