Update web directory after a SVN commit: the final solution
Posted by shadow_of__soul | Posted in Uncategorized | Posted on 23-08-2010
0
Hi,
i wrote about this in the past (you can see some post at the end) but i’m writing again as i found the perfect solution to make a SVN update after a commit to a web directory.
the difference between the old and this new one, is that the old make a svn update in all the working copy, something like that is not a problem if you have some files, but when you have like 100K files, it takes too much time and resources. so the idea was to get a list of changed directories after each commit and run a svn update on each directory.
for this i used some bash scripting and a C program (the C program is needed when the files do not belong to the user who execute the post-commit script).
in the post-commit script put something like this:
svnlook dirs-changed /path/to/your/repository > /tmp/dirschanged
while read line
do
/path/to/C/Binary/updateFolder $line
done < “/tmp/dirschanged”
and save it. remember that after the svnlook (that is what return the list of directories that has been modified) and before the while, you can use sed to change any path of your repository and convert it into a valid full path in your web directory.
then, create a .c file and paste this code to make the binary:
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{int i;
for (i = 1; i < argc; i++) /* Skip argv[0] (program name). */
{printf(“making update to %s \n”,argv[i]);
execl(“/usr/bin/svn”, “svn”, “update”,argv[i],
(const char *) NULL);
}
exit(0);}
compile and set a chmod +s, and is done
. the binary will accept any amount of arguments as paths to run the svn update, anyway i’ll recomend to make 1 at time, so you have more control of it.
i know that this code could be improved, maybe using less bash scripting and more C coding, but i’m not good as before in C, so for me was more easy to make the loop and event the replacements with sed in the bash scripts.
i hope this help you in some way



