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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Dec 6, 2019 at 16:06 UTC
8d57f7574993deb906461d4267373e1c9c733053
2 files changed
+19
-15
builtin/commit.c
+11
-14
@@ -122,7 +122,6 @@ static enum commit_msg_cleanup_mode cleanup_mode;
122
static const char *cleanup_arg;
123
124
static enum commit_whence whence;
125
-static int sequencer_in_use;
125
static int use_editor = 1, include_status = 1;
126
static int have_option_m;
127
static struct strbuf message = STRBUF_INIT;
@@ -179,11 +178,9 @@ static void determine_whence(struct wt_status *s)
178
{
179
if (file_exists(git_path_merge_head(the_repository)))
180
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;
184
else
185
whence = FROM_COMMIT;
186
if (s)
@@ -453,7 +450,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
450
if (whence != FROM_COMMIT) {
451
if (whence == FROM_MERGE)
452
die(_("cannot do a partial commit during a merge."));
456
- else if (whence == FROM_CHERRY_PICK)
453
+ else if (is_from_cherry_pick(whence))
454
die(_("cannot do a partial commit during a cherry-pick."));
455
}
456
@@ -771,7 +768,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
768
*/
769
else if (whence == FROM_MERGE)
770
hook_arg1 = "merge";
774
- else if (whence == FROM_CHERRY_PICK) {
771
+ else if (is_from_cherry_pick(whence)) {
772
hook_arg1 = "commit";
773
hook_arg2 = "CHERRY_PICK_HEAD";
774
}
@@ -948,9 +945,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
945
run_status(stdout, index_file, prefix, 0, s);
946
if (amend)
947
fputs(_(empty_amend_advice), stderr);
951
- else if (whence == FROM_CHERRY_PICK) {
948
+ else if (is_from_cherry_pick(whence)) {
949
fputs(_(empty_cherry_pick_advice), stderr);
953
- if (!sequencer_in_use)
950
+ if (whence == FROM_CHERRY_PICK_SINGLE)
951
fputs(_(empty_cherry_pick_advice_single), stderr);
952
else
953
fputs(_(empty_cherry_pick_advice_multi), stderr);
@@ -1156,7 +1153,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1153
if (amend && whence != FROM_COMMIT) {
1154
if (whence == FROM_MERGE)
1155
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))
1157
die(_("You are in the middle of a cherry-pick -- cannot amend."));
1158
}
1159
if (fixup_message && squash_message)
@@ -1179,7 +1176,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1176
use_message = edit_message;
1177
if (amend && !use_message && !fixup_message)
1178
use_message = "HEAD";
1182
- if (!use_message && whence != FROM_CHERRY_PICK && renew_authorship)
1179
+ if (!use_message && !is_from_cherry_pick(whence) && renew_authorship)
1180
die(_("--reset-author can be used only with -C, -c or --amend."));
1181
if (use_message) {
1182
use_message_buffer = read_commit_message(use_message);
@@ -1188,7 +1185,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1185
author_message_buffer = use_message_buffer;
1186
}
1187
}
1191
- if (whence == FROM_CHERRY_PICK && !renew_authorship) {
1188
+ if (is_from_cherry_pick(whence) && !renew_authorship) {
1189
author_message = "CHERRY_PICK_HEAD";
1190
author_message_buffer = read_commit_message(author_message);
1191
}
@@ -1606,7 +1603,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1603
reduce_heads_replace(&parents);
1604
} else {
1605
if (!reflog_msg)
1609
- reflog_msg = (whence == FROM_CHERRY_PICK)
1606
+ reflog_msg = is_from_cherry_pick(whence)
1607
? "commit (cherry-pick)"
1608
: "commit";
1609
commit_list_insert(current_head, &parents);
wt-status.h
+8
-1
@@ -38,9 +38,16 @@ enum show_ignored_type {
38
enum commit_whence {
39
FROM_COMMIT, /* normal */
40
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 */
43
};
44
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
+
51
struct wt_status_change_data {
52
int worktree_status;
53
int index_status;