Skip to content

Commit 3389853

Browse files
phillipwoodgitster
authored andcommitted
rebase -i: use struct object_id for squash_onto
More preparation for using `struct rebase_options` in cmd_rebase__interactive(). Using a string was a hangover from the scripted version of rebase, update the functions that use `squash_onto` to take a `sturct object_id`. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d3488e commit 3389853

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

builtin/rebase.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
198198
static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
199199
const char *switch_to, struct commit *upstream,
200200
struct commit *onto, const char *onto_name,
201-
const char *squash_onto, const char *head_name,
201+
struct object_id *squash_onto, const char *head_name,
202202
struct commit *restrict_revision, char *raw_strategies,
203203
struct string_list *commands, unsigned autosquash)
204204
{
@@ -226,7 +226,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
226226
}
227227

228228
if (!upstream && squash_onto)
229-
write_file(path_squash_onto(), "%s\n", squash_onto);
229+
write_file(path_squash_onto(), "%s\n",
230+
oid_to_hex(squash_onto));
230231

231232
argv_array_pushl(&make_script_args, "", revisions, NULL);
232233
if (restrict_revision)
@@ -267,10 +268,11 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
267268
struct replay_opts opts = REPLAY_OPTS_INIT;
268269
unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
269270
int abbreviate_commands = 0, rebase_cousins = -1, ret = 0;
270-
const char *onto_name = NULL,
271-
*squash_onto = NULL, *head_name = NULL,
272-
*switch_to = NULL, *cmd = NULL;
271+
const char *onto_name = NULL, *head_name = NULL, *switch_to = NULL,
272+
*cmd = NULL;
273273
struct commit *onto = NULL, *upstream = NULL, *restrict_revision = NULL;
274+
struct object_id squash_onto = null_oid;
275+
struct object_id *squash_onto_opt = NULL;
274276
struct string_list commands = STRING_LIST_INIT_DUP;
275277
char *raw_strategies = NULL;
276278
enum {
@@ -311,8 +313,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
311313
{ OPTION_CALLBACK, 0, "restrict-revision", &restrict_revision,
312314
N_("restrict-revision"), N_("restrict revision"),
313315
PARSE_OPT_NONEG, parse_opt_commit, 0 },
314-
OPT_STRING(0, "squash-onto", &squash_onto, N_("squash-onto"),
315-
N_("squash onto")),
316+
{ OPTION_CALLBACK, 0, "squash-onto", &squash_onto, N_("squash-onto"),
317+
N_("squash onto"), PARSE_OPT_NONEG, parse_opt_object_id, 0 },
316318
{ OPTION_CALLBACK, 0, "upstream", &upstream, N_("upstream"),
317319
N_("the upstream commit"), PARSE_OPT_NONEG, parse_opt_commit,
318320
0 },
@@ -349,6 +351,9 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
349351

350352
opts.gpg_sign = xstrdup_or_null(opts.gpg_sign);
351353

354+
if (!is_null_oid(&squash_onto))
355+
squash_onto_opt = &squash_onto;
356+
352357
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
353358
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
354359
flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
@@ -373,7 +378,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
373378
die(_("a base commit must be provided with --upstream or --onto"));
374379

375380
ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto,
376-
onto_name, squash_onto, head_name, restrict_revision,
381+
onto_name, squash_onto_opt, head_name, restrict_revision,
377382
raw_strategies, &commands, autosquash);
378383
break;
379384
case SKIP: {

parse-options-cb.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
129129
return 0;
130130
}
131131

132+
int parse_opt_object_id(const struct option *opt, const char *arg, int unset)
133+
{
134+
struct object_id oid;
135+
struct object_id *target = opt->value;
136+
137+
if (unset) {
138+
*target = null_oid;
139+
return 0;
140+
}
141+
if (!arg)
142+
return -1;
143+
if (get_oid(arg, &oid))
144+
return error(_("malformed object name '%s'"), arg);
145+
*target = oid;
146+
return 0;
147+
}
148+
132149
int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
133150
{
134151
int *target = opt->value;

parse-options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ int parse_opt_abbrev_cb(const struct option *, const char *, int);
264264
int parse_opt_expiry_date_cb(const struct option *, const char *, int);
265265
int parse_opt_color_flag_cb(const struct option *, const char *, int);
266266
int parse_opt_verbosity_cb(const struct option *, const char *, int);
267+
/* value is struct oid_array* */
267268
int parse_opt_object_name(const struct option *, const char *, int);
269+
/* value is struct object_id* */
270+
int parse_opt_object_id(const struct option *, const char *, int);
268271
int parse_opt_commits(const struct option *, const char *, int);
269272
int parse_opt_commit(const struct option *, const char *, int);
270273
int parse_opt_tertiary(const struct option *, const char *, int);

0 commit comments

Comments
 (0)