merge: use refresh_and_write_cache

Use the 'refresh_and_write_cache()' convenience function introduced in the last commit, instead of refreshing and writing the index manually in merge.c Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Sep 11, 2019 at 19:20 UTC e080b34540296e4671b4d1110ba3c71b5224884a
1 file changed +3 -10
builtin/merge.c
+3 -10
@@ -688,16 +688,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
688 struct commit_list *remoteheads,
689 struct commit *head)
690 {
691 - struct lock_file lock = LOCK_INIT;
691 const char *head_arg = "HEAD";
692
694 - hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
695 - refresh_cache(REFRESH_QUIET);
696 - if (write_locked_index(&the_index, &lock,
697 - COMMIT_LOCK | SKIP_IF_UNCHANGED))
693 + if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)
694 return error(_("Unable to write index."));
695
696 if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
697 + struct lock_file lock = LOCK_INIT;
698 int clean, x;
699 struct commit *result;
700 struct commit_list *reversed = NULL;
@@ -860,12 +857,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
857 {
858 struct object_id result_tree, result_commit;
859 struct commit_list *parents, **pptr = &parents;
863 - struct lock_file lock = LOCK_INIT;
860
865 - hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
866 - refresh_cache(REFRESH_QUIET);
867 - if (write_locked_index(&the_index, &lock,
868 - COMMIT_LOCK | SKIP_IF_UNCHANGED))
861 + if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)
862 return error(_("Unable to write index."));
863
864 write_tree_trivial(&result_tree);