Merge branch 'hn/refs-pseudorefs'

Accesses to two pseudorefs have been updated to properly use ref
API.

* hn/refs-pseudorefs:
  sequencer: treat REVERT_HEAD as a pseudo ref
  builtin/commit: suggest update-ref for pseudoref removal
  sequencer: treat CHERRY_PICK_HEAD as a pseudo ref
  refs: make refs_ref_exists public
This commit is contained in:
Junio C Hamano 2020-08-31 15:49:48 -07:00
commit e699684cf6
8 changed files with 57 additions and 48 deletions

View File

@ -847,21 +847,19 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
!merge_contains_scissors) !merge_contains_scissors)
wt_status_add_cut_line(s->fp); wt_status_add_cut_line(s->fp);
status_printf_ln(s, GIT_COLOR_NORMAL, status_printf_ln(
whence == FROM_MERGE s, GIT_COLOR_NORMAL,
? _("\n"
"It looks like you may be committing a merge.\n"
"If this is not correct, please remove the file\n"
" %s\n"
"and try again.\n")
: _("\n"
"It looks like you may be committing a cherry-pick.\n"
"If this is not correct, please remove the file\n"
" %s\n"
"and try again.\n"),
whence == FROM_MERGE ? whence == FROM_MERGE ?
git_path_merge_head(the_repository) : _("\n"
git_path_cherry_pick_head(the_repository)); "It looks like you may be committing a merge.\n"
"If this is not correct, please run\n"
" git update-ref -d MERGE_HEAD\n"
"and try again.\n") :
_("\n"
"It looks like you may be committing a cherry-pick.\n"
"If this is not correct, please run\n"
" git update-ref -d CHERRY_PICK_HEAD\n"
"and try again.\n"));
} }
fprintf(s->fp, "\n"); fprintf(s->fp, "\n");

View File

@ -1348,7 +1348,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
else else
die(_("You have not concluded your merge (MERGE_HEAD exists).")); die(_("You have not concluded your merge (MERGE_HEAD exists)."));
} }
if (file_exists(git_path_cherry_pick_head(the_repository))) { if (ref_exists("CHERRY_PICK_HEAD")) {
if (advice_resolve_conflict) if (advice_resolve_conflict)
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n" die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
"Please, commit your changes before you merge.")); "Please, commit your changes before you merge."));

2
path.c
View File

@ -1528,8 +1528,6 @@ char *xdg_cache_home(const char *filename)
return NULL; return NULL;
} }
REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD")
REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG") REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG") REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR") REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")

9
path.h
View File

@ -170,8 +170,6 @@ void report_linked_checkout_garbage(void);
} }
struct path_cache { struct path_cache {
const char *cherry_pick_head;
const char *revert_head;
const char *squash_msg; const char *squash_msg;
const char *merge_msg; const char *merge_msg;
const char *merge_rr; const char *merge_rr;
@ -182,10 +180,11 @@ struct path_cache {
const char *shallow; const char *shallow;
}; };
#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } #define PATH_CACHE_INIT \
{ \
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
}
const char *git_path_cherry_pick_head(struct repository *r);
const char *git_path_revert_head(struct repository *r);
const char *git_path_squash_msg(struct repository *r); const char *git_path_squash_msg(struct repository *r);
const char *git_path_merge_msg(struct repository *r); const char *git_path_merge_msg(struct repository *r);
const char *git_path_merge_rr(struct repository *r); const char *git_path_merge_rr(struct repository *r);

2
refs.c
View File

@ -313,7 +313,7 @@ int read_ref(const char *refname, struct object_id *oid)
return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL); return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
} }
static int refs_ref_exists(struct ref_store *refs, const char *refname) int refs_ref_exists(struct ref_store *refs, const char *refname)
{ {
return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL); return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
} }

2
refs.h
View File

@ -105,6 +105,8 @@ int refs_verify_refname_available(struct ref_store *refs,
const struct string_list *skip, const struct string_list *skip,
struct strbuf *err); struct strbuf *err);
int refs_ref_exists(struct ref_store *refs, const char *refname);
int ref_exists(const char *refname); int ref_exists(const char *refname);
int should_autocreate_reflog(const char *refname); int should_autocreate_reflog(const char *refname);

View File

@ -381,7 +381,8 @@ static void print_advice(struct repository *r, int show_hint,
* (typically rebase --interactive) wants to take care * (typically rebase --interactive) wants to take care
* of the commit itself so remove CHERRY_PICK_HEAD * of the commit itself so remove CHERRY_PICK_HEAD
*/ */
unlink(git_path_cherry_pick_head(r)); refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
NULL, 0);
return; return;
} }
@ -1455,7 +1456,8 @@ static int do_commit(struct repository *r,
author, opts, flags, &oid); author, opts, flags, &oid);
strbuf_release(&sb); strbuf_release(&sb);
if (!res) { if (!res) {
unlink(git_path_cherry_pick_head(r)); refs_delete_ref(get_main_ref_store(r), "",
"CHERRY_PICK_HEAD", NULL, 0);
unlink(git_path_merge_msg(r)); unlink(git_path_merge_msg(r));
if (!is_rebase_i(opts)) if (!is_rebase_i(opts))
print_commit_summary(r, NULL, &oid, print_commit_summary(r, NULL, &oid,
@ -1966,7 +1968,8 @@ static int do_pick_commit(struct repository *r,
flags |= ALLOW_EMPTY; flags |= ALLOW_EMPTY;
} else if (allow == 2) { } else if (allow == 2) {
drop_commit = 1; drop_commit = 1;
unlink(git_path_cherry_pick_head(r)); refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
NULL, 0);
unlink(git_path_merge_msg(r)); unlink(git_path_merge_msg(r));
fprintf(stderr, fprintf(stderr,
_("dropping %s %s -- patch contents already upstream\n"), _("dropping %s %s -- patch contents already upstream\n"),
@ -2305,15 +2308,19 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
struct replay_opts opts = REPLAY_OPTS_INIT; struct replay_opts opts = REPLAY_OPTS_INIT;
int need_cleanup = 0; int need_cleanup = 0;
if (file_exists(git_path_cherry_pick_head(r))) { if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
if (!unlink(git_path_cherry_pick_head(r)) && verbose) if (!refs_delete_ref(get_main_ref_store(r), "",
"CHERRY_PICK_HEAD", NULL, 0) &&
verbose)
warning(_("cancelling a cherry picking in progress")); warning(_("cancelling a cherry picking in progress"));
opts.action = REPLAY_PICK; opts.action = REPLAY_PICK;
need_cleanup = 1; need_cleanup = 1;
} }
if (file_exists(git_path_revert_head(r))) { if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
if (!unlink(git_path_revert_head(r)) && verbose) if (!refs_delete_ref(get_main_ref_store(r), "", "REVERT_HEAD",
NULL, 0) &&
verbose)
warning(_("cancelling a revert in progress")); warning(_("cancelling a revert in progress"));
opts.action = REPLAY_REVERT; opts.action = REPLAY_REVERT;
need_cleanup = 1; need_cleanup = 1;
@ -2671,8 +2678,9 @@ static int create_seq_dir(struct repository *r)
enum replay_action action; enum replay_action action;
const char *in_progress_error = NULL; const char *in_progress_error = NULL;
const char *in_progress_advice = NULL; const char *in_progress_advice = NULL;
unsigned int advise_skip = file_exists(git_path_revert_head(r)) || unsigned int advise_skip =
file_exists(git_path_cherry_pick_head(r)); refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") ||
refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD");
if (!sequencer_get_last_command(r, &action)) { if (!sequencer_get_last_command(r, &action)) {
switch (action) { switch (action) {
@ -2771,8 +2779,8 @@ static int rollback_single_pick(struct repository *r)
{ {
struct object_id head_oid; struct object_id head_oid;
if (!file_exists(git_path_cherry_pick_head(r)) && if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
!file_exists(git_path_revert_head(r))) !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
return error(_("no cherry-pick or revert in progress")); return error(_("no cherry-pick or revert in progress"));
if (read_ref_full("HEAD", 0, &head_oid, NULL)) if (read_ref_full("HEAD", 0, &head_oid, NULL))
return error(_("cannot resolve HEAD")); return error(_("cannot resolve HEAD"));
@ -2866,7 +2874,7 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
*/ */
switch (opts->action) { switch (opts->action) {
case REPLAY_REVERT: case REPLAY_REVERT:
if (!file_exists(git_path_revert_head(r))) { if (!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
if (action != REPLAY_REVERT) if (action != REPLAY_REVERT)
return error(_("no revert in progress")); return error(_("no revert in progress"));
if (!rollback_is_safe()) if (!rollback_is_safe())
@ -2874,7 +2882,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
} }
break; break;
case REPLAY_PICK: case REPLAY_PICK:
if (!file_exists(git_path_cherry_pick_head(r))) { if (!refs_ref_exists(get_main_ref_store(r),
"CHERRY_PICK_HEAD")) {
if (action != REPLAY_PICK) if (action != REPLAY_PICK)
return error(_("no cherry-pick in progress")); return error(_("no cherry-pick in progress"));
if (!rollback_is_safe()) if (!rollback_is_safe())
@ -3569,7 +3578,8 @@ static int do_merge(struct repository *r,
oid_to_hex(&j->item->object.oid)); oid_to_hex(&j->item->object.oid));
strbuf_release(&ref_name); strbuf_release(&ref_name);
unlink(git_path_cherry_pick_head(r)); refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
NULL, 0);
rollback_lock_file(&lock); rollback_lock_file(&lock);
rollback_lock_file(&lock); rollback_lock_file(&lock);
@ -4201,8 +4211,8 @@ static int continue_single_pick(struct repository *r)
{ {
const char *argv[] = { "commit", NULL }; const char *argv[] = { "commit", NULL };
if (!file_exists(git_path_cherry_pick_head(r)) && if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
!file_exists(git_path_revert_head(r))) !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
return error(_("no cherry-pick or revert in progress")); return error(_("no cherry-pick or revert in progress"));
return run_command_v_opt(argv, RUN_GIT_CMD); return run_command_v_opt(argv, RUN_GIT_CMD);
} }
@ -4318,9 +4328,10 @@ static int commit_staged_changes(struct repository *r,
} }
if (is_clean) { if (is_clean) {
const char *cherry_pick_head = git_path_cherry_pick_head(r); if (refs_ref_exists(get_main_ref_store(r),
"CHERRY_PICK_HEAD") &&
if (file_exists(cherry_pick_head) && unlink(cherry_pick_head)) refs_delete_ref(get_main_ref_store(r), "",
"CHERRY_PICK_HEAD", NULL, 0))
return error(_("could not remove CHERRY_PICK_HEAD")); return error(_("could not remove CHERRY_PICK_HEAD"));
if (!final_fixup) if (!final_fixup)
return 0; return 0;
@ -4379,8 +4390,9 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
if (!is_rebase_i(opts)) { if (!is_rebase_i(opts)) {
/* Verify that the conflict has been resolved */ /* Verify that the conflict has been resolved */
if (file_exists(git_path_cherry_pick_head(r)) || if (refs_ref_exists(get_main_ref_store(r),
file_exists(git_path_revert_head(r))) { "CHERRY_PICK_HEAD") ||
refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
res = continue_single_pick(r); res = continue_single_pick(r);
if (res) if (res)
goto release_todo_list; goto release_todo_list;
@ -5443,7 +5455,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence) int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
{ {
if (file_exists(git_path_cherry_pick_head(r))) { if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
struct object_id cherry_pick_head, rebase_head; struct object_id cherry_pick_head, rebase_head;
if (file_exists(git_path_seq_dir())) if (file_exists(git_path_seq_dir()))

View File

@ -1668,13 +1668,13 @@ void wt_status_get_state(struct repository *r,
state->merge_in_progress = 1; state->merge_in_progress = 1;
} else if (wt_status_check_rebase(NULL, state)) { } else if (wt_status_check_rebase(NULL, state)) {
; /* all set */ ; /* all set */
} else if (!stat(git_path_cherry_pick_head(r), &st) && } else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
!get_oid("CHERRY_PICK_HEAD", &oid)) { !get_oid("CHERRY_PICK_HEAD", &oid)) {
state->cherry_pick_in_progress = 1; state->cherry_pick_in_progress = 1;
oidcpy(&state->cherry_pick_head_oid, &oid); oidcpy(&state->cherry_pick_head_oid, &oid);
} }
wt_status_check_bisect(NULL, state); wt_status_check_bisect(NULL, state);
if (!stat(git_path_revert_head(r), &st) && if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") &&
!get_oid("REVERT_HEAD", &oid)) { !get_oid("REVERT_HEAD", &oid)) {
state->revert_in_progress = 1; state->revert_in_progress = 1;
oidcpy(&state->revert_head_oid, &oid); oidcpy(&state->revert_head_oid, &oid);