Skip to content
  • Martin Ågren's avatar
    write_locked_index(): add flag to avoid writing unchanged index · 61000814
    Martin Ågren authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    We have several callers like
    
    	if (active_cache_changed && write_locked_index(...))
    		handle_error();
    	rollback_lock_file(...);
    
    where the final rollback is needed because "!active_cache_changed"
    shortcuts the if-expression. There are also a few variants of this,
    including some if-else constructs that make it more clear when the
    explicit rollback is really needed.
    
    Teach `write_locked_index()` to take a new flag SKIP_IF_UNCHANGED and
    simplify the callers. Leave the most complicated of the callers (in
    builtin/update-index.c) unchanged. Rewriting it to use this new flag
    would end up duplicating logic.
    
    We could have made the new flag behave the other way round
    ("FORCE_WRITE"), but that could break existing users behind their backs.
    Let's take the more conservative approach. We can still migrate existing
    callers to use our new flag. Later we might even be able to flip the
    default, possibly without entirely ignoring the risk to in-flight or
    out-of-tree topics.
    
    Suggested-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarMartin Ågren <martin.agren@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    61000814