Re: [RFC] git checkout $tree -- $path always rewrites files
- From
Jeff King <peff@peff.net>
- Date
- Nov 7, 2014, 19:15 UTC
- Message-ID
- <20141107191554.GA5695@peff.net>
- In-Reply-To
- <CACsJy8CPLvmbcdHHmfu6g0dUXJVQ8NhwqfGPD=-kcBmzF_ha6g@mail.gmail.com>
On Fri, Nov 07, 2014 at 05:13:47PM +0700, Duy Nguyen wrote:
Show 15 quoted lines
> > By the way, one other thing I wondered while looking at this code: when > > we checkout a working tree file, we unlink the old one and write the new > > one in-place. Is there a particular reason we do this versus writing to > > a temporary file and renaming it into place? That would give > > simultaneous readers a more atomic view. > > > > I suspect the answer is something like: you cannot always do a rename, > > because you might have a typechange, directory becoming a file, or vice > > versa; so anyone relying on an atomic view during a checkout operation > > is already Doing It Wrong. Handling a content-change of an existing > > path would complicate the code, so we do not bother. > > Not a confirmation, but it looks like Linus did it just to make sure > he had new permissions right, in e447947 (Be much more liberal about > the file mode bits. - 2005-04-16).
Thanks for digging that up. I think that only gives us half the story, though. That explains why we would unlink/open instead of relying on just open(O_TRUNC). But I think opening a new tempfile would work the same as the current code in that respect.
-Peff