Re: [SCRIPT] cg-rpush & locking
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Jun 2, 2005, 02:58 UTC
- Message-ID
- <Pine.LNX.4.58.0506011951150.1876@ppc970.osdl.org>
- In-Reply-To
- <20050601065123.GA23358@cip.informatik.uni-erlangen.de>
On Wed, 1 Jun 2005, Thomas Glanzmann wrote:
Show 8 quoted lines
> > 1. acquire remote lock > 2. get remote HEAD > 3. if remote HEAD is ahead (not included in our history) abort > and free lock. > 4. push objects > 5. update remote HEAD with local > 6. free remote lock.
You really need a specialized client at the other end, because regardless of locking, you want to write the objects atomically (ie download them into a temp-file, and then do the "rename" thing to make them show up all-or-nothing).
Also, I'd suggest a slight modification to avoid keeping the lock for a long time, namely to have the lock protect just a quick "compare and exchange". So the algorithm would become:
1. read remote HEAD 2. if remote HEAD isn't in our history, abort with "remote is ahead" 3. calculate the objects needed to push locally 4. push them (but accept the possibility that the remote may already have them, so have the protocol able to say "got that one already"). Make this use the atomic write on the other end. 5. do an atomic compare-and-exchange of the remote head with the new one (ie only switch the remote HEAD if it still matches what we were expecting it to be)
Hmm?
Linus