X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin%2Fcheckout.c;h=44e73b5a4fc57f206c09b4c630d2028bf7475a51;hb=00754b20f931e0e85fe12e59111cf250d51d288b;hp=a7a493cecf08b20f32e4161dd5009fd2c3b97448;hpb=992499d8532c107f0f77163de4376ed2e0fd05a0;p=git.git diff --git a/builtin/checkout.c b/builtin/checkout.c index a7a493cec..44e73b5a4 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -411,7 +411,7 @@ static int merge_working_tree(struct checkout_opts *opts, topts.fn = twoway_merge; topts.dir = xcalloc(1, sizeof(*topts.dir)); topts.dir->flags |= DIR_SHOW_IGNORED; - topts.dir->exclude_per_dir = ".gitignore"; + setup_standard_excludes(topts.dir); tree = parse_tree_indirect(old->commit ? old->commit->object.sha1 : EMPTY_TREE_SHA1_BIN); @@ -540,7 +540,9 @@ static void update_refs_for_switch(struct checkout_opts *opts, else create_branch(old->name, opts->new_branch, new->name, opts->new_branch_force ? 1 : 0, - opts->new_branch_log, opts->track); + opts->new_branch_log, + opts->new_branch_force ? 1 : 0, + opts->track); new->name = opts->new_branch; setup_branch_path(new); } @@ -565,8 +567,12 @@ static void update_refs_for_switch(struct checkout_opts *opts, create_symref("HEAD", new->path, msg.buf); if (!opts->quiet) { if (old->path && !strcmp(new->path, old->path)) { - fprintf(stderr, _("Already on '%s'\n"), - new->name); + if (opts->new_branch_force) + fprintf(stderr, _("Reset branch '%s'\n"), + new->name); + else + fprintf(stderr, _("Already on '%s'\n"), + new->name); } else if (opts->new_branch) { if (opts->branch_exists) fprintf(stderr, _("Switched to and reset branch '%s'\n"), new->name); @@ -593,23 +599,11 @@ static void update_refs_for_switch(struct checkout_opts *opts, report_tracking(new); } -static int add_one_ref_to_rev_list_arg(const char *refname, - const unsigned char *sha1, - int flags, - void *cb_data) -{ - argv_array_push(cb_data, refname); - return 0; -} - -static int clear_commit_marks_from_one_ref(const char *refname, - const unsigned char *sha1, - int flags, - void *cb_data) +static int add_pending_uninteresting_ref(const char *refname, + const unsigned char *sha1, + int flags, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(sha1, 1); - if (commit) - clear_commit_marks(commit, -1); + add_pending_sha1(cb_data, refname, sha1, flags | UNINTERESTING); return 0; } @@ -678,18 +672,21 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs) */ static void orphaned_commit_warning(struct commit *commit) { - struct argv_array args = ARGV_ARRAY_INIT; struct rev_info revs; - - argv_array_push(&args, "(internal)"); - argv_array_push(&args, sha1_to_hex(commit->object.sha1)); - argv_array_push(&args, "--not"); - for_each_ref(add_one_ref_to_rev_list_arg, &args); - argv_array_push(&args, "--"); + struct object *object = &commit->object; + struct object_array refs; init_revisions(&revs, NULL); - if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1) - die(_("internal error: only -- alone should have been left")); + setup_revisions(0, NULL, &revs, NULL); + + object->flags &= ~UNINTERESTING; + add_pending_object(&revs, object, sha1_to_hex(object->sha1)); + + for_each_ref(add_pending_uninteresting_ref, &revs); + + refs = revs.pending; + revs.leak_pending = 1; + if (prepare_revision_walk(&revs)) die(_("internal error in revision walk")); if (!(commit->object.flags & UNINTERESTING)) @@ -697,9 +694,8 @@ static void orphaned_commit_warning(struct commit *commit) else describe_detached_head(_("Previous HEAD position was"), commit); - argv_array_clear(&args); - clear_commit_marks(commit, -1); - for_each_ref(clear_commit_marks_from_one_ref, NULL); + clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS); + free(refs.objects); } static int switch_branches(struct checkout_opts *opts, struct branch_info *new) @@ -875,7 +871,7 @@ static int parse_branchname_arg(int argc, const char **argv, new->name = arg; setup_branch_path(new); - if (check_ref_format(new->path) == CHECK_REF_FORMAT_OK && + if (!check_refname_format(new->path, 0) && resolve_ref(new->path, branch_rev, 1, NULL)) hashcpy(rev, branch_rev); else @@ -1067,7 +1063,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct strbuf buf = STRBUF_INIT; opts.branch_exists = validate_new_branchname(opts.new_branch, &buf, - !!opts.new_branch_force, 0); + !!opts.new_branch_force, + !!opts.new_branch_force); strbuf_release(&buf); }