]> git.ipfire.org Git - thirdparty/git.git/commit - shallow.c
shallow: use stat_validity to check for up-to-date file
authorJeff King <peff@peff.net>
Thu, 27 Feb 2014 10:56:31 +0000 (05:56 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Feb 2014 20:04:23 +0000 (12:04 -0800)
commit0cc77c386cea7afebb54a5e7263ca37569ecfe7a
treee718edef67b0e74a1cdcb3850b0479aedb226585
parent5f95c9f850b19b368c43ae399cc831b17a26a5ac
shallow: use stat_validity to check for up-to-date file

When we are about to write the shallow file, we check that
it has not changed since we last read it. Instead of
hand-rolling this, we can use stat_validity. This is built
around the index stat-check, so it is more robust than just
checking the mtime, as we do now (it uses the same check as
we do for index files).

The new code also handles the case of a shallow file
appearing unexpectedly. With the current code, two
simultaneous processes making us shallow (e.g., two "git
fetch --depth=1" running at the same time in a non-shallow
repository) can race to overwrite each other.

As a bonus, we also remove a race in determining the stat
information of what we read (we stat and then open, leaving
a race window; instead we should open and then fstat the
descriptor).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shallow.c