rebase -i: update functions to use a flags parameter
Update functions used in the rebase--helper so that they take a generic 'flags' parameter instead of a growing list of options. Signed-off-by: Liam Beguin <liambeguin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Liam Beguin committed
Dec 5, 2017 at 12:52 UTC
313a48eaca58ecd170bef9e6a5a55001c7511f08
3 files changed
+17
-13
builtin/rebase--helper.c
+7
-6
@@ -12,7 +12,7 @@ static const char * const builtin_rebase_helper_usage[] = {
12
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
13
{
14
struct replay_opts opts = REPLAY_OPTS_INIT;
15
- int keep_empty = 0;
15
+ unsigned flags = 0, keep_empty = 0;
16
enum {
17
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
18
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
@@ -48,16 +48,17 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
48
argc = parse_options(argc, argv, NULL, options,
49
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
50
51
+ flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
52
+ flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
53
+
54
if (command == CONTINUE && argc == 1)
55
return !!sequencer_continue(&opts);
56
if (command == ABORT && argc == 1)
57
return !!sequencer_remove_state(&opts);
58
if (command == MAKE_SCRIPT && argc > 1)
56
- return !!sequencer_make_script(keep_empty, stdout, argc, argv);
57
- if (command == SHORTEN_OIDS && argc == 1)
58
- return !!transform_todos(1);
59
- if (command == EXPAND_OIDS && argc == 1)
60
- return !!transform_todos(0);
59
+ return !!sequencer_make_script(stdout, argc, argv, flags);
60
+ if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
61
+ return !!transform_todos(flags);
62
if (command == CHECK_TODO_LIST && argc == 1)
63
return !!check_todo_list();
64
if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c
+5
-4
@@ -2444,14 +2444,15 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
2444
strbuf_release(&sob);
2445
}
2446
2447
-int sequencer_make_script(int keep_empty, FILE *out,
2448
- int argc, const char **argv)
2447
+int sequencer_make_script(FILE *out, int argc, const char **argv,
2448
+ unsigned flags)
2449
{
2450
char *format = NULL;
2451
struct pretty_print_context pp = {0};
2452
struct strbuf buf = STRBUF_INIT;
2453
struct rev_info revs;
2454
struct commit *commit;
2455
+ int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
2456
2457
init_revisions(&revs, NULL);
2458
revs.verbose_header = 1;
@@ -2494,7 +2495,7 @@ int sequencer_make_script(int keep_empty, FILE *out,
2495
}
2496
2497
2497
-int transform_todos(int shorten_ids)
2498
+int transform_todos(unsigned flags)
2499
{
2500
const char *todo_file = rebase_path_todo();
2501
struct todo_list todo_list = TODO_LIST_INIT;
@@ -2522,7 +2523,7 @@ int transform_todos(int shorten_ids)
2523
2524
/* add commit id */
2525
if (item->commit) {
2525
- const char *oid = shorten_ids ?
2526
+ const char *oid = flags & TODO_LIST_SHORTEN_IDS ?
2527
short_commit_name(item->commit) :
2528
oid_to_hex(&item->commit->object.oid);
2529
sequencer.h
+5
-3
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
45
int sequencer_rollback(struct replay_opts *opts);
46
int sequencer_remove_state(struct replay_opts *opts);
47
48
-int sequencer_make_script(int keep_empty, FILE *out,
49
- int argc, const char **argv);
48
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
49
+#define TODO_LIST_SHORTEN_IDS (1U << 1)
50
+int sequencer_make_script(FILE *out, int argc, const char **argv,
51
+ unsigned flags);
52
51
-int transform_todos(int shorten_ids);
53
+int transform_todos(unsigned flags);
54
int check_todo_list(void);
55
int skip_unnecessary_picks(void);
56
int rearrange_squash(void);