Skip to content

Commit 468224e

Browse files
René Scharfegitster
authored andcommitted
checkout: use add_pending_{object,sha1} in orphan check
Instead of building a list of textual arguments for setup_revisions, use add_pending_object and add_pending_sha1 to queue the objects directly. This is both faster and simpler. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26c3177 commit 468224e

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

builtin/checkout.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -588,24 +588,11 @@ static void update_refs_for_switch(struct checkout_opts *opts,
588588
report_tracking(new);
589589
}
590590

591-
struct rev_list_args {
592-
int argc;
593-
int alloc;
594-
const char **argv;
595-
};
596-
597-
static void add_one_rev_list_arg(struct rev_list_args *args, const char *s)
598-
{
599-
ALLOC_GROW(args->argv, args->argc + 1, args->alloc);
600-
args->argv[args->argc++] = s;
601-
}
602-
603-
static int add_one_ref_to_rev_list_arg(const char *refname,
604-
const unsigned char *sha1,
605-
int flags,
606-
void *cb_data)
591+
static int add_pending_uninteresting_ref(const char *refname,
592+
const unsigned char *sha1,
593+
int flags, void *cb_data)
607594
{
608-
add_one_rev_list_arg(cb_data, refname);
595+
add_pending_sha1(cb_data, refname, sha1, flags | UNINTERESTING);
609596
return 0;
610597
}
611598

@@ -684,19 +671,17 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
684671
*/
685672
static void orphaned_commit_warning(struct commit *commit)
686673
{
687-
struct rev_list_args args = { 0, 0, NULL };
688674
struct rev_info revs;
689-
690-
add_one_rev_list_arg(&args, "(internal)");
691-
add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1));
692-
add_one_rev_list_arg(&args, "--not");
693-
for_each_ref(add_one_ref_to_rev_list_arg, &args);
694-
add_one_rev_list_arg(&args, "--");
695-
add_one_rev_list_arg(&args, NULL);
675+
struct object *object = &commit->object;
696676

697677
init_revisions(&revs, NULL);
698-
if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
699-
die(_("internal error: only -- alone should have been left"));
678+
setup_revisions(0, NULL, &revs, NULL);
679+
680+
object->flags &= ~UNINTERESTING;
681+
add_pending_object(&revs, object, sha1_to_hex(object->sha1));
682+
683+
for_each_ref(add_pending_uninteresting_ref, &revs);
684+
700685
if (prepare_revision_walk(&revs))
701686
die(_("internal error in revision walk"));
702687
if (!(commit->object.flags & UNINTERESTING))

0 commit comments

Comments
 (0)