You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by "Jan Ciesko (GMAIL)" <ja...@gmail.com> on 2011/08/03 15:14:49 UTC

svnlook changed - howto see all deleted files in pre-/post-commit hooks

Dear SVN-experts,

I'd like to ask if there is a way to see which particular files have 
been deleted when a directory deletion has been commited.

Example:

I add to a repository BAR/Apps the folder Jacobi. With "svnlook changed 
"$REPOS"" in the post-commit hook I get the output:
A   BAR/Apps/Jacobi/
A   BAR/Apps/Jacobi/LICENSE
A   BAR/Apps/Jacobi/Makefile
A   BAR/Apps/Jacobi/Readme
A   BAR/Apps/Jacobi/bin/
A   BAR/Apps/Jacobi/src/
A   BAR/Apps/Jacobi/src/jacobi.c

On deleting the folder Jacobi from the repository and running $SVNLOOK 
changed "$REPOS" --transaction "$TXN" I'm getting only.
D   BAR/Apps/Jacobi/

Since I'm parsing a Readme file to update a TRAC front-end, I would very 
much need to see the individual files that were deleted in the Jacobi 
folder, including the Readme. Is there a way of getting this information?

Thanks a lot,
Jan.

Re: svnlook changed - howto see all deleted files in pre-/post-commit hooks

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Aug 12, 2011, at 11:01, Jan Ciesko (GMAIL) wrote:

> What I was wondering though: if I commit a delete and run any svn command on the REV-1 version in the post-commit hook, is it guaranteed that in the meantime no other commits were run, thus making REV-1 invalid?
> Or in other words: pre-commit, commit and post-commit are atomic?

Well let's think about each of those.

The commit will not be finalized until after the pre-commit hook has run successfully. So the directory should continue to exist in the head of the repository for the duration of the pre-commit hook. It might be possible (though unlikely) that another developer will happen to delete the directory while the hook is running. To minimize the possibility of that messing up the script, the first thing the script should do is get the HEAD revision of the repository into a variable, and use that variable for the duration of the script:


#!/bin/bash
REPOS=$1
TXN=$2
SVNLOOK=/usr/bin/svnlook
SED=/usr/bin/sed
HEAD_REV=$($SVNLOOK youngest $REPOS)
PATHS_IN_REPOS=$($SVNLOOK changed $REPOS -t $TXN | $SED -n -E 's/^D...(.*)$/\1/p')
for PATH_IN_REPOS in $PATHS_IN_REPOS; do
	TREE=$($SVNLOOK tree $REPOS $PATH_IN_REPOS -r $HEAD_REV)
	... (do something with $TREE)
done



The commit itself is atomic. That's one of the fundamental properties of Subversion and is well documented so we don't need to go into it further here.

http://svnbook.red-bean.com/en/1.5/svn.basic.in-action.html

"An svn commit operation publishes changes to any number of files and directories as a single atomic transaction."



That leaves the post-commit. By this time the commit is finalized in the repository. So you can look at that new revision all you want and it's not going to change. Yes other commits might happen subsequently but your post-commit hook is called with the number of the newly-added revision, so just subtract one from that to find the last revision in which the directory still existed.

#!/bin/bash
REPOS=$1
REV=$2
SVNLOOK=/usr/bin/svnlook
SED=/usr/bin/sed
PREV_REV=$(($REV-1))
PATHS_IN_REPOS=$($SVNLOOK changed $REPOS -r $REV | $SED -n -E 's/^D...(.*)$/\1/p')
for PATH_IN_REPOS in $PATHS_IN_REPOS; do
	TREE=$($SVNLOOK tree $REPOS $PATH_IN_REPOS -r $PREV_REV)
	... (do something with $TREE)
done



These examples do not properly handle paths that contain spaces. Also, PATHS_IN_REPOS could contain files and/or directories; if you want only directories, you'll have to skip the files somehow.





Re: svnlook changed - howto see all deleted files in pre-/post-commit hooks

Posted by "Jan Ciesko (GMAIL)" <ja...@gmail.com>.
Thanks Ryan and David for the info, that solved my problem.
(I inspect the tree in a post-commit in the previous revision where the 
deleted files were still present.)

What I was wondering though: if I commit a delete and run any svn 
command on the REV-1 version in the post-commit hook, is it guaranteed 
that in the meantime no other commits were run, thus making REV-1 invalid?
Or in other words: pre-commit, commit and post-commit are atomic?

Thanks,
Jan




On 8/4/11 9:24 AM, Ryan Schmidt wrote:
> On Aug 3, 2011, at 08:14, Jan Ciesko (GMAIL) wrote:
>
>> I'd like to ask if there is a way to see which particular files have been deleted when a directory deletion has been commited.
>>
>> Example:
>>
>> I add to a repository BAR/Apps the folder Jacobi. With "svnlook changed "$REPOS"" in the post-commit hook I get the output:
>> A   BAR/Apps/Jacobi/
>> A   BAR/Apps/Jacobi/LICENSE
>> A   BAR/Apps/Jacobi/Makefile
>> A   BAR/Apps/Jacobi/Readme
>> A   BAR/Apps/Jacobi/bin/
>> A   BAR/Apps/Jacobi/src/
>> A   BAR/Apps/Jacobi/src/jacobi.c
>>
>> On deleting the folder Jacobi from the repository and running $SVNLOOK changed "$REPOS" --transaction "$TXN" I'm getting only.
>> D   BAR/Apps/Jacobi/
>>
>> Since I'm parsing a Readme file to update a TRAC front-end, I would very much need to see the individual files that were deleted in the Jacobi folder, including the Readme. Is there a way of getting this information?
> There's a slight confusion in your email, in that in a post-commit hook, you would not have a transaction ($TXN); you would have a revision ($REV). In a pre-commit hook you would have a transaction.
>
> When a commit comes in, Subversion creates a transaction, calls the pre-commit hook with that transaction to see if the commit is allowed to proceed; if it is, Subversion promotes the transaction to a revision, then calls the post-commit hook with that revision.
>
> One way to see what's in a directory would be to use "svnlook tree $REPOS $PATH_IN_REPOS". If you're calling this from a pre-commit hook, then the directory currently still exists in the repository and you can call it just like that, which will look at the HEAD of the repository. If we're in a post-commit hook, the directory has already been deleted from the HEAD, so you would need to look at the preceding revision ($REV - 1).
>
>

Re: svnlook changed - howto see all deleted files in pre-/post-commit hooks

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Aug 3, 2011, at 08:14, Jan Ciesko (GMAIL) wrote:

> I'd like to ask if there is a way to see which particular files have been deleted when a directory deletion has been commited.
> 
> Example:
> 
> I add to a repository BAR/Apps the folder Jacobi. With "svnlook changed "$REPOS"" in the post-commit hook I get the output:
> A   BAR/Apps/Jacobi/
> A   BAR/Apps/Jacobi/LICENSE
> A   BAR/Apps/Jacobi/Makefile
> A   BAR/Apps/Jacobi/Readme
> A   BAR/Apps/Jacobi/bin/
> A   BAR/Apps/Jacobi/src/
> A   BAR/Apps/Jacobi/src/jacobi.c
> 
> On deleting the folder Jacobi from the repository and running $SVNLOOK changed "$REPOS" --transaction "$TXN" I'm getting only.
> D   BAR/Apps/Jacobi/
> 
> Since I'm parsing a Readme file to update a TRAC front-end, I would very much need to see the individual files that were deleted in the Jacobi folder, including the Readme. Is there a way of getting this information?

There's a slight confusion in your email, in that in a post-commit hook, you would not have a transaction ($TXN); you would have a revision ($REV). In a pre-commit hook you would have a transaction.

When a commit comes in, Subversion creates a transaction, calls the pre-commit hook with that transaction to see if the commit is allowed to proceed; if it is, Subversion promotes the transaction to a revision, then calls the post-commit hook with that revision.

One way to see what's in a directory would be to use "svnlook tree $REPOS $PATH_IN_REPOS". If you're calling this from a pre-commit hook, then the directory currently still exists in the repository and you can call it just like that, which will look at the HEAD of the repository. If we're in a post-commit hook, the directory has already been deleted from the HEAD, so you would need to look at the preceding revision ($REV - 1).