merge: remove drop_save() in favor of remove_merge_branch_state()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 9 May 2019 10:10:27 +0000 (17:10 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 May 2019 02:49:14 +0000 (11:49 +0900)
Both remove_branch_state() and drop_save() delete almost the same set of
files about the current merge state. The only difference is MERGE_RR but
it should also be cleaned up after a successful merge, which is what
drop_save() is for.

Make a new function that deletes all merge-related state files and use
it instead of drop_save(). This function will also be used in the next
patch that introduces --quit.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c
branch.h
builtin/merge.c
index 28b81a7e0256b2923c0fe296d9618d130821cdc4..1db0601a1124be0dcb83c4805e37baa55bfff5b5 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -337,15 +337,20 @@ void create_branch(struct repository *r,
        free(real_ref);
 }
 
-void remove_branch_state(struct repository *r)
+void remove_merge_branch_state(struct repository *r)
 {
-       unlink(git_path_cherry_pick_head(r));
-       unlink(git_path_revert_head(r));
        unlink(git_path_merge_head(r));
        unlink(git_path_merge_rr(r));
        unlink(git_path_merge_msg(r));
        unlink(git_path_merge_mode(r));
+}
+
+void remove_branch_state(struct repository *r)
+{
+       unlink(git_path_cherry_pick_head(r));
+       unlink(git_path_revert_head(r));
        unlink(git_path_squash_msg(r));
+       remove_merge_branch_state(r);
 }
 
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
index 29c1afa4d0ce5d1639b81d3d652d5b16085218e9..c90ba9d7bfa2db0588092200f98c1e0c2cc1b80f 100644 (file)
--- a/branch.h
+++ b/branch.h
@@ -60,6 +60,12 @@ extern int validate_branchname(const char *name, struct strbuf *ref);
  */
 extern int validate_new_branchname(const char *name, struct strbuf *ref, int force);
 
+/*
+ * Remove information about the merge state on the current
+ * branch. (E.g., MERGE_HEAD)
+ */
+void remove_merge_branch_state(struct repository *r);
+
 /*
  * Remove information about the state of working on the current
  * branch. (E.g., MERGE_HEAD)
index e47d77baeebe888cfb67f8e03804ffc3ee3715c0..e9663f027ada2807e62a1ce625d2bffca0332dac 100644 (file)
@@ -37,6 +37,7 @@
 #include "packfile.h"
 #include "tag.h"
 #include "alias.h"
+#include "branch.h"
 #include "commit-reach.h"
 
 #define DEFAULT_TWOHEAD (1<<0)
@@ -279,14 +280,6 @@ static struct option builtin_merge_options[] = {
        OPT_END()
 };
 
-/* Cleans up metadata that is uninteresting after a succeeded merge. */
-static void drop_save(void)
-{
-       unlink(git_path_merge_head(the_repository));
-       unlink(git_path_merge_msg(the_repository));
-       unlink(git_path_merge_mode(the_repository));
-}
-
 static int save_state(struct object_id *stash)
 {
        int len;
@@ -380,7 +373,7 @@ static void finish_up_to_date(const char *msg)
 {
        if (verbosity >= 0)
                printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
-       drop_save();
+       remove_merge_branch_state(the_repository);
 }
 
 static void squash_message(struct commit *commit, struct commit_list *remoteheads)
@@ -858,7 +851,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
                        &result_commit, NULL, sign_commit))
                die(_("failed to write commit object"));
        finish(head, remoteheads, &result_commit, "In-index merge");
-       drop_save();
+       remove_merge_branch_state(the_repository);
        return 0;
 }
 
@@ -885,7 +878,7 @@ static int finish_automerge(struct commit *head,
        strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
        finish(head, remoteheads, &result_commit, buf.buf);
        strbuf_release(&buf);
-       drop_save();
+       remove_merge_branch_state(the_repository);
        return 0;
 }
 
@@ -1463,7 +1456,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                }
 
                finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
-               drop_save();
+               remove_merge_branch_state(the_repository);
                goto done;
        } else if (!remoteheads->next && common->next)
                ;