]> granicus.if.org Git - git/commitdiff
merge: use refresh_and_write_cache
authorThomas Gummerer <t.gummerer@gmail.com>
Wed, 11 Sep 2019 18:20:26 +0000 (19:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2019 16:58:22 +0000 (09:58 -0700)
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>
builtin/merge.c

index e2ccbc44e204173b09f5ad4b704a31a9e8643bb6..83e42fcb10151f7bc6684335b7a24fce73ed2f45 100644 (file)
@@ -688,16 +688,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                              struct commit_list *remoteheads,
                              struct commit *head)
 {
-       struct lock_file lock = LOCK_INIT;
        const char *head_arg = "HEAD";
 
-       hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
-       refresh_cache(REFRESH_QUIET);
-       if (write_locked_index(&the_index, &lock,
-                              COMMIT_LOCK | SKIP_IF_UNCHANGED))
+       if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)
                return error(_("Unable to write index."));
 
        if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
+               struct lock_file lock = LOCK_INIT;
                int clean, x;
                struct commit *result;
                struct commit_list *reversed = NULL;
@@ -860,12 +857,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
 {
        struct object_id result_tree, result_commit;
        struct commit_list *parents, **pptr = &parents;
-       struct lock_file lock = LOCK_INIT;
 
-       hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
-       refresh_cache(REFRESH_QUIET);
-       if (write_locked_index(&the_index, &lock,
-                              COMMIT_LOCK | SKIP_IF_UNCHANGED))
+       if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)
                return error(_("Unable to write index."));
 
        write_tree_trivial(&result_tree);