Question

I'm writing a post-commit hook, in which I use svn diff -summarize to get a summary of what was changed. When files/folders are added or modified, I can simply get their file type in a working copy that is kept updated at all times automatically. But when a file or folder is deleted, I have no way of finding out whether an item in the svn diff -summarize was a file or a folder.

One workaround I've thought for this is to keep another working copy, updated automatically, but always kept one revision behind the other working copy. That way, if a file/folder was deleted, I could get it in the older working copy. However, I think that this is an extraordinarily inefficient way of doing this, forcing me to keep two different working copies at the same time, and I was wondering whether there is anything in SVN that'd help with this task.

Was it helpful?

Solution

When writing svn hooks of any type, if you need information about the repository or about a transaction, you want to use the svnlook program from a shell script, or use the svn API in the language of your choice. Using svnlook is faster, as it bypasses all the svn RA (remote access) code, including the layer of authorization checks - because the scripts are being run in the context of the server, this isn't a problem. Additionally, you don't have the additional overhead of updating a working copy that you aren't using for, well, anything other than file type information.

svnlook contains numerous options for investigating both revisions (for post-* hooks) and transactions (for pre-* transactions). Of particular interest here is the changed option.

changed: usage: svnlook changed REPOS_PATH Print the paths that were changed. Valid options: -r [--revision] ARG : specify revision number ARG -t [--transaction] ARG : specify transaction name ARG --copy-info : show details for copies

The changes that made up the revision or transaction are displayed, like so:

A   trunk/src/new-dir/
A   trunk/src/new-dir/newheader.h
A   trunk/src/new-dir/newsrc.c
U   trunk/src/existingsrc.c

Output from svnlook, when referencing a directory, always ends in /. This is an easy discriminator for detection of file or directory.

However, things do get a little murkier when dealing with deletes. If a directory is deleted, everything under the directory is also removed and this information isn't displayed in changed. See here:

D   trunk/src/new-dir/
U   trunk/src/existingsrc.c

Based on the description of what you are looking at, I'm going to guess that you are looking for some form of post-commit reporting. If so, you may want to check out the subversion mailer post-* hook. Even if you don't want to email results, the code demonstrates how to walk through a transaction or revision for changes using the svn API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top