@@ -586,24 +586,17 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o
586
586
return path .buf ;
587
587
}
588
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
-
598
589
/* Initialize the rebase options from the state directory. */
599
590
static int read_basic_state (struct rebase_options * opts )
600
591
{
601
592
struct strbuf head_name = STRBUF_INIT ;
602
593
struct strbuf buf = STRBUF_INIT ;
603
594
struct object_id oid ;
604
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 ))
607
600
return -1 ;
608
601
opts -> head_name = starts_with (head_name .buf , "refs/" ) ?
609
602
xstrdup (head_name .buf ) : NULL ;
@@ -619,9 +612,11 @@ static int read_basic_state(struct rebase_options *opts)
619
612
*/
620
613
strbuf_reset (& buf );
621
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 ))
623
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 ))
625
620
return -1 ;
626
621
if (get_oid (buf .buf , & opts -> orig_head ))
627
622
return error (_ ("invalid orig-head: '%s'" ), buf .buf );
@@ -641,8 +636,8 @@ static int read_basic_state(struct rebase_options *opts)
641
636
642
637
if (file_exists (state_dir_path ("allow_rerere_autoupdate" , opts ))) {
643
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 ))
646
641
return -1 ;
647
642
if (!strcmp (buf .buf , "--rerere-autoupdate" ))
648
643
opts -> allow_rerere_autoupdate = RERERE_AUTOUPDATE ;
@@ -655,24 +650,26 @@ static int read_basic_state(struct rebase_options *opts)
655
650
656
651
if (file_exists (state_dir_path ("gpg_sign_opt" , opts ))) {
657
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 ))
660
655
return -1 ;
661
656
free (opts -> gpg_sign_opt );
662
657
opts -> gpg_sign_opt = xstrdup (buf .buf );
663
658
}
664
659
665
660
if (file_exists (state_dir_path ("strategy" , opts ))) {
666
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 ))
668
664
return -1 ;
669
665
free (opts -> strategy );
670
666
opts -> strategy = xstrdup (buf .buf );
671
667
}
672
668
673
669
if (file_exists (state_dir_path ("strategy_opts" , opts ))) {
674
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 ))
676
673
return -1 ;
677
674
free (opts -> strategy_opts );
678
675
opts -> strategy_opts = xstrdup (buf .buf );
@@ -724,7 +721,7 @@ static int apply_autostash(struct rebase_options *opts)
724
721
if (!file_exists (path ))
725
722
return 0 ;
726
723
727
- if (read_one ( path , & autostash ))
724
+ if (! read_oneliner ( & autostash , path , READ_ONELINER_WARN_MISSING ))
728
725
return error (_ ("Could not read '%s'" ), path );
729
726
/* Ensure that the hash is not mistaken for a number */
730
727
strbuf_addstr (& autostash , "^0" );
0 commit comments