Skip to content

Commit cca3be6

Browse files
committed
Merge branch 'js/prepare-sequencer'
Update of the sequencer codebase to make it reusable to reimplement "rebase -i" continues. * js/prepare-sequencer: (27 commits) sequencer: mark all error messages for translation sequencer: start error messages consistently with lower case sequencer: quote filenames in error messages sequencer: mark action_name() for translation sequencer: remove overzealous assumption in rebase -i mode sequencer: teach write_message() to append an optional LF sequencer: refactor write_message() to take a pointer/length sequencer: roll back lock file if write_message() failed sequencer: stop releasing the strbuf in write_message() sequencer: left-trim lines read from the script sequencer: support cleaning up commit messages sequencer: support amending commits sequencer: allow editing the commit message on a case-by-case basis sequencer: introduce a helper to read files written by scripts sequencer: prepare for rebase -i's commit functionality sequencer: remember the onelines when parsing the todo file sequencer: get rid of the subcommand field sequencer: avoid completely different messages for different actions sequencer: strip CR from the todo script sequencer: completely revamp the "todo" script parsing ...
2 parents ee87d47 + 791eb87 commit cca3be6

File tree

5 files changed

+492
-261
lines changed

5 files changed

+492
-261
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void determine_whence(struct wt_status *s)
183183
whence = FROM_MERGE;
184184
else if (file_exists(git_path_cherry_pick_head())) {
185185
whence = FROM_CHERRY_PICK;
186-
if (file_exists(git_path(SEQ_DIR)))
186+
if (file_exists(git_path_seq_dir()))
187187
sequencer_in_use = 1;
188188
}
189189
else

builtin/revert.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
7171
die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
7272
}
7373

74-
static void parse_args(int argc, const char **argv, struct replay_opts *opts)
74+
static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
7575
{
7676
const char * const * usage_str = revert_or_cherry_pick_usage(opts);
7777
const char *me = action_name(opts);
@@ -115,25 +115,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
115115
if (opts->keep_redundant_commits)
116116
opts->allow_empty = 1;
117117

118-
/* Set the subcommand */
119-
if (cmd == 'q')
120-
opts->subcommand = REPLAY_REMOVE_STATE;
121-
else if (cmd == 'c')
122-
opts->subcommand = REPLAY_CONTINUE;
123-
else if (cmd == 'a')
124-
opts->subcommand = REPLAY_ROLLBACK;
125-
else
126-
opts->subcommand = REPLAY_NONE;
127-
128118
/* Check for incompatible command line arguments */
129-
if (opts->subcommand != REPLAY_NONE) {
119+
if (cmd) {
130120
char *this_operation;
131-
if (opts->subcommand == REPLAY_REMOVE_STATE)
121+
if (cmd == 'q')
132122
this_operation = "--quit";
133-
else if (opts->subcommand == REPLAY_CONTINUE)
123+
else if (cmd == 'c')
134124
this_operation = "--continue";
135125
else {
136-
assert(opts->subcommand == REPLAY_ROLLBACK);
126+
assert(cmd == 'a');
137127
this_operation = "--abort";
138128
}
139129

@@ -156,7 +146,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
156146
"--edit", opts->edit,
157147
NULL);
158148

159-
if (opts->subcommand != REPLAY_NONE) {
149+
if (cmd) {
160150
opts->revs = NULL;
161151
} else {
162152
struct setup_revision_opt s_r_opt;
@@ -174,35 +164,43 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
174164

175165
if (argc > 1)
176166
usage_with_options(usage_str, options);
167+
168+
/* These option values will be free()d */
169+
opts->gpg_sign = xstrdup_or_null(opts->gpg_sign);
170+
opts->strategy = xstrdup_or_null(opts->strategy);
171+
172+
if (cmd == 'q')
173+
return sequencer_remove_state(opts);
174+
if (cmd == 'c')
175+
return sequencer_continue(opts);
176+
if (cmd == 'a')
177+
return sequencer_rollback(opts);
178+
return sequencer_pick_revisions(opts);
177179
}
178180

179181
int cmd_revert(int argc, const char **argv, const char *prefix)
180182
{
181-
struct replay_opts opts;
183+
struct replay_opts opts = REPLAY_OPTS_INIT;
182184
int res;
183185

184-
memset(&opts, 0, sizeof(opts));
185186
if (isatty(0))
186187
opts.edit = 1;
187188
opts.action = REPLAY_REVERT;
188189
git_config(git_default_config, NULL);
189-
parse_args(argc, argv, &opts);
190-
res = sequencer_pick_revisions(&opts);
190+
res = run_sequencer(argc, argv, &opts);
191191
if (res < 0)
192192
die(_("revert failed"));
193193
return res;
194194
}
195195

196196
int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
197197
{
198-
struct replay_opts opts;
198+
struct replay_opts opts = REPLAY_OPTS_INIT;
199199
int res;
200200

201-
memset(&opts, 0, sizeof(opts));
202201
opts.action = REPLAY_PICK;
203202
git_config(git_default_config, NULL);
204-
parse_args(argc, argv, &opts);
205-
res = sequencer_pick_revisions(&opts);
203+
res = run_sequencer(argc, argv, &opts);
206204
if (res < 0)
207205
die(_("cherry-pick failed"));
208206
return res;

0 commit comments

Comments
 (0)