@matheusbsbs / matheus-bagliano / commits / c8e4159efd
Fork 0

sequencer: treat CHERRY_PICK_HEAD as a pseudo ref

Check for existence and delete CHERRY_PICK_HEAD through ref functions. This will help cherry-pick work with alternate ref storage backends. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Aug 21, 2020 at 16:59 UTC c8e4159efd226218d827b5da71fc8f95f8172412
5 files changed +33 -23
builtin/merge.c
+1 -1
@@ -1348,7 +1348,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1348 else
1349 die(_("You have not concluded your merge (MERGE_HEAD exists)."));
1350 }
1351 - if (file_exists(git_path_cherry_pick_head(the_repository))) {
1351 + if (ref_exists("CHERRY_PICK_HEAD")) {
1352 if (advice_resolve_conflict)
1353 die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
1354 "Please, commit your changes before you merge."));
path.c
-1
@@ -1528,7 +1528,6 @@ char *xdg_cache_home(const char *filename)
1528 return NULL;
1529 }
1530
1531 -REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD")
1531 REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
1532 REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
1533 REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
path.h
+4 -3
@@ -170,7 +170,6 @@ void report_linked_checkout_garbage(void);
170 }
171
172 struct path_cache {
173 - const char *cherry_pick_head;
173 const char *revert_head;
174 const char *squash_msg;
175 const char *merge_msg;
@@ -182,9 +181,11 @@ struct path_cache {
181 const char *shallow;
182 };
183
185 -#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
184 +#define PATH_CACHE_INIT \
185 + { \
186 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
187 + }
188
187 -const char *git_path_cherry_pick_head(struct repository *r);
189 const char *git_path_revert_head(struct repository *r);
190 const char *git_path_squash_msg(struct repository *r);
191 const char *git_path_merge_msg(struct repository *r);
sequencer.c
+26 -16
@@ -381,7 +381,8 @@ static void print_advice(struct repository *r, int show_hint,
381 * (typically rebase --interactive) wants to take care
382 * of the commit itself so remove CHERRY_PICK_HEAD
383 */
384 - unlink(git_path_cherry_pick_head(r));
384 + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
385 + NULL, 0);
386 return;
387 }
388
@@ -1455,7 +1456,8 @@ static int do_commit(struct repository *r,
1456 author, opts, flags, &oid);
1457 strbuf_release(&sb);
1458 if (!res) {
1458 - unlink(git_path_cherry_pick_head(r));
1459 + refs_delete_ref(get_main_ref_store(r), "",
1460 + "CHERRY_PICK_HEAD", NULL, 0);
1461 unlink(git_path_merge_msg(r));
1462 if (!is_rebase_i(opts))
1463 print_commit_summary(r, NULL, &oid,
@@ -1966,7 +1968,8 @@ static int do_pick_commit(struct repository *r,
1968 flags |= ALLOW_EMPTY;
1969 } else if (allow == 2) {
1970 drop_commit = 1;
1969 - unlink(git_path_cherry_pick_head(r));
1971 + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
1972 + NULL, 0);
1973 unlink(git_path_merge_msg(r));
1974 fprintf(stderr,
1975 _("dropping %s %s -- patch contents already upstream\n"),
@@ -2305,8 +2308,10 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
2308 struct replay_opts opts = REPLAY_OPTS_INIT;
2309 int need_cleanup = 0;
2310
2308 - if (file_exists(git_path_cherry_pick_head(r))) {
2309 - if (!unlink(git_path_cherry_pick_head(r)) && verbose)
2311 + if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
2312 + if (!refs_delete_ref(get_main_ref_store(r), "",
2313 + "CHERRY_PICK_HEAD", NULL, 0) &&
2314 + verbose)
2315 warning(_("cancelling a cherry picking in progress"));
2316 opts.action = REPLAY_PICK;
2317 need_cleanup = 1;
@@ -2671,8 +2676,9 @@ static int create_seq_dir(struct repository *r)
2676 enum replay_action action;
2677 const char *in_progress_error = NULL;
2678 const char *in_progress_advice = NULL;
2674 - unsigned int advise_skip = file_exists(git_path_revert_head(r)) ||
2675 - file_exists(git_path_cherry_pick_head(r));
2679 + unsigned int advise_skip =
2680 + file_exists(git_path_revert_head(r)) ||
2681 + refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD");
2682
2683 if (!sequencer_get_last_command(r, &action)) {
2684 switch (action) {
@@ -2771,7 +2777,7 @@ static int rollback_single_pick(struct repository *r)
2777 {
2778 struct object_id head_oid;
2779
2774 - if (!file_exists(git_path_cherry_pick_head(r)) &&
2780 + if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
2781 !file_exists(git_path_revert_head(r)))
2782 return error(_("no cherry-pick or revert in progress"));
2783 if (read_ref_full("HEAD", 0, &head_oid, NULL))
@@ -2874,7 +2880,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
2880 }
2881 break;
2882 case REPLAY_PICK:
2877 - if (!file_exists(git_path_cherry_pick_head(r))) {
2883 + if (!refs_ref_exists(get_main_ref_store(r),
2884 + "CHERRY_PICK_HEAD")) {
2885 if (action != REPLAY_PICK)
2886 return error(_("no cherry-pick in progress"));
2887 if (!rollback_is_safe())
@@ -3569,7 +3576,8 @@ static int do_merge(struct repository *r,
3576 oid_to_hex(&j->item->object.oid));
3577
3578 strbuf_release(&ref_name);
3572 - unlink(git_path_cherry_pick_head(r));
3579 + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
3580 + NULL, 0);
3581 rollback_lock_file(&lock);
3582
3583 rollback_lock_file(&lock);
@@ -4201,7 +4209,7 @@ static int continue_single_pick(struct repository *r)
4209 {
4210 const char *argv[] = { "commit", NULL };
4211
4204 - if (!file_exists(git_path_cherry_pick_head(r)) &&
4212 + if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
4213 !file_exists(git_path_revert_head(r)))
4214 return error(_("no cherry-pick or revert in progress"));
4215 return run_command_v_opt(argv, RUN_GIT_CMD);
@@ -4318,9 +4326,10 @@ static int commit_staged_changes(struct repository *r,
4326 }
4327
4328 if (is_clean) {
4321 - const char *cherry_pick_head = git_path_cherry_pick_head(r);
4322 -
4323 - if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
4329 + if (refs_ref_exists(get_main_ref_store(r),
4330 + "CHERRY_PICK_HEAD") &&
4331 + refs_delete_ref(get_main_ref_store(r), "",
4332 + "CHERRY_PICK_HEAD", NULL, 0))
4333 return error(_("could not remove CHERRY_PICK_HEAD"));
4334 if (!final_fixup)
4335 return 0;
@@ -4379,7 +4388,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4388
4389 if (!is_rebase_i(opts)) {
4390 /* Verify that the conflict has been resolved */
4382 - if (file_exists(git_path_cherry_pick_head(r)) ||
4391 + if (refs_ref_exists(get_main_ref_store(r),
4392 + "CHERRY_PICK_HEAD") ||
4393 file_exists(git_path_revert_head(r))) {
4394 res = continue_single_pick(r);
4395 if (res)
@@ -5442,7 +5452,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
5452
5453 int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
5454 {
5445 - if (file_exists(git_path_cherry_pick_head(r))) {
5455 + if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
5456 struct object_id cherry_pick_head, rebase_head;
5457
5458 if (file_exists(git_path_seq_dir()))
wt-status.c
+2 -2
@@ -1672,8 +1672,8 @@ void wt_status_get_state(struct repository *r,
1672 state->merge_in_progress = 1;
1673 } else if (wt_status_check_rebase(NULL, state)) {
1674 ; /* all set */
1675 - } else if (!stat(git_path_cherry_pick_head(r), &st) &&
1676 - !get_oid("CHERRY_PICK_HEAD", &oid)) {
1675 + } else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
1676 + !get_oid("CHERRY_PICK_HEAD", &oid)) {
1677 state->cherry_pick_in_progress = 1;
1678 oidcpy(&state->cherry_pick_head_oid, &oid);
1679 }