[git-users] Asyncronous post-receive

2013-01-07 Thread kumar
Hi

Is it possible to have asynchronous post-receive. I want to run a mirror 
script which will send a push request to the mirror server. Currently when 
i do a push to the remote server I have to wait for it push to the mirror 
server also. Is there a way for post-receive script asynchronously from my 
push to the remote server

-- 




Re: [git-users] Asyncronous post-receive

2013-01-07 Thread Konstantin Khomoutov
On Mon, Jan 07, 2013 at 02:42:46AM -0800, kumar wrote:

 Is it possible to have asynchronous post-receive. I want to run a mirror 
 script which will send a push request to the mirror server. Currently when 
 i do a push to the remote server I have to wait for it push to the mirror 
 server also. Is there a way for post-receive script asynchronously from my 
 push to the remote server

Implementing this has nothing to do with Git -- it's a matter of shell
scripting (or of whatever means your post-receive hook is implemented
with).

For shell scripting, just terminate the command which is to run the code
doing your push request with `' rather than plain newline or `;'.
The code might be just a single command pipeline, a script executed in
a subshell or it might be contained in a separate script file.

To demonstrate:

1) Running just one command without waiting it to complete:

git push -q $remote $refspec 

2) Calling a subshell:

(
   logger -p daemon.info -t git-server 'About to mirror...'
   git push -q $mirror $refspec
   logger -p daemon.info -t git-server Completed; RC=$?
) 

3) Calling an external script:

`dirname $0`/push-to-mirror 


Note though that a scheme like this one might be prone to abusing: if
the mirror server is slow (say, it's being accessed over a WAN link)
anyone with commit access might arrange for performing a long series of
pushes of tiny commits leading to creation of several mirror push request
processes running concurrently on your server.

Since you seem not to care about whether pushing to the mirror server
really succeeded or not, probably it's better to arrange for the
post-receive hook to just `touch` a flag file in a well-known place and
then set up a cron job that will check for the existence of this file,
and if it exists, it would push whatever changes available to the remote
server and then delete the file.

Another way is to `touch` such a flag file before performing a mirror
push and remove it afterwards; before attempting a mirror push, the
existence of this flag file should be checked, and if the file exists,
the push should not be attempted.  This would ensure only a single
mirror push attempt is active at any given time.

--