diff options
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 4eaedff0c4..04df4d786e 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -19,6 +19,7 @@ #include "ll-merge.h" #include "resolve-undo.h" #include "submodule.h" +#include "argv-array.h" static const char * const checkout_usage[] = { "git checkout [options] <branch>", @@ -588,24 +589,12 @@ static void update_refs_for_switch(struct checkout_opts *opts, report_tracking(new); } -struct rev_list_args { - int argc; - int alloc; - const char **argv; -}; - -static void add_one_rev_list_arg(struct rev_list_args *args, const char *s) -{ - ALLOC_GROW(args->argv, args->argc + 1, args->alloc); - args->argv[args->argc++] = s; -} - static int add_one_ref_to_rev_list_arg(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { - add_one_rev_list_arg(cb_data, refname); + argv_array_push(cb_data, refname); return 0; } @@ -685,15 +674,14 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs) */ static void orphaned_commit_warning(struct commit *commit) { - struct rev_list_args args = { 0, 0, NULL }; + struct argv_array args = ARGV_ARRAY_INIT; struct rev_info revs; - add_one_rev_list_arg(&args, "(internal)"); - add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1)); - add_one_rev_list_arg(&args, "--not"); + 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); - add_one_rev_list_arg(&args, "--"); - add_one_rev_list_arg(&args, NULL); + argv_array_push(&args, "--"); init_revisions(&revs, NULL); if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1) @@ -705,6 +693,7 @@ 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); } @@ -882,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 @@ -1072,15 +1061,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) if (opts.new_branch) { struct strbuf buf = STRBUF_INIT; - if (strbuf_check_branch_ref(&buf, opts.new_branch)) - die(_("git checkout: we do not like '%s' as a branch name."), - opts.new_branch); - if (ref_exists(buf.buf)) { - opts.branch_exists = 1; - if (!opts.new_branch_force) - die(_("git checkout: branch %s already exists"), - opts.new_branch); - } + + opts.branch_exists = validate_new_branchname(opts.new_branch, &buf, + !!opts.new_branch_force, 0); + strbuf_release(&buf); } |