checkout: use argv_array API
We were using a similar ad-hoc rev_list_args structure, but this saves some code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8a534b6124
commit
7bf0b01750
@ -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;
|
||||
}
|
||||
|
||||
@ -684,15 +673,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)
|
||||
@ -704,6 +692,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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user