@@ -967,41 +967,41 @@ static void show_bisect_in_progress(struct wt_status *s,
967967/*
968968 * Extract branch information from rebase/bisect
969969 */
970- static void read_and_strip_branch (struct strbuf * sb ,
971- const char * * branch ,
972- const char * path )
970+ static char * read_and_strip_branch (const char * path )
973971{
972+ struct strbuf sb = STRBUF_INIT ;
974973 unsigned char sha1 [20 ];
975974
976- strbuf_reset (sb );
977- if (strbuf_read_file (sb , git_path ("%s" , path ), 0 ) <= 0 )
978- return ;
975+ if (strbuf_read_file (& sb , git_path ("%s" , path ), 0 ) <= 0 )
976+ goto got_nothing ;
979977
980- while (sb -> len && sb -> buf [sb -> len - 1 ] == '\n' )
981- strbuf_setlen (sb , sb -> len - 1 );
982- if (!sb -> len )
983- return ;
984- if (!prefixcmp (sb -> buf , "refs/heads/" ))
985- * branch = sb -> buf + strlen ("refs/heads/" );
986- else if (!prefixcmp (sb -> buf , "refs/" ))
987- * branch = sb -> buf ;
988- else if (!get_sha1_hex (sb -> buf , sha1 )) {
978+ while (& sb . len && sb . buf [sb . len - 1 ] == '\n' )
979+ strbuf_setlen (& sb , sb . len - 1 );
980+ if (!sb . len )
981+ goto got_nothing ;
982+ if (!prefixcmp (sb . buf , "refs/heads/" ))
983+ strbuf_remove ( & sb , 0 , strlen ("refs/heads/" ) );
984+ else if (!prefixcmp (sb . buf , "refs/" ))
985+ ;
986+ else if (!get_sha1_hex (sb . buf , sha1 )) {
989987 const char * abbrev ;
990988 abbrev = find_unique_abbrev (sha1 , DEFAULT_ABBREV );
991- strbuf_reset (sb );
992- strbuf_addstr (sb , abbrev );
993- * branch = sb -> buf ;
994- } else if (!strcmp (sb -> buf , "detached HEAD" )) /* rebase */
995- ;
989+ strbuf_reset (& sb );
990+ strbuf_addstr (& sb , abbrev );
991+ } else if (!strcmp (sb .buf , "detached HEAD" )) /* rebase */
992+ goto got_nothing ;
996993 else /* bisect */
997- * branch = sb -> buf ;
994+ ;
995+ return strbuf_detach (& sb , NULL );
996+
997+ got_nothing :
998+ strbuf_release (& sb );
999+ return NULL ;
9981000}
9991001
10001002static void wt_status_print_state (struct wt_status * s )
10011003{
10021004 const char * state_color = color (WT_STATUS_HEADER , s );
1003- struct strbuf branch = STRBUF_INIT ;
1004- struct strbuf onto = STRBUF_INIT ;
10051005 struct wt_status_state state ;
10061006 struct stat st ;
10071007
@@ -1016,27 +1016,22 @@ static void wt_status_print_state(struct wt_status *s)
10161016 state .am_empty_patch = 1 ;
10171017 } else {
10181018 state .rebase_in_progress = 1 ;
1019- read_and_strip_branch (& branch , & state .branch ,
1020- "rebase-apply/head-name" );
1021- read_and_strip_branch (& onto , & state .onto ,
1022- "rebase-apply/onto" );
1019+ state .branch = read_and_strip_branch ("rebase-apply/head-name" );
1020+ state .onto = read_and_strip_branch ("rebase-apply/onto" );
10231021 }
10241022 } else if (!stat (git_path ("rebase-merge" ), & st )) {
10251023 if (!stat (git_path ("rebase-merge/interactive" ), & st ))
10261024 state .rebase_interactive_in_progress = 1 ;
10271025 else
10281026 state .rebase_in_progress = 1 ;
1029- read_and_strip_branch (& branch , & state .branch ,
1030- "rebase-merge/head-name" );
1031- read_and_strip_branch (& onto , & state .onto ,
1032- "rebase-merge/onto" );
1027+ state .branch = read_and_strip_branch ("rebase-merge/head-name" );
1028+ state .onto = read_and_strip_branch ("rebase-merge/onto" );
10331029 } else if (!stat (git_path ("CHERRY_PICK_HEAD" ), & st )) {
10341030 state .cherry_pick_in_progress = 1 ;
10351031 }
10361032 if (!stat (git_path ("BISECT_LOG" ), & st )) {
10371033 state .bisect_in_progress = 1 ;
1038- read_and_strip_branch (& branch , & state .branch ,
1039- "BISECT_START" );
1034+ state .branch = read_and_strip_branch ("BISECT_START" );
10401035 }
10411036
10421037 if (state .merge_in_progress )
@@ -1049,8 +1044,8 @@ static void wt_status_print_state(struct wt_status *s)
10491044 show_cherry_pick_in_progress (s , & state , state_color );
10501045 if (state .bisect_in_progress )
10511046 show_bisect_in_progress (s , & state , state_color );
1052- strbuf_release ( & branch );
1053- strbuf_release ( & onto );
1047+ free ( state . branch );
1048+ free ( state . onto );
10541049}
10551050
10561051void wt_status_print (struct wt_status * s )
0 commit comments