• J
    check_and_freshen_file: fix reversed success-check · 3096b2ec
    Jeff King 提交于
    When we want to write out a loose object file, we have
    always first made sure we don't already have the object
    somewhere. Since 33d4221c (write_sha1_file: freshen existing
    objects, 2014-10-15), we also update the timestamp on the
    file, so that a simultaneous prune knows somebody is
    likely to reference it soon.
    
    If our utime() call fails, we treat this the same as not
    having the object in the first place; the safe thing to do
    is write out another copy. However, the loose-object check
    accidentally inverts the utime() check; it returns failure
    _only_ when the utime() call actually succeeded. Thus it was
    failing to protect us there, and in the normal case where
    utime() succeeds, it caused us to pointlessly write out and
    link the object.
    
    This passed our freshening tests, because writing out the
    new object is certainly _one_ way of updating its utime. So
    the normal case was inefficient, but not wrong.
    
    While we're here, let's also drop a comment in front of the
    check_and_freshen functions, making a note of their return
    type (since it is not our usual "0 for success, -1 for
    error").
    Signed-off-by: NJeff King <peff@peff.net>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    3096b2ec
sha1_file.c 85.7 KB