@@ -1486,12 +1486,17 @@ static const char *update(struct command *cmd, struct shallow_info *si)
14861486 struct object_id * old_oid = & cmd -> old_oid ;
14871487 struct object_id * new_oid = & cmd -> new_oid ;
14881488 int do_update_worktree = 0 ;
1489- const struct worktree * worktree = is_bare_repository () ? NULL : find_shared_symref ("HEAD" , name );
1489+ struct worktree * * worktrees = get_worktrees ();
1490+ const struct worktree * worktree =
1491+ is_bare_repository () ?
1492+ NULL :
1493+ find_shared_symref (worktrees , "HEAD" , name );
14901494
14911495 /* only refs/... are allowed */
14921496 if (!starts_with (name , "refs/" ) || check_refname_format (name + 5 , 0 )) {
14931497 rp_error ("refusing to create funny ref '%s' remotely" , name );
1494- return "funny refname" ;
1498+ ret = "funny refname" ;
1499+ goto out ;
14951500 }
14961501
14971502 strbuf_addf (& namespaced_name_buf , "%s%s" , get_git_namespace (), name );
@@ -1510,7 +1515,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15101515 rp_error ("refusing to update checked out branch: %s" , name );
15111516 if (deny_current_branch == DENY_UNCONFIGURED )
15121517 refuse_unconfigured_deny ();
1513- return "branch is currently checked out" ;
1518+ ret = "branch is currently checked out" ;
1519+ goto out ;
15141520 case DENY_UPDATE_INSTEAD :
15151521 /* pass -- let other checks intervene first */
15161522 do_update_worktree = 1 ;
@@ -1521,13 +1527,15 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15211527 if (!is_null_oid (new_oid ) && !has_object_file (new_oid )) {
15221528 error ("unpack should have generated %s, "
15231529 "but I can't find it!" , oid_to_hex (new_oid ));
1524- return "bad pack" ;
1530+ ret = "bad pack" ;
1531+ goto out ;
15251532 }
15261533
15271534 if (!is_null_oid (old_oid ) && is_null_oid (new_oid )) {
15281535 if (deny_deletes && starts_with (name , "refs/heads/" )) {
15291536 rp_error ("denying ref deletion for %s" , name );
1530- return "deletion prohibited" ;
1537+ ret = "deletion prohibited" ;
1538+ goto out ;
15311539 }
15321540
15331541 if (worktree || (head_name && !strcmp (namespaced_name , head_name ))) {
@@ -1543,9 +1551,11 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15431551 if (deny_delete_current == DENY_UNCONFIGURED )
15441552 refuse_unconfigured_deny_delete_current ();
15451553 rp_error ("refusing to delete the current branch: %s" , name );
1546- return "deletion of the current branch prohibited" ;
1554+ ret = "deletion of the current branch prohibited" ;
1555+ goto out ;
15471556 default :
1548- return "Invalid denyDeleteCurrent setting" ;
1557+ ret = "Invalid denyDeleteCurrent setting" ;
1558+ goto out ;
15491559 }
15501560 }
15511561 }
@@ -1563,25 +1573,30 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15631573 old_object -> type != OBJ_COMMIT ||
15641574 new_object -> type != OBJ_COMMIT ) {
15651575 error ("bad sha1 objects for %s" , name );
1566- return "bad ref" ;
1576+ ret = "bad ref" ;
1577+ goto out ;
15671578 }
15681579 old_commit = (struct commit * )old_object ;
15691580 new_commit = (struct commit * )new_object ;
15701581 if (!in_merge_bases (old_commit , new_commit )) {
15711582 rp_error ("denying non-fast-forward %s"
15721583 " (you should pull first)" , name );
1573- return "non-fast-forward" ;
1584+ ret = "non-fast-forward" ;
1585+ goto out ;
15741586 }
15751587 }
15761588 if (run_update_hook (cmd )) {
15771589 rp_error ("hook declined to update %s" , name );
1578- return "hook declined" ;
1590+ ret = "hook declined" ;
1591+ goto out ;
15791592 }
15801593
15811594 if (do_update_worktree ) {
1582- ret = update_worktree (new_oid -> hash , find_shared_symref ("HEAD" , name ));
1595+ ret = update_worktree (new_oid -> hash ,
1596+ find_shared_symref (worktrees , "HEAD" ,
1597+ name ));
15831598 if (ret )
1584- return ret ;
1599+ goto out ;
15851600 }
15861601
15871602 if (is_null_oid (new_oid )) {
@@ -1600,32 +1615,36 @@ static const char *update(struct command *cmd, struct shallow_info *si)
16001615 old_oid ,
16011616 0 , "push" , & err )) {
16021617 rp_error ("%s" , err .buf );
1603- strbuf_release (& err );
1604- return "failed to delete" ;
1618+ ret = "failed to delete" ;
1619+ } else {
1620+ ret = NULL ; /* good */
16051621 }
16061622 strbuf_release (& err );
1607- return NULL ; /* good */
16081623 }
16091624 else {
16101625 struct strbuf err = STRBUF_INIT ;
16111626 if (shallow_update && si -> shallow_ref [cmd -> index ] &&
1612- update_shallow_ref (cmd , si ))
1613- return "shallow error" ;
1627+ update_shallow_ref (cmd , si )) {
1628+ ret = "shallow error" ;
1629+ goto out ;
1630+ }
16141631
16151632 if (ref_transaction_update (transaction ,
16161633 namespaced_name ,
16171634 new_oid , old_oid ,
16181635 0 , "push" ,
16191636 & err )) {
16201637 rp_error ("%s" , err .buf );
1621- strbuf_release ( & err ) ;
1622-
1623- return "failed to update ref" ;
1638+ ret = "failed to update ref" ;
1639+ } else {
1640+ ret = NULL ; /* good */
16241641 }
16251642 strbuf_release (& err );
1626-
1627- return NULL ; /* good */
16281643 }
1644+
1645+ out :
1646+ free_worktrees (worktrees );
1647+ return ret ;
16291648}
16301649
16311650static void run_update_post_hook (struct command * commands )
0 commit comments