@@ -486,9 +486,9 @@ static void print_current_branch_name(void)
486
486
die (_ ("HEAD (%s) points outside of refs/heads/" ), refname );
487
487
}
488
488
489
- static void reject_rebase_or_bisect_branch (const char * target )
489
+ static void reject_rebase_or_bisect_branch (struct worktree * * worktrees ,
490
+ const char * target )
490
491
{
491
- struct worktree * * worktrees = get_worktrees ();
492
492
int i ;
493
493
494
494
for (i = 0 ; worktrees [i ]; i ++ ) {
@@ -505,20 +505,18 @@ static void reject_rebase_or_bisect_branch(const char *target)
505
505
die (_ ("Branch %s is being bisected at %s" ),
506
506
target , wt -> path );
507
507
}
508
-
509
- free_worktrees (worktrees );
510
508
}
511
509
512
510
/*
513
511
* Update all per-worktree HEADs pointing at the old ref to point the new ref.
514
512
* This will be used when renaming a branch. Returns 0 if successful, non-zero
515
513
* otherwise.
516
514
*/
517
- static int replace_each_worktree_head_symref (const char * oldref , const char * newref ,
515
+ static int replace_each_worktree_head_symref (struct worktree * * worktrees ,
516
+ const char * oldref , const char * newref ,
518
517
const char * logmsg )
519
518
{
520
519
int ret = 0 ;
521
- struct worktree * * worktrees = get_worktrees ();
522
520
int i ;
523
521
524
522
for (i = 0 ; worktrees [i ]; i ++ ) {
@@ -537,7 +535,6 @@ static int replace_each_worktree_head_symref(const char *oldref, const char *new
537
535
worktrees [i ]-> path );
538
536
}
539
537
540
- free_worktrees (worktrees );
541
538
return ret ;
542
539
}
543
540
@@ -548,6 +545,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
548
545
const char * interpreted_oldname = NULL ;
549
546
const char * interpreted_newname = NULL ;
550
547
int recovery = 0 ;
548
+ struct worktree * * worktrees = get_worktrees ();
551
549
552
550
if (strbuf_check_branch_ref (& oldref , oldname )) {
553
551
/*
@@ -576,7 +574,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
576
574
else
577
575
validate_new_branchname (newname , & newref , force );
578
576
579
- reject_rebase_or_bisect_branch (oldref .buf );
577
+ reject_rebase_or_bisect_branch (worktrees , oldref .buf );
580
578
581
579
if (!skip_prefix (oldref .buf , "refs/heads/" , & interpreted_oldname ) ||
582
580
!skip_prefix (newref .buf , "refs/heads/" , & interpreted_newname )) {
@@ -607,7 +605,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
607
605
}
608
606
609
607
if (!copy &&
610
- replace_each_worktree_head_symref (oldref .buf , newref .buf , logmsg .buf ))
608
+ replace_each_worktree_head_symref (worktrees , oldref .buf , newref .buf ,
609
+ logmsg .buf ))
611
610
die (_ ("Branch renamed to %s, but HEAD is not updated!" ), newname );
612
611
613
612
strbuf_release (& logmsg );
@@ -622,6 +621,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
622
621
strbuf_release (& newref );
623
622
strbuf_release (& oldsection );
624
623
strbuf_release (& newsection );
624
+ free_worktrees (worktrees );
625
625
}
626
626
627
627
static GIT_PATH_FUNC (edit_description , "EDIT_DESCRIPTION ")
0 commit comments