{"thread":{"id":"22875","subject":"Remote operations synchronization, and hooks","startedAt":"2010-03-02T05:09:46Z","lastAt":"2010-03-02T23:43:21Z","messageCount":2,"participants":["Eli Barzilay","Ilari Liusvaara"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"135999","messageId":"m3r5o3ux5x.fsf@winooski.ccs.neu.edu","threadId":"22875","inReplyTo":null,"subject":"Remote operations synchronization, and hooks","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-03-02T05:09:46Z","receivedAt":"2010-03-02T05:09:46Z","isPatch":false,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"Is there any kind of synchronization with remote operations?  That is,\ncan there be any race conditions if multiple clients connect?  I'm\nassuming that such operations are safe, but I couldn't find a place\nwith a concrete description.\n\nMore specifically, I'm wondering about writing hooks (specifically, a\n`post-receive' hook), and it would make things convenient if I knew\nthat it was called synchronously.\n\nAnd a related question: is there somewhere a summary of how the hooks\nare called for each operation?  The githooks man page specifies some\nof the relationships but a list with how each operation perform its\nwork would be much more convenient to read through.  For example, if a\nremote update had a list of operations with \"grab lock\" in the\nbeginning and a \"release lock\" after running the `post-receive' hook,\nthen I wouldn't have the above question.  Also, it's unclear how\n`post-update' is related to `post-receive' -- there's one comment in\nthe man entry for the former that makes it sound like it is supersedes\nby the latter, but there's nothing explicit about it.\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"136048","messageId":"20100302234320.GA13446@Knoppix","threadId":"22875","inReplyTo":"m3r5o3ux5x.fsf@winooski.ccs.neu.edu","subject":"Re: Remote operations synchronization, and hooks","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-03-02T23:43:21Z","receivedAt":"2010-03-02T23:43:21Z","isPatch":false,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Tue, Mar 02, 2010 at 12:09:46AM -0500, Eli Barzilay wrote:\n> Is there any kind of synchronization with remote operations?  That is,\n> can there be any race conditions if multiple clients connect?  I'm\n> assuming that such operations are safe, but I couldn't find a place\n> with a concrete description.\n\nWith respect to Git itself, each ref update is atomic and happens as\nclient intended or does not happen at all. Ref updates within push\nare independent. \n\nThus, Git remote ops themselves are safe from races (with exception of\nforced push, where race condition can lead to other client's changes\nbeing lost).\n\n> More specifically, I'm wondering about writing hooks (specifically, a\n> `post-receive' hook), and it would make things convenient if I knew\n> that it was called synchronously.\n\nAFAIK, there can be multiple post-receives running simulataneously.\n\n> And a related question: is there somewhere a summary of how the hooks\n> are called for each operation?  The githooks man page specifies some\n> of the relationships but a list with how each operation perform its\n> work would be much more convenient to read through.  For example, if a\n> remote update had a list of operations with \"grab lock\" in the\n> beginning and a \"release lock\" after running the `post-receive' hook,\n> then I wouldn't have the above question.\n\nThere are no such locks. I think the operation sequence goes as follows\n(reading the source code):\n\n1) List of modifications to do is received.\n2) If additional objects are needed, pack is received and installed/unpacked.\n3) pre-receive is run. If it fails, whole push is aborted.\n4) For each ref pushed, do:\n4a) update hook for that ref is run. If it fails, skip the ref.\n4b) Do atomic compare-and-swap on ref.\n5) Run post-receive hook.\n6) Run post-update hook.\n\nNo locking there.\n\n>  Also, it's unclear how\n> `post-update' is related to `post-receive' -- there's one comment in\n> the man entry for the former that makes it sound like it is supersedes\n> by the latter, but there's nothing explicit about it.\n\nThey both execute after push has completed. Interfaces are different but\nthat's about it. post-receive gets old and new values, post-update only\nref names.\n\n-Ilari\n"}]}