You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Andrew Brosnan <an...@broscom.com> on 2007/03/01 15:26:02 UTC

update hook per project (or directory)

Hello,

I have a repos layout like

trunk
    proj_a
    proj_b
    proj_c

When wc1 commits I want a hook to update wc2. However, if wc1 only
commits something in proj_a, I only want proj_a updated in wc2. Since
post-commit only knows about repos path and revision number, how do I
accomplish this?

Thanks,
Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: update hook per project (or directory)

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 17, 2007, at 07:25, Jan Hendrik wrote:

>> Anything you do just in the post-commit hook, or any script the post-
>> commit hook calls, or any script called by such a script, and so
>> forth, is fine.
>>
>> However, if you fork off a new process (create a thread, whatever),
>> then that is a separate process and the post-commit hook itself can
>> end before the forked process does, and that's when problems as
>> described above can start.
>>
>> So, by (Unix) example (since I don't know Windows):
>>
>> If my post-commit hook is...
>>
>>
>> #!/bin/sh
>> REPOS="$1"
>> REV="$2"
>> /path/to/some-other-script.sh "$REPOS" "$REV"
>>
>>
>> ....then everything is fine, because post-commit will wait for some-
>> other-script.sh to finish before it finishes.
>>
>> However, if my post-commit hook is...
>>
>>
>> #!/bin/sh
>> REPOS="$1"
>> REV="$2"
>> /path/to/some-other-script.sh "$REPOS" "$REV" >/dev/null 2>/dev/ 
>> null &
>>
>>
>> ....then some-other-script.sh has been forked off into its own
>> process, and post-commit ends immediately, before some-other-
>> script.sh is done running, which can cause the possible problems as
>> mentioned above.
>
> I am not very versed with pipes, but if the output/result/whatever of
> a script/program is directed elsewhere (>/dev/null ...) then this is a
> fork-off or new thread and the calling script would not wait for  
> stuff?

[snip]

It's not the redirecting of stdout and stderr; it's the "&" character  
at the end that causes a new process to be forked. However,  
Subversion has recently acquired a new "feature" whereby if you do  
not also redirect stdout and stderr somewhere, Subversion will still  
wait for that forked process to end before returning from the hook  
script.


-- 

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Jan Hendrik <ja...@myrealbox.com>.
Concerning Re: update hook per project (or dir
Ryan Schmidt wrote on 6 Mar 2007, 21:49, at least in part:

[...]

> Maybe threads isn't the right word. But what I meant to say:
> 
> Anything you do just in the post-commit hook, or any script the post-
> commit hook calls, or any script called by such a script, and so 
> forth, is fine.
> 
> However, if you fork off a new process (create a thread, whatever), 
> then that is a separate process and the post-commit hook itself can 
> end before the forked process does, and that's when problems as 
> described above can start.
> 
> So, by (Unix) example (since I don't know Windows):
> 
> If my post-commit hook is...
> 
> 
> #!/bin/sh
> REPOS="$1"
> REV="$2"
> /path/to/some-other-script.sh "$REPOS" "$REV"
> 
> 
> ....then everything is fine, because post-commit will wait for some-
> other-script.sh to finish before it finishes.
> 
> However, if my post-commit hook is...
> 
> 
> #!/bin/sh
> REPOS="$1"
> REV="$2"
> /path/to/some-other-script.sh "$REPOS" "$REV" >/dev/null 2>/dev/null &
> 
> 
> ....then some-other-script.sh has been forked off into its own  
> process, and post-commit ends immediately, before some-other- 
> script.sh is done running, which can cause the possible problems as 
> mentioned above.

I am not very versed with pipes, but if the output/result/whatever of 
a script/program is directed elsewhere (>/dev/null ...) then this is a 
fork-off or new thread and the calling script would not wait for stuff?  
Logical enough.  What you wrote also reminds me of a couple of 
scripts I use here for some operations on both local and remote 
stuff.  The local script calls a complementary script on the remote 
system (telnet/ssh) and then waits for the remote script to finish, 
and if the connection to the remote system breaks occasionally I 
have to kill the local script process.  Guess I understand this 
business better now.  Thanks, Ryan.

JH
---------------------------------------
Freedom quote:

     Freedom makes a huge requirement of every human being.
     With freedom comes responsibility.
     For the person who is unwilling to grow up,
     the person who does not want to carry is own weight,
     this is a frightening prospect.
               -- Eleanor Roosevelt

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Jeff Smith <js...@robotronics.com>.
On Saturday 17 March 2007 07:30, Jan Hendrik wrote:
> > #!/bin/sh
> > REPOS="$1"
> > REV="$2"
> > /path/to/some-other-script.sh "$REPOS" "$REV" >/dev/null
> > 2>/dev/null &
> >
> >
> > ....then some-other-script.sh has been forked off into its own
> > process, and post-commit ends immediately, before some-other-
> > script.sh is done running, which can cause the possible problems
> > as mentioned above.
>
> I am not very versed with pipes, but if the output/result/whatever
> of a script/program is directed elsewhere (>/dev/null ...) then
> this is a fork-off or new thread and the calling script would not
> wait for stuff? Logical enough.  What you wrote also reminds me of
> a couple of scripts I use here for some operations on both local
> and remote stuff.  The local script calls a complementary script on
> the remote system (telnet/ssh) and then waits for the remote script
> to finish, and if the connection to the remote system breaks
> occasionally I have to kill the local script process.  Guess I
> understand this business better now.  Thanks, Ryan.
>
> JH

Basically, what matters is whether they are running in parallel, so 
that post-commit hook likely finishes before some-other-script. So if 
you're not sure how that works in your system, you could try running 
some-other-script with a long delay and see if the script calling it 
finishes quickly or also waits a long time.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 6, 2007, at 06:30, Jan Hendrik wrote:

>> If the post-commit hook just runs svn update on the server's working
>> copy, then the commit will not be completed until the update is done.
>> Therefore, nobody can commit while the update is running. That would
>> be a good thing.
>
> Except if it happens to be a big commit/update, might block others
> from committing for quite some time.  If the post-commit hook
> updating the server's working copy hangs, e.g. network problems,
> probably forever, till someone goes in and kills the process.
>
>> If, on the other hand, you have written your post-commit hook script
>> to kick off the svn update process in its own thread and then return
>> control, then the commit will complete right then, before the update
>> is done, and another user could commit before the first user's update
>> is complete. Then the second user's svn update will fail because the
>> server's working copy will be locked, and your site will be missing
>> the second user's updates, until someone else commits something.
>
> Not familiar with threads, but I suppose it would be the same
> thread as long as the post-commit hook script does the work itself.
>  But if it is just a wrapper for the actual script, e.g. post- 
> commit.bat
> calling server-update.py, then this would run in a different thread,
> right?

Maybe threads isn't the right word. But what I meant to say:

Anything you do just in the post-commit hook, or any script the post- 
commit hook calls, or any script called by such a script, and so  
forth, is fine.

However, if you fork off a new process (create a thread, whatever),  
then that is a separate process and the post-commit hook itself can  
end before the forked process does, and that's when problems as  
described above can start.

So, by (Unix) example (since I don't know Windows):

If my post-commit hook is...


#!/bin/sh
REPOS="$1"
REV="$2"
/path/to/some-other-script.sh "$REPOS" "$REV"


...then everything is fine, because post-commit will wait for some- 
other-script.sh to finish before it finishes.

However, if my post-commit hook is...


#!/bin/sh
REPOS="$1"
REV="$2"
/path/to/some-other-script.sh "$REPOS" "$REV" >/dev/null 2>/dev/null &


...then some-other-script.sh has been forked off into its own  
process, and post-commit ends immediately, before some-other- 
script.sh is done running, which can cause the possible problems as  
mentioned above.


-- 

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Jan Hendrik <ja...@myrealbox.com>.
Concerning Re: update hook per project (or dir
Ryan Schmidt wrote on 2 Mar 2007, 21:52, at least in part:

> On Mar 2, 2007, at 06:38, Andrew Brosnan wrote:
> 
> > On 3/2/07 at 9:42 AM, Jan Hendrik wrote:

> >> But consider what happens to your website if the svn update
> >> execution fails for any reason
> >
> > the script needs to deal with that, i.e. - logging, error handling
> >
> >> or if there is another commit while
> >> the script still runs
> >
> > ...hmmm, I don't know. The script just runs svn up. What happens if 
> > one user commits while another is running update? That should be OK.
> 
> If the post-commit hook just runs svn update on the server's working 
> copy, then the commit will not be completed until the update is done. 
> Therefore, nobody can commit while the update is running. That would 
> be a good thing.

Except if it happens to be a big commit/update, might block others 
from committing for quite some time.  If the post-commit hook 
updating the server's working copy hangs, e.g. network problems, 
probably forever, till someone goes in and kills the process.

> If, on the other hand, you have written your post-commit hook script 
> to kick off the svn update process in its own thread and then return 
> control, then the commit will complete right then, before the update 
> is done, and another user could commit before the first user's update 
> is complete. Then the second user's svn update will fail because the 
> server's working copy will be locked, and your site will be missing 
> the second user's updates, until someone else commits something.

Not familiar with threads, but I suppose it would be the same 
thread as long as the post-commit hook script does the work itself. 
 But if it is just a wrapper for the actual script, e.g. post-commit.bat 
calling server-update.py, then this would run in a different thread, 
right?

> >> Guess this will be less of an
> >> issue if repository and the website wc are on the same machine,
> >
> > one is, a mirror is not

Wouldn't the mirror best be handled by a cron job completely 
separate of svn repository and post-commit hooks?

> svn updates are not atomic. It is possible that the update could fail 
> part of the way through, leaving you with a working copy that has 
> some updates in it, and is missing some others. This becomes much 
> more likely if the repository and the working copy are not on the 
> same machine, because then network issues can affect the update.

At least a full svn update should be run at reasonable intervals to 
make sure the server's working copy is really and completely 
updated as kind of insurance against (partly) failed post-commit 
updates.  Or probably be part of error handling, though if a post-
commit update fails for network issues it is likely that another 
attempt through error handling will fail just the same.

JH
---------------------------------------
Freedom quote:

     You need only reflect that one of the best ways
     to get yourself a reputation as a dangerous citizen these days
     is to go about repeating the very phrases
     which our founding fathers used in the great struggle for independence.
               -- Charles Austin Beard (1874-1948)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 2, 2007, at 06:38, Andrew Brosnan wrote:

> On 3/2/07 at 9:42 AM, Jan Hendrik wrote:
>
>> Concerning Re: update hook per project (or dir
>> Andrew Brosnan wrote on 1 Mar 2007, 13:18, at least in part:
>>
>>> The idea is to update the wc running a website, so only that one wc
>>> will auto-update. I was trying to avoid running svn up on the entire
>>> wc. when perhaps only a few files had been committed.
>>>
>>> Funnily enough, I started writing a script to do this using svnlook
>>> just as I got your response. Thanks Andy!
>>
>> But consider what happens to your website if the svn update
>> execution fails for any reason
>
> the script needs to deal with that, i.e. - logging, error handling
>
>> or if there is another commit while
>> the script still runs
>
> ...hmmm, I don't know. The script just runs svn up. What happens if  
> one
> user commits while another is running update? That should be OK.

If the post-commit hook just runs svn update on the server's working  
copy, then the commit will not be completed until the update is done.  
Therefore, nobody can commit while the update is running. That would  
be a good thing.

If, on the other hand, you have written your post-commit hook script  
to kick off the svn update process in its own thread and then return  
control, then the commit will complete right then, before the update  
is done, and another user could commit before the first user's update  
is complete. Then the second user's svn update will fail because the  
server's working copy will be locked, and your site will be missing  
the second user's updates, until someone else commits something.

>> Guess this will be less of an
>> issue if repository and the website wc are on the same machine,
>
> one is, a mirror is not
>
>> but if they are not and you have to run the script through ssh/telnet
>> you might more easily end up with a wc lacking some updates.
>
> Not sure how. An update occurs after any commit. Seems like it  
> should be
> OK.

svn updates are not atomic. It is possible that the update could fail  
part of the way through, leaving you with a working copy that has  
some updates in it, and is missing some others. This becomes much  
more likely if the repository and the working copy are not on the  
same machine, because then network issues can affect the update.


-- 

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Andrew Brosnan <an...@broscom.com>.
On 3/2/07 at 9:42 AM, jan.hendrik@myrealbox.com (Jan Hendrik) wrote:

> Concerning Re: update hook per project (or dir
> Andrew Brosnan wrote on 1 Mar 2007, 13:18, at least in part:
> 
> > The idea is to update the wc running a website, so only that one wc
> > will auto-update. I was trying to avoid running svn up on the entire
> > wc. when perhaps only a few files had been committed.
> > 
> > Funnily enough, I started writing a script to do this using svnlook
> > just as I got your response. Thanks Andy!
> 
> But consider what happens to your website if the svn update 
> execution fails for any reason

the script needs to deal with that, i.e. - logging, error handling

> or if there is another commit while 
> the script still runs

...hmmm, I don't know. The script just runs svn up. What happens if one
user commits while another is running update? That should be OK.

> Guess this will be less of an 
> issue if repository and the website wc are on the same machine, 

one is, a mirror is not

> but if they are not and you have to run the script through ssh/telnet 
> you might more easily end up with a wc lacking some updates.

Not sure how. An update occurs after any commit. Seems like it should be
OK.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: update hook per project (or directory)

Posted by Jan Hendrik <ja...@myrealbox.com>.
Concerning Re: update hook per project (or dir
Andrew Brosnan wrote on 1 Mar 2007, 13:18, at least in part:

> The idea is to update the wc running a website, so only that one wc
> will auto-update. I was trying to avoid running svn up on the entire
> wc. when perhaps only a few files had been committed.
> 
> Funnily enough, I started writing a script to do this using svnlook
> just as I got your response. Thanks Andy!

But consider what happens to your website if the svn update 
execution fails for any reason or if there is another commit while 
the script still runs (or even hangs).  Guess this will be less of an 
issue if repository and the website wc are on the same machine, 
but if they are not and you have to run the script through ssh/telnet 
you might more easily end up with a wc lacking some updates.

JH
---------------------------------------
Freedom quote:

     Freedom is the right to question and change
     the established way of doing things.
     It is the continuous revolution of the marketplace,
     and the understanding that allows us to recognize shortcomings
     and seek solutions.
               -- Ronald Reagan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Andy Levy <an...@gmail.com>.
On 3/1/07, Andrew Brosnan <an...@broscom.com> wrote:
> On 3/1/07 at 1:03 PM, andy.levy@gmail.com (Andy Levy) wrote:
>
> > On 3/1/07, Andrew Brosnan <an...@broscom.com> wrote:
> > > Hello,
> > >
> > > I have a repos layout like
> > >
> > > trunk
> > >     proj_a
> > >     proj_b
> > >     proj_c
> > >
> > > When wc1 commits I want a hook to update wc2. However, if wc1 only
> > > commits something in proj_a, I only want proj_a updated in wc2.
> Since
> > > post-commit only knows about repos path and revision number, how do
> I
> > > accomplish this?
> >
> > Have the first step of your hook script be to check what changed using
> > svnlook changed. Then, based on the paths changed, do whatever needs
> > to be done.
> >
> > HOWEVER, modifying the repository in a hook script can be troublesome.
> > If someone commits to wc1, then their WC is instantly out of date
> > because your hook will increment the global revision # when /trunk/wc2
> > is updated. I know modifying the in-flight transaction in the
> > pre-commit is considered a Bad Thing(tm); doing what you're asking is
> > less bad, but may still not be a great idea.
> >
> > Plus, you could find yourself in a loop if you're not every careful -
> > if that hook accidentally updates /trunk/wc1, it'll call the hook
> > again.
>
> The idea is to update the wc running a website, so only that one wc will
> auto-update. I was trying to avoid running svn up on the entire wc. when
> perhaps only a few files had been committed.

OK, that makes more sense. As I originally read it, I thought you
wanted a commit on /trunk/wc1 to trigger a change and commit made to
/trunk/wc2

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Andrew Brosnan <an...@broscom.com>.
On 3/1/07 at 1:03 PM, andy.levy@gmail.com (Andy Levy) wrote:

> On 3/1/07, Andrew Brosnan <an...@broscom.com> wrote:
> > Hello,
> >
> > I have a repos layout like
> >
> > trunk
> >     proj_a
> >     proj_b
> >     proj_c
> >
> > When wc1 commits I want a hook to update wc2. However, if wc1 only
> > commits something in proj_a, I only want proj_a updated in wc2.
Since
> > post-commit only knows about repos path and revision number, how do
I
> > accomplish this?
> 
> Have the first step of your hook script be to check what changed using
> svnlook changed. Then, based on the paths changed, do whatever needs
> to be done.
> 
> HOWEVER, modifying the repository in a hook script can be troublesome.
> If someone commits to wc1, then their WC is instantly out of date
> because your hook will increment the global revision # when /trunk/wc2
> is updated. I know modifying the in-flight transaction in the
> pre-commit is considered a Bad Thing(tm); doing what you're asking is
> less bad, but may still not be a great idea.
> 
> Plus, you could find yourself in a loop if you're not every careful -
> if that hook accidentally updates /trunk/wc1, it'll call the hook
> again.

The idea is to update the wc running a website, so only that one wc will
auto-update. I was trying to avoid running svn up on the entire wc. when
perhaps only a few files had been committed.

Funnily enough, I started writing a script to do this using svnlook just
as I got your response. Thanks Andy!

Regards,
Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: update hook per project (or directory)

Posted by Andy Levy <an...@gmail.com>.
On 3/1/07, Andrew Brosnan <an...@broscom.com> wrote:
> Hello,
>
> I have a repos layout like
>
> trunk
>     proj_a
>     proj_b
>     proj_c
>
> When wc1 commits I want a hook to update wc2. However, if wc1 only
> commits something in proj_a, I only want proj_a updated in wc2. Since
> post-commit only knows about repos path and revision number, how do I
> accomplish this?

Have the first step of your hook script be to check what changed using
svnlook changed. Then, based on the paths changed, do whatever needs
to be done.

HOWEVER, modifying the repository in a hook script can be troublesome.
If someone commits to wc1, then their WC is instantly out of date
because your hook will increment the global revision # when /trunk/wc2
is updated. I know modifying the in-flight transaction in the
pre-commit is considered a Bad Thing(tm); doing what you're asking is
less bad, but may still not be a great idea.

Plus, you could find yourself in a loop if you're not every careful -
if that hook accidentally updates /trunk/wc1, it'll call the hook
again.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: update hook per project (or directory)

Posted by Andrew Brosnan <an...@broscom.com>.
On 3/1/07 at 10:26 AM, andrew@broscom.com (Andrew Brosnan) wrote:
> 
> I have a repos layout like
> 
> trunk
>     proj_a
>     proj_b
>     proj_c
> 
> When wc1 commits I want a hook to update wc2. However, if wc1 only
> commits something in proj_a, I only want proj_a updated in wc2. Since
> post-commit only knows about repos path and revision number, how do I
> accomplish this?

I've been looking through the list archives - seems a simpler way to ask
my question is:

How can one use post-commit to run update only on the files/directories
that were committed?

It seems like this is not currently possible. Is this correct?

Regards,
Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org