[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gits] How does git really change one's directory view?



On Sun, Jul 09, 2017 at 06:22:08AM -0600, Ganesh Gopalakrishnan wrote:
> > there must be some delicate dist. system issues if people are concurrently
> > switching branches and the machine hosting the repo crashes. No?
> 
> I guess not; branch switches are local; I meant, when concurrently pushing
> branches to remote..

You might actually be surprised how trivial git's primitive operations
are, and consequently how simple the concurrency becomes.

First, all git "objects" (files, trees, commits, etc.) are immutable,
and so the "alice sends object x to bob" operation is idempotent.
(Assuming SHA-1 collisions do not occur.)  Pushing a branch is really
just a matter of transferring the HEAD commit object (plus all objects
transitively reachable from that commit).  The recipient needs to be
careful that it doesn't consider itself to "have" any object until it
has received all of it and verified the hash, but any number of
transfers can happen in parallel (even for the same object, which
might be wasteful, but harmless).  If a transfer of a large number
of objects is interrupted then some unreferenced objects could
accumulate, which will waste space until they're eventually garbage
collected, but it's otherwise safe.

Finally, a push does need to update the branch reference (and each
branch is represented by a file containing the id, i.e. hash, of the
head commit).  This file is mutable, and it is important that modifications
to it are atomic.  But it's easy enough for git to write the new hash
to a temporary file and then rely on rename(2) filesystem semantics
to provide atomicity.

Cheers,
Gary.
-- 
       Gary Wong      gtw@flux.utah.edu      http://www.cs.utah.edu/~gtw/