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

sequencer: treat REVERT_HEAD as a pseudo ref

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 b8825ef233840136bd01a9619b36af515f498eb2
4 files changed +13 -14
path.c
-1
@@ -1528,7 +1528,6 @@ char *xdg_cache_home(const char *filename)
1528 return NULL;
1529 }
1530
1531 -REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
1531 REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
1532 REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
1533 REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
path.h
+3 -5
@@ -170,7 +170,6 @@ void report_linked_checkout_garbage(void);
170 }
171
172 struct path_cache {
173 - const char *revert_head;
173 const char *squash_msg;
174 const char *merge_msg;
175 const char *merge_rr;
@@ -181,12 +180,11 @@ struct path_cache {
180 const char *shallow;
181 };
182
184 -#define PATH_CACHE_INIT \
185 - { \
186 - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
183 +#define PATH_CACHE_INIT \
184 + { \
185 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
186 }
187
189 -const char *git_path_revert_head(struct repository *r);
188 const char *git_path_squash_msg(struct repository *r);
189 const char *git_path_merge_msg(struct repository *r);
190 const char *git_path_merge_rr(struct repository *r);
sequencer.c
+9 -7
@@ -2317,8 +2317,10 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
2317 need_cleanup = 1;
2318 }
2319
2320 - if (file_exists(git_path_revert_head(r))) {
2321 - if (!unlink(git_path_revert_head(r)) && verbose)
2320 + if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
2321 + if (!refs_delete_ref(get_main_ref_store(r), "", "REVERT_HEAD",
2322 + NULL, 0) &&
2323 + verbose)
2324 warning(_("cancelling a revert in progress"));
2325 opts.action = REPLAY_REVERT;
2326 need_cleanup = 1;
@@ -2677,7 +2679,7 @@ static int create_seq_dir(struct repository *r)
2679 const char *in_progress_error = NULL;
2680 const char *in_progress_advice = NULL;
2681 unsigned int advise_skip =
2680 - file_exists(git_path_revert_head(r)) ||
2682 + refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") ||
2683 refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD");
2684
2685 if (!sequencer_get_last_command(r, &action)) {
@@ -2778,7 +2780,7 @@ static int rollback_single_pick(struct repository *r)
2780 struct object_id head_oid;
2781
2782 if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
2781 - !file_exists(git_path_revert_head(r)))
2783 + !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
2784 return error(_("no cherry-pick or revert in progress"));
2785 if (read_ref_full("HEAD", 0, &head_oid, NULL))
2786 return error(_("cannot resolve HEAD"));
@@ -2872,7 +2874,7 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
2874 */
2875 switch (opts->action) {
2876 case REPLAY_REVERT:
2875 - if (!file_exists(git_path_revert_head(r))) {
2877 + if (!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
2878 if (action != REPLAY_REVERT)
2879 return error(_("no revert in progress"));
2880 if (!rollback_is_safe())
@@ -4210,7 +4212,7 @@ static int continue_single_pick(struct repository *r)
4212 const char *argv[] = { "commit", NULL };
4213
4214 if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
4213 - !file_exists(git_path_revert_head(r)))
4215 + !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
4216 return error(_("no cherry-pick or revert in progress"));
4217 return run_command_v_opt(argv, RUN_GIT_CMD);
4218 }
@@ -4390,7 +4392,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4392 /* Verify that the conflict has been resolved */
4393 if (refs_ref_exists(get_main_ref_store(r),
4394 "CHERRY_PICK_HEAD") ||
4393 - file_exists(git_path_revert_head(r))) {
4395 + refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
4396 res = continue_single_pick(r);
4397 if (res)
4398 goto release_todo_list;
wt-status.c
+1 -1
@@ -1678,7 +1678,7 @@ void wt_status_get_state(struct repository *r,
1678 oidcpy(&state->cherry_pick_head_oid, &oid);
1679 }
1680 wt_status_check_bisect(NULL, state);
1681 - if (!stat(git_path_revert_head(r), &st) &&
1681 + if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") &&
1682 !get_oid("REVERT_HEAD", &oid)) {
1683 state->revert_in_progress = 1;
1684 oidcpy(&state->revert_head_oid, &oid);