branch: avoid unnecessary worktrees traversals

When we rename a branch ref, we need to update any worktree that have its HEAD pointing to the branch ref being renamed, so to make it use the new ref name. If we know in advance that we're renaming a branch that is not currently checked out in any worktree, we can skip this step entirely. Let's do it so. Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rubén Justo committed Mar 27, 2023 at 00:33 UTC 3521c6321350cf1432f4772efa09db8bec0aa331
1 file changed +1 -1
builtin/branch.c
+1 -1
@@ -617,7 +617,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
617 interpreted_oldname);
618 }
619
620 - if (!copy &&
620 + if (!copy && (oldref_usage & IS_HEAD) &&
621 replace_each_worktree_head_symref(worktrees, oldref.buf, newref.buf,
622 logmsg.buf))
623 die(_("Branch renamed to %s, but HEAD is not updated!"), newname);