]> Kevux Git Server - rit/commitdiff
branch: avoid unnecessary worktrees traversals
authorRubén Justo <rjusto@gmail.com>
Sun, 26 Mar 2023 22:33:40 +0000 (00:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2023 16:40:15 +0000 (09:40 -0700)
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>
builtin/branch.c

index a93b9fc..6a564b2 100644 (file)
@@ -617,7 +617,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
                                interpreted_oldname);
        }
 
-       if (!copy &&
+       if (!copy && (oldref_usage & IS_HEAD) &&
            replace_each_worktree_head_symref(worktrees, oldref.buf, newref.buf,
                                              logmsg.buf))
                die(_("Branch renamed to %s, but HEAD is not updated!"), newname);