merge: remove drop_save() in favor of remove_merge_branch_state()

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>

Nguyễn Thái Ngọc Duy committed May 9, 2019 at 17:10 UTC b64335554a3691cbc134fb73a598dfd593f44b4e
3 files changed +19 -15
branch.c
+8 -3
@@ -337,15 +337,20 @@ void create_branch(struct repository *r,
337 free(real_ref);
338 }
339
340 -void remove_branch_state(struct repository *r)
340 +void remove_merge_branch_state(struct repository *r)
341 {
342 - unlink(git_path_cherry_pick_head(r));
343 - unlink(git_path_revert_head(r));
342 unlink(git_path_merge_head(r));
343 unlink(git_path_merge_rr(r));
344 unlink(git_path_merge_msg(r));
345 unlink(git_path_merge_mode(r));
346 +}
347 +
348 +void remove_branch_state(struct repository *r)
349 +{
350 + unlink(git_path_cherry_pick_head(r));
351 + unlink(git_path_revert_head(r));
352 unlink(git_path_squash_msg(r));
353 + remove_merge_branch_state(r);
354 }
355
356 void die_if_checked_out(const char *branch, int ignore_current_worktree)
branch.h
+6
@@ -60,6 +60,12 @@ extern int validate_branchname(const char *name, struct strbuf *ref);
60 */
61 extern int validate_new_branchname(const char *name, struct strbuf *ref, int force);
62
63 +/*
64 + * Remove information about the merge state on the current
65 + * branch. (E.g., MERGE_HEAD)
66 + */
67 +void remove_merge_branch_state(struct repository *r);
68 +
69 /*
70 * Remove information about the state of working on the current
71 * branch. (E.g., MERGE_HEAD)
builtin/merge.c
+5 -12
@@ -37,6 +37,7 @@
37 #include "packfile.h"
38 #include "tag.h"
39 #include "alias.h"
40 +#include "branch.h"
41 #include "commit-reach.h"
42
43 #define DEFAULT_TWOHEAD (1<<0)
@@ -279,14 +280,6 @@ static struct option builtin_merge_options[] = {
280 OPT_END()
281 };
282
282 -/* Cleans up metadata that is uninteresting after a succeeded merge. */
283 -static void drop_save(void)
284 -{
285 - unlink(git_path_merge_head(the_repository));
286 - unlink(git_path_merge_msg(the_repository));
287 - unlink(git_path_merge_mode(the_repository));
288 -}
289 -
283 static int save_state(struct object_id *stash)
284 {
285 int len;
@@ -380,7 +373,7 @@ static void finish_up_to_date(const char *msg)
373 {
374 if (verbosity >= 0)
375 printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
383 - drop_save();
376 + remove_merge_branch_state(the_repository);
377 }
378
379 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)
851 &result_commit, NULL, sign_commit))
852 die(_("failed to write commit object"));
853 finish(head, remoteheads, &result_commit, "In-index merge");
861 - drop_save();
854 + remove_merge_branch_state(the_repository);
855 return 0;
856 }
857
@@ -885,7 +878,7 @@ static int finish_automerge(struct commit *head,
878 strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
879 finish(head, remoteheads, &result_commit, buf.buf);
880 strbuf_release(&buf);
888 - drop_save();
881 + remove_merge_branch_state(the_repository);
882 return 0;
883 }
884
@@ -1463,7 +1456,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1456 }
1457
1458 finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
1466 - drop_save();
1459 + remove_merge_branch_state(the_repository);
1460 goto done;
1461 } else if (!remoteheads->next && common->next)
1462 ;