Skip to content

Commit 8d57f75

Browse files
phillipwoodgitster
authored andcommitted
commit: use enum value for multiple cherry-picks
Add FROM_CHERRY_PICK_MULTI for a sequence of cherry-picks rather than using a separate variable. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21b11c6 commit 8d57f75

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

builtin/commit.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ static enum commit_msg_cleanup_mode cleanup_mode;
122122
static const char *cleanup_arg;
123123

124124
static enum commit_whence whence;
125-
static int sequencer_in_use;
126125
static int use_editor = 1, include_status = 1;
127126
static int have_option_m;
128127
static struct strbuf message = STRBUF_INIT;
@@ -179,11 +178,9 @@ static void determine_whence(struct wt_status *s)
179178
{
180179
if (file_exists(git_path_merge_head(the_repository)))
181180
whence = FROM_MERGE;
182-
else if (file_exists(git_path_cherry_pick_head(the_repository))) {
183-
whence = FROM_CHERRY_PICK;
184-
if (file_exists(git_path_seq_dir()))
185-
sequencer_in_use = 1;
186-
}
181+
else if (file_exists(git_path_cherry_pick_head(the_repository)))
182+
whence = file_exists(git_path_seq_dir()) ?
183+
FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
187184
else
188185
whence = FROM_COMMIT;
189186
if (s)
@@ -453,7 +450,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
453450
if (whence != FROM_COMMIT) {
454451
if (whence == FROM_MERGE)
455452
die(_("cannot do a partial commit during a merge."));
456-
else if (whence == FROM_CHERRY_PICK)
453+
else if (is_from_cherry_pick(whence))
457454
die(_("cannot do a partial commit during a cherry-pick."));
458455
}
459456

@@ -771,7 +768,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
771768
*/
772769
else if (whence == FROM_MERGE)
773770
hook_arg1 = "merge";
774-
else if (whence == FROM_CHERRY_PICK) {
771+
else if (is_from_cherry_pick(whence)) {
775772
hook_arg1 = "commit";
776773
hook_arg2 = "CHERRY_PICK_HEAD";
777774
}
@@ -948,9 +945,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
948945
run_status(stdout, index_file, prefix, 0, s);
949946
if (amend)
950947
fputs(_(empty_amend_advice), stderr);
951-
else if (whence == FROM_CHERRY_PICK) {
948+
else if (is_from_cherry_pick(whence)) {
952949
fputs(_(empty_cherry_pick_advice), stderr);
953-
if (!sequencer_in_use)
950+
if (whence == FROM_CHERRY_PICK_SINGLE)
954951
fputs(_(empty_cherry_pick_advice_single), stderr);
955952
else
956953
fputs(_(empty_cherry_pick_advice_multi), stderr);
@@ -1156,7 +1153,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
11561153
if (amend && whence != FROM_COMMIT) {
11571154
if (whence == FROM_MERGE)
11581155
die(_("You are in the middle of a merge -- cannot amend."));
1159-
else if (whence == FROM_CHERRY_PICK)
1156+
else if (is_from_cherry_pick(whence))
11601157
die(_("You are in the middle of a cherry-pick -- cannot amend."));
11611158
}
11621159
if (fixup_message && squash_message)
@@ -1179,7 +1176,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
11791176
use_message = edit_message;
11801177
if (amend && !use_message && !fixup_message)
11811178
use_message = "HEAD";
1182-
if (!use_message && whence != FROM_CHERRY_PICK && renew_authorship)
1179+
if (!use_message && !is_from_cherry_pick(whence) && renew_authorship)
11831180
die(_("--reset-author can be used only with -C, -c or --amend."));
11841181
if (use_message) {
11851182
use_message_buffer = read_commit_message(use_message);
@@ -1188,7 +1185,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
11881185
author_message_buffer = use_message_buffer;
11891186
}
11901187
}
1191-
if (whence == FROM_CHERRY_PICK && !renew_authorship) {
1188+
if (is_from_cherry_pick(whence) && !renew_authorship) {
11921189
author_message = "CHERRY_PICK_HEAD";
11931190
author_message_buffer = read_commit_message(author_message);
11941191
}
@@ -1606,7 +1603,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16061603
reduce_heads_replace(&parents);
16071604
} else {
16081605
if (!reflog_msg)
1609-
reflog_msg = (whence == FROM_CHERRY_PICK)
1606+
reflog_msg = is_from_cherry_pick(whence)
16101607
? "commit (cherry-pick)"
16111608
: "commit";
16121609
commit_list_insert(current_head, &parents);

wt-status.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ enum show_ignored_type {
3838
enum commit_whence {
3939
FROM_COMMIT, /* normal */
4040
FROM_MERGE, /* commit came from merge */
41-
FROM_CHERRY_PICK /* commit came from cherry-pick */
41+
FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */
42+
FROM_CHERRY_PICK_MULTI /* commit came from a sequence of cherry-picks */
4243
};
4344

45+
static inline int is_from_cherry_pick(enum commit_whence whence)
46+
{
47+
return whence == FROM_CHERRY_PICK_SINGLE ||
48+
whence == FROM_CHERRY_PICK_MULTI;
49+
}
50+
4451
struct wt_status_change_data {
4552
int worktree_status;
4653
int index_status;

0 commit comments

Comments
 (0)