summaryrefslogtreecommitdiff
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorLibravatar Martin Ågren <martin.agren@gmail.com>2018-03-01 21:40:20 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-03-01 13:28:01 -0800
commit610008146ed1647bb1da6a098e314b8929ff213e (patch)
tree373d4290af3644d7123a623133c6f10ca9dc4f78 /merge-recursive.c
parentsequencer: do not roll back lockfile unnecessarily (diff)
downloadtgif-610008146ed1647bb1da6a098e314b8929ff213e.tar.xz
write_locked_index(): add flag to avoid writing unchanged index
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: Jeff King <peff@peff.net> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 129577987b..2f232ad3b4 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2223,10 +2223,9 @@ int merge_recursive_generic(struct merge_options *o,
return clean;
}
- if (active_cache_changed &&
- write_locked_index(&the_index, &lock, COMMIT_LOCK))
+ if (write_locked_index(&the_index, &lock,
+ COMMIT_LOCK | SKIP_IF_UNCHANGED))
return err(o, _("Unable to write index."));
- rollback_lock_file(&lock);
return clean ? 0 : 1;
}