@matheusbsbs / matheus-bagliano / commits / efcf6cf049
Fork 0

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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 7, 2020 at 10:27 UTC efcf6cf0492c4a78d968c6246698d9aafae61578
1 file changed +17 -20
builtin/rebase.c
+17 -20
@@ -586,15 +586,6 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o
586 return path.buf;
587 }
588
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 -
589 /* Initialize the rebase options from the state directory. */
590 static int read_basic_state(struct rebase_options *opts)
591 {
@@ -602,8 +593,10 @@ static int read_basic_state(struct rebase_options *opts)
593 struct strbuf buf = STRBUF_INIT;
594 struct object_id oid;
595
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))
600 return -1;
601 opts->head_name = starts_with(head_name.buf, "refs/") ?
602 xstrdup(head_name.buf) : NULL;
@@ -619,9 +612,11 @@ static int read_basic_state(struct rebase_options *opts)
612 */
613 strbuf_reset(&buf);
614 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))
617 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))
620 return -1;
621 if (get_oid(buf.buf, &opts->orig_head))
622 return error(_("invalid orig-head: '%s'"), buf.buf);
@@ -641,8 +636,8 @@ static int read_basic_state(struct rebase_options *opts)
636
637 if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) {
638 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))
641 return -1;
642 if (!strcmp(buf.buf, "--rerere-autoupdate"))
643 opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE;
@@ -655,8 +650,8 @@ static int read_basic_state(struct rebase_options *opts)
650
651 if (file_exists(state_dir_path("gpg_sign_opt", opts))) {
652 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))
655 return -1;
656 free(opts->gpg_sign_opt);
657 opts->gpg_sign_opt = xstrdup(buf.buf);
@@ -664,7 +659,8 @@ static int read_basic_state(struct rebase_options *opts)
659
660 if (file_exists(state_dir_path("strategy", opts))) {
661 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))
664 return -1;
665 free(opts->strategy);
666 opts->strategy = xstrdup(buf.buf);
@@ -672,7 +668,8 @@ static int read_basic_state(struct rebase_options *opts)
668
669 if (file_exists(state_dir_path("strategy_opts", opts))) {
670 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))
673 return -1;
674 free(opts->strategy_opts);
675 opts->strategy_opts = xstrdup(buf.buf);
@@ -724,7 +721,7 @@ static int apply_autostash(struct rebase_options *opts)
721 if (!file_exists(path))
722 return 0;
723
727 - if (read_one(path, &autostash))
724 + if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING))
725 return error(_("Could not read '%s'"), path);
726 /* Ensure that the hash is not mistaken for a number */
727 strbuf_addstr(&autostash, "^0");