Skip to content

Commit e699684

Browse files
committed
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
2 parents 53015c9 + b8825ef commit e699684

File tree

8 files changed

+57
-48
lines changed

8 files changed

+57
-48
lines changed

builtin/commit.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -847,21 +847,19 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
847847
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
848848
!merge_contains_scissors)
849849
wt_status_add_cut_line(s->fp);
850-
status_printf_ln(s, GIT_COLOR_NORMAL,
851-
whence == FROM_MERGE
852-
? _("\n"
853-
"It looks like you may be committing a merge.\n"
854-
"If this is not correct, please remove the file\n"
855-
" %s\n"
856-
"and try again.\n")
857-
: _("\n"
858-
"It looks like you may be committing a cherry-pick.\n"
859-
"If this is not correct, please remove the file\n"
860-
" %s\n"
861-
"and try again.\n"),
850+
status_printf_ln(
851+
s, GIT_COLOR_NORMAL,
862852
whence == FROM_MERGE ?
863-
git_path_merge_head(the_repository) :
864-
git_path_cherry_pick_head(the_repository));
853+
_("\n"
854+
"It looks like you may be committing a merge.\n"
855+
"If this is not correct, please run\n"
856+
" git update-ref -d MERGE_HEAD\n"
857+
"and try again.\n") :
858+
_("\n"
859+
"It looks like you may be committing a cherry-pick.\n"
860+
"If this is not correct, please run\n"
861+
" git update-ref -d CHERRY_PICK_HEAD\n"
862+
"and try again.\n"));
865863
}
866864

867865
fprintf(s->fp, "\n");

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13481348
else
13491349
die(_("You have not concluded your merge (MERGE_HEAD exists)."));
13501350
}
1351-
if (file_exists(git_path_cherry_pick_head(the_repository))) {
1351+
if (ref_exists("CHERRY_PICK_HEAD")) {
13521352
if (advice_resolve_conflict)
13531353
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
13541354
"Please, commit your changes before you merge."));

path.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,6 @@ char *xdg_cache_home(const char *filename)
15281528
return NULL;
15291529
}
15301530

1531-
REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD")
1532-
REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
15331531
REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
15341532
REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
15351533
REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")

path.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void report_linked_checkout_garbage(void);
170170
}
171171

172172
struct path_cache {
173-
const char *cherry_pick_head;
174-
const char *revert_head;
175173
const char *squash_msg;
176174
const char *merge_msg;
177175
const char *merge_rr;
@@ -182,10 +180,11 @@ struct path_cache {
182180
const char *shallow;
183181
};
184182

185-
#define PATH_CACHE_INIT { NULL, 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+
}
186187

187-
const char *git_path_cherry_pick_head(struct repository *r);
188-
const char *git_path_revert_head(struct repository *r);
189188
const char *git_path_squash_msg(struct repository *r);
190189
const char *git_path_merge_msg(struct repository *r);
191190
const char *git_path_merge_rr(struct repository *r);

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ int read_ref(const char *refname, struct object_id *oid)
313313
return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
314314
}
315315

316-
static int refs_ref_exists(struct ref_store *refs, const char *refname)
316+
int refs_ref_exists(struct ref_store *refs, const char *refname)
317317
{
318318
return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
319319
}

refs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ int refs_verify_refname_available(struct ref_store *refs,
105105
const struct string_list *skip,
106106
struct strbuf *err);
107107

108+
int refs_ref_exists(struct ref_store *refs, const char *refname);
109+
108110
int ref_exists(const char *refname);
109111

110112
int should_autocreate_reflog(const char *refname);

sequencer.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ static void print_advice(struct repository *r, int show_hint,
381381
* (typically rebase --interactive) wants to take care
382382
* of the commit itself so remove CHERRY_PICK_HEAD
383383
*/
384-
unlink(git_path_cherry_pick_head(r));
384+
refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
385+
NULL, 0);
385386
return;
386387
}
387388

@@ -1455,7 +1456,8 @@ static int do_commit(struct repository *r,
14551456
author, opts, flags, &oid);
14561457
strbuf_release(&sb);
14571458
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);
14591461
unlink(git_path_merge_msg(r));
14601462
if (!is_rebase_i(opts))
14611463
print_commit_summary(r, NULL, &oid,
@@ -1966,7 +1968,8 @@ static int do_pick_commit(struct repository *r,
19661968
flags |= ALLOW_EMPTY;
19671969
} else if (allow == 2) {
19681970
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);
19701973
unlink(git_path_merge_msg(r));
19711974
fprintf(stderr,
19721975
_("dropping %s %s -- patch contents already upstream\n"),
@@ -2305,15 +2308,19 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
23052308
struct replay_opts opts = REPLAY_OPTS_INIT;
23062309
int need_cleanup = 0;
23072310

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)
23102315
warning(_("cancelling a cherry picking in progress"));
23112316
opts.action = REPLAY_PICK;
23122317
need_cleanup = 1;
23132318
}
23142319

2315-
if (file_exists(git_path_revert_head(r))) {
2316-
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)
23172324
warning(_("cancelling a revert in progress"));
23182325
opts.action = REPLAY_REVERT;
23192326
need_cleanup = 1;
@@ -2671,8 +2678,9 @@ static int create_seq_dir(struct repository *r)
26712678
enum replay_action action;
26722679
const char *in_progress_error = NULL;
26732680
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));
2681+
unsigned int advise_skip =
2682+
refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") ||
2683+
refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD");
26762684

26772685
if (!sequencer_get_last_command(r, &action)) {
26782686
switch (action) {
@@ -2771,8 +2779,8 @@ static int rollback_single_pick(struct repository *r)
27712779
{
27722780
struct object_id head_oid;
27732781

2774-
if (!file_exists(git_path_cherry_pick_head(r)) &&
2775-
!file_exists(git_path_revert_head(r)))
2782+
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
2783+
!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
27762784
return error(_("no cherry-pick or revert in progress"));
27772785
if (read_ref_full("HEAD", 0, &head_oid, NULL))
27782786
return error(_("cannot resolve HEAD"));
@@ -2866,15 +2874,16 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
28662874
*/
28672875
switch (opts->action) {
28682876
case REPLAY_REVERT:
2869-
if (!file_exists(git_path_revert_head(r))) {
2877+
if (!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
28702878
if (action != REPLAY_REVERT)
28712879
return error(_("no revert in progress"));
28722880
if (!rollback_is_safe())
28732881
goto give_advice;
28742882
}
28752883
break;
28762884
case REPLAY_PICK:
2877-
if (!file_exists(git_path_cherry_pick_head(r))) {
2885+
if (!refs_ref_exists(get_main_ref_store(r),
2886+
"CHERRY_PICK_HEAD")) {
28782887
if (action != REPLAY_PICK)
28792888
return error(_("no cherry-pick in progress"));
28802889
if (!rollback_is_safe())
@@ -3569,7 +3578,8 @@ static int do_merge(struct repository *r,
35693578
oid_to_hex(&j->item->object.oid));
35703579

35713580
strbuf_release(&ref_name);
3572-
unlink(git_path_cherry_pick_head(r));
3581+
refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
3582+
NULL, 0);
35733583
rollback_lock_file(&lock);
35743584

35753585
rollback_lock_file(&lock);
@@ -4201,8 +4211,8 @@ static int continue_single_pick(struct repository *r)
42014211
{
42024212
const char *argv[] = { "commit", NULL };
42034213

4204-
if (!file_exists(git_path_cherry_pick_head(r)) &&
4205-
!file_exists(git_path_revert_head(r)))
4214+
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
4215+
!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
42064216
return error(_("no cherry-pick or revert in progress"));
42074217
return run_command_v_opt(argv, RUN_GIT_CMD);
42084218
}
@@ -4318,9 +4328,10 @@ static int commit_staged_changes(struct repository *r,
43184328
}
43194329

43204330
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))
4331+
if (refs_ref_exists(get_main_ref_store(r),
4332+
"CHERRY_PICK_HEAD") &&
4333+
refs_delete_ref(get_main_ref_store(r), "",
4334+
"CHERRY_PICK_HEAD", NULL, 0))
43244335
return error(_("could not remove CHERRY_PICK_HEAD"));
43254336
if (!final_fixup)
43264337
return 0;
@@ -4379,8 +4390,9 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
43794390

43804391
if (!is_rebase_i(opts)) {
43814392
/* Verify that the conflict has been resolved */
4382-
if (file_exists(git_path_cherry_pick_head(r)) ||
4383-
file_exists(git_path_revert_head(r))) {
4393+
if (refs_ref_exists(get_main_ref_store(r),
4394+
"CHERRY_PICK_HEAD") ||
4395+
refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) {
43844396
res = continue_single_pick(r);
43854397
if (res)
43864398
goto release_todo_list;
@@ -5443,7 +5455,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
54435455

54445456
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
54455457
{
5446-
if (file_exists(git_path_cherry_pick_head(r))) {
5458+
if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
54475459
struct object_id cherry_pick_head, rebase_head;
54485460

54495461
if (file_exists(git_path_seq_dir()))

wt-status.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,13 +1668,13 @@ void wt_status_get_state(struct repository *r,
16681668
state->merge_in_progress = 1;
16691669
} else if (wt_status_check_rebase(NULL, state)) {
16701670
; /* all set */
1671-
} else if (!stat(git_path_cherry_pick_head(r), &st) &&
1672-
!get_oid("CHERRY_PICK_HEAD", &oid)) {
1671+
} else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
1672+
!get_oid("CHERRY_PICK_HEAD", &oid)) {
16731673
state->cherry_pick_in_progress = 1;
16741674
oidcpy(&state->cherry_pick_head_oid, &oid);
16751675
}
16761676
wt_status_check_bisect(NULL, state);
1677-
if (!stat(git_path_revert_head(r), &st) &&
1677+
if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") &&
16781678
!get_oid("REVERT_HEAD", &oid)) {
16791679
state->revert_in_progress = 1;
16801680
oidcpy(&state->revert_head_oid, &oid);

0 commit comments

Comments
 (0)