@@ -1648,7 +1648,7 @@ static char *get_branch(const struct worktree *wt, const char *path)
16481648 struct object_id oid ;
16491649 const char * branch_name ;
16501650
1651- if (strbuf_read_file (& sb , worktree_git_path (the_repository , wt , "%s" , path ), 0 ) <= 0 )
1651+ if (strbuf_read_file (& sb , worktree_git_path (wt , "%s" , path ), 0 ) <= 0 )
16521652 goto got_nothing ;
16531653
16541654 while (sb .len && sb .buf [sb .len - 1 ] == '\n' )
@@ -1747,18 +1747,21 @@ int wt_status_check_rebase(const struct worktree *wt,
17471747{
17481748 struct stat st ;
17491749
1750- if (!stat (worktree_git_path (the_repository , wt , "rebase-apply" ), & st )) {
1751- if (!stat (worktree_git_path (the_repository , wt , "rebase-apply/applying" ), & st )) {
1750+ if (!wt )
1751+ BUG ("wt_status_check_rebase() called with NULL worktree" );
1752+
1753+ if (!stat (worktree_git_path (wt , "rebase-apply" ), & st )) {
1754+ if (!stat (worktree_git_path (wt , "rebase-apply/applying" ), & st )) {
17521755 state -> am_in_progress = 1 ;
1753- if (!stat (worktree_git_path (the_repository , wt , "rebase-apply/patch" ), & st ) && !st .st_size )
1756+ if (!stat (worktree_git_path (wt , "rebase-apply/patch" ), & st ) && !st .st_size )
17541757 state -> am_empty_patch = 1 ;
17551758 } else {
17561759 state -> rebase_in_progress = 1 ;
17571760 state -> branch = get_branch (wt , "rebase-apply/head-name" );
17581761 state -> onto = get_branch (wt , "rebase-apply/onto" );
17591762 }
1760- } else if (!stat (worktree_git_path (the_repository , wt , "rebase-merge" ), & st )) {
1761- if (!stat (worktree_git_path (the_repository , wt , "rebase-merge/interactive" ), & st ))
1763+ } else if (!stat (worktree_git_path (wt , "rebase-merge" ), & st )) {
1764+ if (!stat (worktree_git_path (wt , "rebase-merge/interactive" ), & st ))
17621765 state -> rebase_interactive_in_progress = 1 ;
17631766 else
17641767 state -> rebase_in_progress = 1 ;
@@ -1774,7 +1777,10 @@ int wt_status_check_bisect(const struct worktree *wt,
17741777{
17751778 struct stat st ;
17761779
1777- if (!stat (worktree_git_path (the_repository , wt , "BISECT_LOG" ), & st )) {
1780+ if (!wt )
1781+ BUG ("wt_status_check_bisect() called with NULL worktree" );
1782+
1783+ if (!stat (worktree_git_path (wt , "BISECT_LOG" ), & st )) {
17781784 state -> bisect_in_progress = 1 ;
17791785 state -> bisecting_from = get_branch (wt , "BISECT_START" );
17801786 return 1 ;
@@ -1821,18 +1827,19 @@ void wt_status_get_state(struct repository *r,
18211827 struct stat st ;
18221828 struct object_id oid ;
18231829 enum replay_action action ;
1830+ struct worktree * wt = get_worktree_from_repository (r );
18241831
18251832 if (!stat (git_path_merge_head (r ), & st )) {
1826- wt_status_check_rebase (NULL , state );
1833+ wt_status_check_rebase (wt , state );
18271834 state -> merge_in_progress = 1 ;
1828- } else if (wt_status_check_rebase (NULL , state )) {
1835+ } else if (wt_status_check_rebase (wt , state )) {
18291836 ; /* all set */
18301837 } else if (refs_ref_exists (get_main_ref_store (r ), "CHERRY_PICK_HEAD" ) &&
18311838 !repo_get_oid (r , "CHERRY_PICK_HEAD" , & oid )) {
18321839 state -> cherry_pick_in_progress = 1 ;
18331840 oidcpy (& state -> cherry_pick_head_oid , & oid );
18341841 }
1835- wt_status_check_bisect (NULL , state );
1842+ wt_status_check_bisect (wt , state );
18361843 if (refs_ref_exists (get_main_ref_store (r ), "REVERT_HEAD" ) &&
18371844 !repo_get_oid (r , "REVERT_HEAD" , & oid )) {
18381845 state -> revert_in_progress = 1 ;
@@ -1850,6 +1857,8 @@ void wt_status_get_state(struct repository *r,
18501857 if (get_detached_from )
18511858 wt_status_get_detached_from (r , state );
18521859 wt_status_check_sparse_checkout (r , state );
1860+
1861+ free_worktree (wt );
18531862}
18541863
18551864static void wt_longstatus_print_state (struct wt_status * s )
0 commit comments