Skip to content

Commit 3442c3d

Browse files
Denton-Lgitster
authored andcommitted
sequencer: make read_oneliner() accept flags
In a future commit, we will need read_oneliner() to accept flags other than just `skip_if_empty`. Instead of having an argument for each flag, teach read_oneliner() to accept the bitfield `flags` instead. For now, only recognize the `READ_ONELINER_SKIP_IF_EMPTY` flag. More flags will be added in a future commit. The result of this is that parallel topics which introduce invocations of read_oneliner() will still be compatible with this new function signature since, instead of passing 1 or 0 for `skip_if_empty`, they'll be passing 1 or 0 to `flags`, which gives equivalent behavior. Mechanically fix up invocations of read_oneliner() with the following spatch @@ expression a, b; @@ read_oneliner(a, b, - 1 + READ_ONELINER_SKIP_IF_EMPTY ) and manually break up long lines in the result. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b2f6d9 commit 3442c3d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

sequencer.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ static int write_message(const void *buf, size_t len, const char *filename,
419419
return 0;
420420
}
421421

422+
#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0)
423+
422424
/*
423425
* Reads a file that was presumably written by a shell script, i.e. with an
424426
* end-of-line marker that needs to be stripped.
@@ -429,7 +431,7 @@ static int write_message(const void *buf, size_t len, const char *filename,
429431
* Returns 1 if the file was read, 0 if it could not be read or does not exist.
430432
*/
431433
static int read_oneliner(struct strbuf *buf,
432-
const char *path, int skip_if_empty)
434+
const char *path, unsigned flags)
433435
{
434436
int orig_len = buf->len;
435437

@@ -445,7 +447,7 @@ static int read_oneliner(struct strbuf *buf,
445447
buf->buf[buf->len] = '\0';
446448
}
447449

448-
if (skip_if_empty && buf->len == orig_len)
450+
if ((flags & READ_ONELINER_SKIP_IF_EMPTY) && buf->len == orig_len)
449451
return 0;
450452

451453
return 1;
@@ -2485,7 +2487,8 @@ static int read_populate_opts(struct replay_opts *opts)
24852487
struct strbuf buf = STRBUF_INIT;
24862488
int ret = 0;
24872489

2488-
if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) {
2490+
if (read_oneliner(&buf, rebase_path_gpg_sign_opt(),
2491+
READ_ONELINER_SKIP_IF_EMPTY)) {
24892492
if (!starts_with(buf.buf, "-S"))
24902493
strbuf_reset(&buf);
24912494
else {
@@ -2495,7 +2498,8 @@ static int read_populate_opts(struct replay_opts *opts)
24952498
strbuf_reset(&buf);
24962499
}
24972500

2498-
if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) {
2501+
if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(),
2502+
READ_ONELINER_SKIP_IF_EMPTY)) {
24992503
if (!strcmp(buf.buf, "--rerere-autoupdate"))
25002504
opts->allow_rerere_auto = RERERE_AUTOUPDATE;
25012505
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
@@ -2527,7 +2531,8 @@ static int read_populate_opts(struct replay_opts *opts)
25272531
strbuf_reset(&buf);
25282532

25292533
if (read_oneliner(&opts->current_fixups,
2530-
rebase_path_current_fixups(), 1)) {
2534+
rebase_path_current_fixups(),
2535+
READ_ONELINER_SKIP_IF_EMPTY)) {
25312536
const char *p = opts->current_fixups.buf;
25322537
opts->current_fixup_count = 1;
25332538
while ((p = strchr(p, '\n'))) {
@@ -3668,7 +3673,8 @@ static int apply_autostash(struct replay_opts *opts)
36683673
struct child_process child = CHILD_PROCESS_INIT;
36693674
int ret = 0;
36703675

3671-
if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) {
3676+
if (!read_oneliner(&stash_sha1, rebase_path_autostash(),
3677+
READ_ONELINER_SKIP_IF_EMPTY)) {
36723678
strbuf_release(&stash_sha1);
36733679
return 0;
36743680
}
@@ -4292,7 +4298,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
42924298
struct strbuf buf = STRBUF_INIT;
42934299
struct object_id oid;
42944300

4295-
if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
4301+
if (read_oneliner(&buf, rebase_path_stopped_sha(),
4302+
READ_ONELINER_SKIP_IF_EMPTY) &&
42964303
!get_oid_committish(buf.buf, &oid))
42974304
record_in_rewritten(&oid, peek_command(&todo_list, 0));
42984305
strbuf_release(&buf);

0 commit comments

Comments
 (0)