diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-07-13 14:02:02 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-07-13 14:02:02 -0700 |
commit | 7783eb2e59684492e75068443e1f77f64fe37cc9 (patch) | |
tree | 28abef68309c3b2cfcb3398955eb3e2d63da5479 /builtin/checkout.c | |
parent | 721f5bb8968ed6a6ec126fe28f679c17a6998e87 (diff) | |
parent | df0b6cfbda88144714541664fb501146d6465a82 (diff) | |
download | git-7783eb2e59684492e75068443e1f77f64fe37cc9.tar.gz |
Merge branch 'nd/multiple-work-trees'
"git checkout [<tree-ish>] <paths>" spent unnecessary cycles
checking if the current branch was checked out elsewhere, when we
know we are not switching the branches ourselves.
* nd/multiple-work-trees:
worktree: new place for "git prune --worktrees"
checkout: don't check worktrees when not necessary
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 9b49f0e413..e227f64995 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1110,7 +1110,6 @@ static int parse_branchname_arg(int argc, const char **argv, { struct tree **source_tree = &opts->source_tree; const char **new_branch = &opts->new_branch; - int force_detach = opts->force_detach; int argcount = 0; unsigned char branch_rev[20]; const char *arg; @@ -1231,17 +1230,6 @@ static int parse_branchname_arg(int argc, const char **argv, else new->path = NULL; /* not an existing branch */ - if (new->path && !force_detach && !*new_branch) { - unsigned char sha1[20]; - int flag; - char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag); - if (head_ref && - (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) && - !opts->ignore_other_worktrees) - check_linked_checkouts(new); - free(head_ref); - } - new->commit = lookup_commit_reference_gently(rev, 1); if (!new->commit) { /* not a commit */ @@ -1321,6 +1309,17 @@ static int checkout_branch(struct checkout_opts *opts, die(_("Cannot switch branch to a non-commit '%s'"), new->name); + if (new->path && !opts->force_detach && !opts->new_branch) { + unsigned char sha1[20]; + int flag; + char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag); + if (head_ref && + (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) && + !opts->ignore_other_worktrees) + check_linked_checkouts(new); + free(head_ref); + } + if (opts->new_worktree) return prepare_linked_checkout(opts, new); |