Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 988
TheKeys Avatar asked Jan 15 '09 12:01

TheKeys


2 Answers

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
like image 193
Jonathan Lonowski Avatar answered Oct 19 '22 03:10

Jonathan Lonowski


#!/bin/bash

REPOS="$1"
REV="$2"

# A - Item added to repository
# D - Item deleted from repository
# U - File contents changed
# _U - Properties of item changed; note the leading underscore
# UU - File contents and properties changed

# Files and directories can be distinguished, as directory paths are displayed with a trailing "/" character.

LOOK=/usr/local/svn/bin/svnlook
SVN=/usr/local/svn/bin/svn
DEV=/var/www/test

cd /var/tmp/svn
  for changes in `$LOOK changed $REPOS | awk '{print $1 "=" $2;}'`;
  do
        len=${#changes}
        idx=`expr index "$changes" =`;
        directory=${changes:$idx};
        action=${changes:0:$idx-1};
        if [ ${changes:len-1} = '/' ]
        then
            case "$action" in
                "A" ) \
                    mkdir --mode=775 -p $DEV/$directory;
                    chown nobody:nobody $DEV/$directory;
                    chmod 775 $DEV/$directory;
                    ;;
                "D" ) \
                    rmdir $DEV/$directory;
                    ;;
            esac
        else
            case "$action" in
                "A"|"U"|"UU" ) \
                    $SVN export --force --non-interactive -r HEAD -q file://$REPOS/$directory;
                    BASE=`basename $directory`;
                    DIR=`dirname $directory`;
                    chown nobody:nobody $BASE;
                    chmod 775 $BASE;
                    mkdir --mode=775 -p $DEV/$DIR;
                    cp -f --preserve=ownership $BASE $DEV/$DIR;
                    unlink $BASE;
                    ;;
                "D" ) \
                    rm -f $DEV/$directory;
                    ;;
            esac
        fi
  done

exit 0
like image 38
IVO GELOV Avatar answered Oct 19 '22 04:10

IVO GELOV