Skip to content

Commit 313a48e

Browse files
liambeguingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d80fc29 commit 313a48e

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

builtin/rebase--helper.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char * const builtin_rebase_helper_usage[] = {
1212
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
1313
{
1414
struct replay_opts opts = REPLAY_OPTS_INIT;
15-
int keep_empty = 0;
15+
unsigned flags = 0, keep_empty = 0;
1616
enum {
1717
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
1818
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
@@ -48,16 +48,17 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
4848
argc = parse_options(argc, argv, NULL, options,
4949
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
5050

51+
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
52+
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
53+
5154
if (command == CONTINUE && argc == 1)
5255
return !!sequencer_continue(&opts);
5356
if (command == ABORT && argc == 1)
5457
return !!sequencer_remove_state(&opts);
5558
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);
6162
if (command == CHECK_TODO_LIST && argc == 1)
6263
return !!check_todo_list();
6364
if (command == SKIP_UNNECESSARY_PICKS && argc == 1)

sequencer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,14 +2444,15 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
24442444
strbuf_release(&sob);
24452445
}
24462446

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)
24492449
{
24502450
char *format = NULL;
24512451
struct pretty_print_context pp = {0};
24522452
struct strbuf buf = STRBUF_INIT;
24532453
struct rev_info revs;
24542454
struct commit *commit;
2455+
int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
24552456

24562457
init_revisions(&revs, NULL);
24572458
revs.verbose_header = 1;
@@ -2494,7 +2495,7 @@ int sequencer_make_script(int keep_empty, FILE *out,
24942495
}
24952496

24962497

2497-
int transform_todos(int shorten_ids)
2498+
int transform_todos(unsigned flags)
24982499
{
24992500
const char *todo_file = rebase_path_todo();
25002501
struct todo_list todo_list = TODO_LIST_INIT;
@@ -2522,7 +2523,7 @@ int transform_todos(int shorten_ids)
25222523

25232524
/* add commit id */
25242525
if (item->commit) {
2525-
const char *oid = shorten_ids ?
2526+
const char *oid = flags & TODO_LIST_SHORTEN_IDS ?
25262527
short_commit_name(item->commit) :
25272528
oid_to_hex(&item->commit->object.oid);
25282529

sequencer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
4545
int sequencer_rollback(struct replay_opts *opts);
4646
int sequencer_remove_state(struct replay_opts *opts);
4747

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);
5052

51-
int transform_todos(int shorten_ids);
53+
int transform_todos(unsigned flags);
5254
int check_todo_list(void);
5355
int skip_unnecessary_picks(void);
5456
int rearrange_squash(void);

0 commit comments

Comments
 (0)