You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de> on 2012/02/22 16:23:07 UTC

commit hooks - is there a hook which is called after commit even if its not successful

Hi,

the http://svnbook.red-bean.com/en/1.6/svn.ref.reposhooks.html book
tells about the various post-* hooks.
But those one are called on "successfull" operations.
Whats the way to implement a hook, which is called after commit - it
does not matter if successful or failed - the hook must be able to
figure out if all went fine or something went wrong.

Can this be done or is this not possible at the moment?

regards

Torsten

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Philip Martin <ph...@wandisco.com>.
Mark Phippard <ma...@gmail.com> writes:

> On Wed, Feb 22, 2012 at 2:49 PM, Torsten Krah
> <tk...@fachschaft.imn.htwk-leipzig.de> wrote:
>
>> If commit can not fail - for which ever reason - why the doc does state that
>> the hook does only run if the commit is actual successful?
>> So it is possible to fail or not?
>
> Commits can fail.  A common reason would be that a file included in
> the commit was not at the HEAD revision in your working copy.  I
> believe these sort of checks do not happen until after the pre-commit
> hook is called.

Out-of-date checks happen twice.  They happen first at an early stage
during the commit as this allows us to reject the commit before the user
has spent a lot of time uploading content.  However these early
out-of-date checks could themselves be out-of-date by the time we come
to finalise the commit (another commit could have completed).  So the
out-of-date checks get repeated once Subversion has taken the commit
lock, and this second check is after the pre-commit hook has run.

-- 
Philip

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Mark Phippard <ma...@gmail.com>.
On Wed, Feb 22, 2012 at 2:49 PM, Torsten Krah
<tk...@fachschaft.imn.htwk-leipzig.de> wrote:

> If commit can not fail - for which ever reason - why the doc does state that
> the hook does only run if the commit is actual successful?
> So it is possible to fail or not?

Commits can fail.  A common reason would be that a file included in
the commit was not at the HEAD revision in your working copy.  I
believe these sort of checks do not happen until after the pre-commit
hook is called.

> I need to be sure that prepared external resources from pre-commit are
> cleaned up - even in case it did fail. If it would be run only on success,
> which does imply that it might fail, i am unable to clean up my work done in
> pre-commit.
>
> any other ideas how to do?

There is no hook called if the commit fails.  If you want to clean
something up that you created during your pre-commit hook then write a
background job that checks for stale information and cleans them up.
Without a lot more details about what you are doing in your pre-commit
hook I do not think there are any other suggestions that can be made.

-- 
Thanks

Mark Phippard
http://markphip.blogspot.com/

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Andreas Krey <a....@gmx.de>.
On Thu, 23 Feb 2012 11:50:29 +0000, Torsten Krah wrote:
...
> In theory yes it would work to do the same thing again in post-commit -
> but pre-commit already did all the work before. Would be nice if there
> would be no need to parse and analyze things twice, may take time and
> resources depending on the commit size.

Put the pre-commit hook work aside (which you need to do anyway),
and when no post-commit hook has picked it up for, say, 15 minutes,
discard it. If the server should really be that slow, then you
will have to recreate the stuff, but only then. You can do the
expiry check in the post-commit trigger; you may also look
at the (monotonical) revision number.

I don't expect there to be a guarantee that there is only ever
one set of hooks (pre-hook/commit/post-hook) running, so you need
to deal with multiple work sets anyway.

Andreas

-- 
"Totally trivial. Famous last words."
From: Linus Torvalds <torvalds@*.org>
Date: Fri, 22 Jan 2010 07:29:21 -0800

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Trent Nelson <tr...@snakebite.org>.

On 2/23/12 10:50 AM, "Torsten Krah" <tk...@fachschaft.imn.htwk-leipzig.de>
wrote:
>
>In theory yes it would work to do the same thing again in post-commit -
>but pre-commit already did all the work before. Would be nice if there
>would be no need to parse and analyze things twice, may take time and
>resources depending on the commit size.

This was added in r1240856:
http://svn.apache.org/viewvc?view=revision&revision=1240856

Post commit hooks will now be invoked with the pre-commit's txn name.  Do
your preparation during pre-commit, persist it in some way, keyed by the
txn name, then apply it during post-commit.

(This doesn't take care of periodically cleaning failed preparation
attempts, and nor should it.)

Regards,

	Trent.


Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>.
Am Donnerstag, den 23.02.2012, 11:16 +0100 schrieb Stephen Butler:
> Why not do 1 & 3 in a post-commit hook?

In pre-commit things are already needed to be parsed to check if the
commit itself is allowed.
When doing those checks things can be prepared too for the external
system - 2 in 1 ;-).
So the parsing work have to be done at pre-commit and preparing can be
done in this process too.

In theory yes it would work to do the same thing again in post-commit -
but pre-commit already did all the work before. Would be nice if there
would be no need to parse and analyze things twice, may take time and
resources depending on the commit size.


Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Stephen Butler <sb...@elego.de>.
On Feb 23, 2012, at 10:44 , Torsten Krah wrote:

> Am Mittwoch, den 22.02.2012, 14:53 -0500 schrieb Andy Levy:
>> Can pre-commit clean up after itself, so that the environment is clean
>> regardless of the result of the commit?
> 
> Hm no, the action should do some work (external system) and does need to
> know if commit was successful or if it failed.
> At pre-commit time i'll got all changes (what changes, is it valid etc.
> pp. - all the things which can be done in pre-commit) and can prepare
> them for an external system.
> Those changes, which were prepared at pre-commit time, need to be
> committed at success time in post-commit and reverted if it fails (which
> is missing at the moment) - as data should be consistent as possible,
> the failing info would be needed here.
> Details how it is done does not matter, use case is:
> 
> 1. At pre-commit prepare things for an external system
> 2. let svn do its work
> 3. At successful commit do this too for prepared work, if it failed,
> revert prepared things too.

Why not do 1 & 3 in a post-commit hook?

Have you measured how much time you save by running the external 
system early?

I suspect you won't save much.  For a large commit over a slow connection, 
there may be a few minutes' gap between start-commit and pre-commit.  
The gap between pre-commit and post-commit is usually short because the 
data is already on the server.

Regards,
Steve

> 
> Did this explanation help to understand the use case? any ideas how to
> do, or impossible at the moment?
> May a feature request at bug tracker help to get those feature?



Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>.
Am Mittwoch, den 22.02.2012, 14:53 -0500 schrieb Andy Levy:
> Can pre-commit clean up after itself, so that the environment is clean
> regardless of the result of the commit?

Hm no, the action should do some work (external system) and does need to
know if commit was successful or if it failed.
At pre-commit time i'll got all changes (what changes, is it valid etc.
pp. - all the things which can be done in pre-commit) and can prepare
them for an external system.
Those changes, which were prepared at pre-commit time, need to be
committed at success time in post-commit and reverted if it fails (which
is missing at the moment) - as data should be consistent as possible,
the failing info would be needed here.
Details how it is done does not matter, use case is:

1. At pre-commit prepare things for an external system
2. let svn do its work
3. At successful commit do this too for prepared work, if it failed,
revert prepared things too.

Did this explanation help to understand the use case? any ideas how to
do, or impossible at the moment?
May a feature request at bug tracker help to get those feature?

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Andy Levy <an...@gmail.com>.
On Wed, Feb 22, 2012 at 14:49, Torsten Krah
<tk...@fachschaft.imn.htwk-leipzig.de> wrote:
> Am 22.02.2012 18:27, schrieb Ryan Schmidt:
>
>>
>> On Feb 22, 2012, at 09:23, Torsten Krah wrote:
>>
>>> the http://svnbook.red-bean.com/en/1.6/svn.ref.reposhooks.html book
>>> tells about the various post-* hooks.
>>> But those one are called on "successfull" operations.
>>> Whats the way to implement a hook, which is called after commit - it
>>> does not matter if successful or failed - the hook must be able to
>>> figure out if all went fine or something went wrong.
>>>
>>> Can this be done or is this not possible at the moment?
>>
>>
>> I don't think this is possible. You have the pre-commit hook, which fires
>> before the commit; you can examine the commit and reject it at that time if
>> desired. Assuming you don't reject it, the commit goes to Subversion's
>> engine which writes it to the repository. Then it calls the post-commit
>> hook, where you can do additional operations like send email notifications
>> about the commit.
>>
>> What circumstance to you envision in which the commit is not successful,
>> and what automated action do you intend to perform as a result?
>>
>
> If commit can not fail - for which ever reason - why the doc does state that
> the hook does only run if the commit is actual successful?
> So it is possible to fail or not?
>
> I need to be sure that prepared external resources from pre-commit are
> cleaned up - even in case it did fail. If it would be run only on success,
> which does imply that it might fail, i am unable to clean up my work done in
> pre-commit.
>
> any other ideas how to do?

Can pre-commit clean up after itself, so that the environment is clean
regardless of the result of the commit?

Perhaps if you described in more detail what you mean when you say
"prepared external resources from pre-commit" people can provide more
complete guidance.

Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>.
Am 22.02.2012 18:27, schrieb Ryan Schmidt:
>
> On Feb 22, 2012, at 09:23, Torsten Krah wrote:
>
>> the http://svnbook.red-bean.com/en/1.6/svn.ref.reposhooks.html book
>> tells about the various post-* hooks.
>> But those one are called on "successfull" operations.
>> Whats the way to implement a hook, which is called after commit - it
>> does not matter if successful or failed - the hook must be able to
>> figure out if all went fine or something went wrong.
>>
>> Can this be done or is this not possible at the moment?
>
> I don't think this is possible. You have the pre-commit hook, which fires before the commit; you can examine the commit and reject it at that time if desired. Assuming you don't reject it, the commit goes to Subversion's engine which writes it to the repository. Then it calls the post-commit hook, where you can do additional operations like send email notifications about the commit.
>
> What circumstance to you envision in which the commit is not successful, and what automated action do you intend to perform as a result?
>

If commit can not fail - for which ever reason - why the doc does state 
that the hook does only run if the commit is actual successful?
So it is possible to fail or not?

I need to be sure that prepared external resources from pre-commit are 
cleaned up - even in case it did fail. If it would be run only on 
success, which does imply that it might fail, i am unable to clean up my 
work done in pre-commit.

any other ideas how to do?


Re: commit hooks - is there a hook which is called after commit even if its not successful

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Feb 22, 2012, at 09:23, Torsten Krah wrote:

> the http://svnbook.red-bean.com/en/1.6/svn.ref.reposhooks.html book
> tells about the various post-* hooks.
> But those one are called on "successfull" operations.
> Whats the way to implement a hook, which is called after commit - it
> does not matter if successful or failed - the hook must be able to
> figure out if all went fine or something went wrong.
> 
> Can this be done or is this not possible at the moment?

I don't think this is possible. You have the pre-commit hook, which fires before the commit; you can examine the commit and reject it at that time if desired. Assuming you don't reject it, the commit goes to Subversion's engine which writes it to the repository. Then it calls the post-commit hook, where you can do additional operations like send email notifications about the commit.

What circumstance to you envision in which the commit is not successful, and what automated action do you intend to perform as a result?