• J
    shallow: use stat_validity to check for up-to-date file · 0cc77c38
    Jeff King 提交于
    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: NJeff King <peff@peff.net>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    0cc77c38
shallow.c 17.1 KB