Skip to content

Commit b643355

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit b643355

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

branch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,20 @@ void create_branch(struct repository *r,
337337
free(real_ref);
338338
}
339339

340-
void remove_branch_state(struct repository *r)
340+
void remove_merge_branch_state(struct repository *r)
341341
{
342-
unlink(git_path_cherry_pick_head(r));
343-
unlink(git_path_revert_head(r));
344342
unlink(git_path_merge_head(r));
345343
unlink(git_path_merge_rr(r));
346344
unlink(git_path_merge_msg(r));
347345
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));
348352
unlink(git_path_squash_msg(r));
353+
remove_merge_branch_state(r);
349354
}
350355

351356
void die_if_checked_out(const char *branch, int ignore_current_worktree)

branch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ extern int validate_branchname(const char *name, struct strbuf *ref);
6060
*/
6161
extern int validate_new_branchname(const char *name, struct strbuf *ref, int force);
6262

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+
6369
/*
6470
* Remove information about the state of working on the current
6571
* branch. (E.g., MERGE_HEAD)

builtin/merge.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "packfile.h"
3838
#include "tag.h"
3939
#include "alias.h"
40+
#include "branch.h"
4041
#include "commit-reach.h"
4142

4243
#define DEFAULT_TWOHEAD (1<<0)
@@ -279,14 +280,6 @@ static struct option builtin_merge_options[] = {
279280
OPT_END()
280281
};
281282

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-
290283
static int save_state(struct object_id *stash)
291284
{
292285
int len;
@@ -380,7 +373,7 @@ static void finish_up_to_date(const char *msg)
380373
{
381374
if (verbosity >= 0)
382375
printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
383-
drop_save();
376+
remove_merge_branch_state(the_repository);
384377
}
385378

386379
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)
858851
&result_commit, NULL, sign_commit))
859852
die(_("failed to write commit object"));
860853
finish(head, remoteheads, &result_commit, "In-index merge");
861-
drop_save();
854+
remove_merge_branch_state(the_repository);
862855
return 0;
863856
}
864857

@@ -885,7 +878,7 @@ static int finish_automerge(struct commit *head,
885878
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
886879
finish(head, remoteheads, &result_commit, buf.buf);
887880
strbuf_release(&buf);
888-
drop_save();
881+
remove_merge_branch_state(the_repository);
889882
return 0;
890883
}
891884

@@ -1463,7 +1456,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14631456
}
14641457

14651458
finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
1466-
drop_save();
1459+
remove_merge_branch_state(the_repository);
14671460
goto done;
14681461
} else if (!remoteheads->next && common->next)
14691462
;

0 commit comments

Comments
 (0)