Skip to content

Commit efcf6cf

Browse files
Denton-Lgitster
authored andcommitted
rebase: use read_oneliner()
Since in sequencer.c, read_one() basically duplicates the functionality of read_oneliner(), reduce code duplication by replacing read_one() with read_oneliner(). This was done with the following Coccinelle script @@ expression a, b; @@ - read_one(a, b) + !read_oneliner(b, a, READ_ONELINER_WARN_MISSING) and long lines were manually broken up. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c20de8b commit efcf6cf

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

builtin/rebase.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -586,24 +586,17 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o
586586
return path.buf;
587587
}
588588

589-
/* Read one file, then strip line endings */
590-
static int read_one(const char *path, struct strbuf *buf)
591-
{
592-
if (strbuf_read_file(buf, path, 0) < 0)
593-
return error_errno(_("could not read '%s'"), path);
594-
strbuf_trim_trailing_newline(buf);
595-
return 0;
596-
}
597-
598589
/* Initialize the rebase options from the state directory. */
599590
static int read_basic_state(struct rebase_options *opts)
600591
{
601592
struct strbuf head_name = STRBUF_INIT;
602593
struct strbuf buf = STRBUF_INIT;
603594
struct object_id oid;
604595

605-
if (read_one(state_dir_path("head-name", opts), &head_name) ||
606-
read_one(state_dir_path("onto", opts), &buf))
596+
if (!read_oneliner(&head_name, state_dir_path("head-name", opts),
597+
READ_ONELINER_WARN_MISSING) ||
598+
!read_oneliner(&buf, state_dir_path("onto", opts),
599+
READ_ONELINER_WARN_MISSING))
607600
return -1;
608601
opts->head_name = starts_with(head_name.buf, "refs/") ?
609602
xstrdup(head_name.buf) : NULL;
@@ -619,9 +612,11 @@ static int read_basic_state(struct rebase_options *opts)
619612
*/
620613
strbuf_reset(&buf);
621614
if (file_exists(state_dir_path("orig-head", opts))) {
622-
if (read_one(state_dir_path("orig-head", opts), &buf))
615+
if (!read_oneliner(&buf, state_dir_path("orig-head", opts),
616+
READ_ONELINER_WARN_MISSING))
623617
return -1;
624-
} else if (read_one(state_dir_path("head", opts), &buf))
618+
} else if (!read_oneliner(&buf, state_dir_path("head", opts),
619+
READ_ONELINER_WARN_MISSING))
625620
return -1;
626621
if (get_oid(buf.buf, &opts->orig_head))
627622
return error(_("invalid orig-head: '%s'"), buf.buf);
@@ -641,8 +636,8 @@ static int read_basic_state(struct rebase_options *opts)
641636

642637
if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) {
643638
strbuf_reset(&buf);
644-
if (read_one(state_dir_path("allow_rerere_autoupdate", opts),
645-
&buf))
639+
if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts),
640+
READ_ONELINER_WARN_MISSING))
646641
return -1;
647642
if (!strcmp(buf.buf, "--rerere-autoupdate"))
648643
opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE;
@@ -655,24 +650,26 @@ static int read_basic_state(struct rebase_options *opts)
655650

656651
if (file_exists(state_dir_path("gpg_sign_opt", opts))) {
657652
strbuf_reset(&buf);
658-
if (read_one(state_dir_path("gpg_sign_opt", opts),
659-
&buf))
653+
if (!read_oneliner(&buf, state_dir_path("gpg_sign_opt", opts),
654+
READ_ONELINER_WARN_MISSING))
660655
return -1;
661656
free(opts->gpg_sign_opt);
662657
opts->gpg_sign_opt = xstrdup(buf.buf);
663658
}
664659

665660
if (file_exists(state_dir_path("strategy", opts))) {
666661
strbuf_reset(&buf);
667-
if (read_one(state_dir_path("strategy", opts), &buf))
662+
if (!read_oneliner(&buf, state_dir_path("strategy", opts),
663+
READ_ONELINER_WARN_MISSING))
668664
return -1;
669665
free(opts->strategy);
670666
opts->strategy = xstrdup(buf.buf);
671667
}
672668

673669
if (file_exists(state_dir_path("strategy_opts", opts))) {
674670
strbuf_reset(&buf);
675-
if (read_one(state_dir_path("strategy_opts", opts), &buf))
671+
if (!read_oneliner(&buf, state_dir_path("strategy_opts", opts),
672+
READ_ONELINER_WARN_MISSING))
676673
return -1;
677674
free(opts->strategy_opts);
678675
opts->strategy_opts = xstrdup(buf.buf);
@@ -724,7 +721,7 @@ static int apply_autostash(struct rebase_options *opts)
724721
if (!file_exists(path))
725722
return 0;
726723

727-
if (read_one(path, &autostash))
724+
if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING))
728725
return error(_("Could not read '%s'"), path);
729726
/* Ensure that the hash is not mistaken for a number */
730727
strbuf_addstr(&autostash, "^0");

0 commit comments

Comments
 (0)