Skip to content

Commit c8e4159

Browse files
hanwengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3f9f1ac commit c8e4159

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +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")
15321531
REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
15331532
REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
15341533
REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")

path.h

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

172172
struct path_cache {
173-
const char *cherry_pick_head;
174173
const char *revert_head;
175174
const char *squash_msg;
176175
const char *merge_msg;
@@ -182,9 +181,11 @@ struct path_cache {
182181
const char *shallow;
183182
};
184183

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+
}
186188

187-
const char *git_path_cherry_pick_head(struct repository *r);
188189
const char *git_path_revert_head(struct repository *r);
189190
const char *git_path_squash_msg(struct repository *r);
190191
const char *git_path_merge_msg(struct repository *r);

sequencer.c

Lines changed: 26 additions & 16 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,8 +2308,10 @@ 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;
@@ -2671,8 +2676,9 @@ static int create_seq_dir(struct repository *r)
26712676
enum replay_action action;
26722677
const char *in_progress_error = NULL;
26732678
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");
26762682

26772683
if (!sequencer_get_last_command(r, &action)) {
26782684
switch (action) {
@@ -2771,7 +2777,7 @@ static int rollback_single_pick(struct repository *r)
27712777
{
27722778
struct object_id head_oid;
27732779

2774-
if (!file_exists(git_path_cherry_pick_head(r)) &&
2780+
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
27752781
!file_exists(git_path_revert_head(r)))
27762782
return error(_("no cherry-pick or revert in progress"));
27772783
if (read_ref_full("HEAD", 0, &head_oid, NULL))
@@ -2874,7 +2880,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
28742880
}
28752881
break;
28762882
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")) {
28782885
if (action != REPLAY_PICK)
28792886
return error(_("no cherry-pick in progress"));
28802887
if (!rollback_is_safe())
@@ -3569,7 +3576,8 @@ static int do_merge(struct repository *r,
35693576
oid_to_hex(&j->item->object.oid));
35703577

35713578
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);
35733581
rollback_lock_file(&lock);
35743582

35753583
rollback_lock_file(&lock);
@@ -4201,7 +4209,7 @@ static int continue_single_pick(struct repository *r)
42014209
{
42024210
const char *argv[] = { "commit", NULL };
42034211

4204-
if (!file_exists(git_path_cherry_pick_head(r)) &&
4212+
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
42054213
!file_exists(git_path_revert_head(r)))
42064214
return error(_("no cherry-pick or revert in progress"));
42074215
return run_command_v_opt(argv, RUN_GIT_CMD);
@@ -4318,9 +4326,10 @@ static int commit_staged_changes(struct repository *r,
43184326
}
43194327

43204328
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))
43244333
return error(_("could not remove CHERRY_PICK_HEAD"));
43254334
if (!final_fixup)
43264335
return 0;
@@ -4379,7 +4388,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
43794388

43804389
if (!is_rebase_i(opts)) {
43814390
/* 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") ||
43834393
file_exists(git_path_revert_head(r))) {
43844394
res = continue_single_pick(r);
43854395
if (res)
@@ -5442,7 +5452,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
54425452

54435453
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
54445454
{
5445-
if (file_exists(git_path_cherry_pick_head(r))) {
5455+
if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) {
54465456
struct object_id cherry_pick_head, rebase_head;
54475457

54485458
if (file_exists(git_path_seq_dir()))

wt-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,8 @@ void wt_status_get_state(struct repository *r,
16721672
state->merge_in_progress = 1;
16731673
} else if (wt_status_check_rebase(NULL, state)) {
16741674
; /* 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)) {
16771677
state->cherry_pick_in_progress = 1;
16781678
oidcpy(&state->cherry_pick_head_oid, &oid);
16791679
}

0 commit comments

Comments
 (0)