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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Apr 17, 2019 at 15:30 UTC
338985317eb84007f0d08979e751cbf32a375a52
3 files changed
+33
-8
builtin/rebase.c
+13
-8
@@ -198,7 +198,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
198
static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
199
const char *switch_to, struct commit *upstream,
200
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,
202
struct commit *restrict_revision, char *raw_strategies,
203
struct string_list *commands, unsigned autosquash)
204
{
@@ -226,7 +226,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
226
}
227
228
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));
231
232
argv_array_pushl(&make_script_args, "", revisions, NULL);
233
if (restrict_revision)
@@ -267,10 +268,11 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
268
struct replay_opts opts = REPLAY_OPTS_INIT;
269
unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
270
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;
273
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;
276
struct string_list commands = STRING_LIST_INIT_DUP;
277
char *raw_strategies = NULL;
278
enum {
@@ -311,8 +313,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
313
{ OPTION_CALLBACK, 0, "restrict-revision", &restrict_revision,
314
N_("restrict-revision"), N_("restrict revision"),
315
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 },
318
{ OPTION_CALLBACK, 0, "upstream", &upstream, N_("upstream"),
319
N_("the upstream commit"), PARSE_OPT_NONEG, parse_opt_commit,
320
0 },
@@ -349,6 +351,9 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
351
352
opts.gpg_sign = xstrdup_or_null(opts.gpg_sign);
353
354
+ if (!is_null_oid(&squash_onto))
355
+ squash_onto_opt = &squash_onto;
356
+
357
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
358
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
359
flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
@@ -373,7 +378,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
378
die(_("a base commit must be provided with --upstream or --onto"));
379
380
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,
382
raw_strategies, &commands, autosquash);
383
break;
384
case SKIP: {
parse-options-cb.c
+17
@@ -129,6 +129,23 @@ int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
129
return 0;
130
}
131
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
+
149
int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
150
{
151
int *target = opt->value;
parse-options.h
+3
@@ -264,7 +264,10 @@ int parse_opt_abbrev_cb(const struct option *, const char *, int);
264
int parse_opt_expiry_date_cb(const struct option *, const char *, int);
265
int parse_opt_color_flag_cb(const struct option *, const char *, int);
266
int parse_opt_verbosity_cb(const struct option *, const char *, int);
267
+/* value is struct oid_array* */
268
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);
271
int parse_opt_commits(const struct option *, const char *, int);
272
int parse_opt_commit(const struct option *, const char *, int);
273
int parse_opt_tertiary(const struct option *, const char *, int);