checkout: avoid resolving HEAD unnecessarily
When --ignore-other-worktree is specified, we unconditionally skip the check to see if the requested branch is already checked out in a linked worktree. Since we know that we will be skipping that check, there is no need to resolve HEAD in order to detect other conditions under which we may skip the check. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Jul 17, 2015 at 18:59 UTC
c265c533cfbced87d56ad6d3d4ae3d62475c29ce
1 file changed
+3
-3
builtin/checkout.c
+3
-3
@@ -1145,13 +1145,13 @@ static int checkout_branch(struct checkout_opts *opts,
1145
die(_("Cannot switch branch to a non-commit '%s'"),
1146
new->name);
1147
1148
- if (new->path && !opts->force_detach && !opts->new_branch) {
1148
+ if (new->path && !opts->force_detach && !opts->new_branch &&
1149
+ !opts->ignore_other_worktrees) {
1150
unsigned char sha1[20];
1151
int flag;
1152
char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
1153
if (head_ref &&
1153
- (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
1154
- !opts->ignore_other_worktrees)
1154
+ (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
1155
check_linked_checkouts(new);
1156
free(head_ref);
1157
}