From 468224e580aeb55bd85b37b86f32baada3d17f1e Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 1 Oct 2011 17:51:39 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/checkout.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index 28cdc51b85..a76899d737 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -588,24 +588,11 @@ 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) +static int add_pending_uninteresting_ref(const char *refname, + const unsigned char *sha1, + int flags, void *cb_data) { - add_one_rev_list_arg(cb_data, refname); + add_pending_sha1(cb_data, refname, sha1, flags | UNINTERESTING); return 0; } @@ -684,19 +671,17 @@ 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 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"); - for_each_ref(add_one_ref_to_rev_list_arg, &args); - add_one_rev_list_arg(&args, "--"); - add_one_rev_list_arg(&args, NULL); + struct object *object = &commit->object; 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); + if (prepare_revision_walk(&revs)) die(_("internal error in revision walk")); if (!(commit->object.flags & UNINTERESTING)) -- cgit v1.2.3 From 1062141928aaa1d272be8ce007d371168e8daef6 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 1 Oct 2011 18:09:36 +0200 Subject: checkout: use leak_pending flag Instead of going through all the references again when we clear the commit marks, do it like bisect and bundle and gain ownership of the list of pending objects which we constructed from those references. We simply copy the struct object_array that points to the list, set the flag leak_pending and then prepare_revision_walk won't destroy it and it's ours. We use it to clear the marks and free it at the end. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/checkout.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index a76899d737..2e8402fe04 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -596,17 +596,6 @@ static int add_pending_uninteresting_ref(const char *refname, return 0; } -static int clear_commit_marks_from_one_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); - return 0; -} - static void describe_one_orphan(struct strbuf *sb, struct commit *commit) { parse_commit(commit); @@ -673,6 +662,8 @@ static void orphaned_commit_warning(struct commit *commit) { struct rev_info revs; struct object *object = &commit->object; + struct object_array refs; + unsigned int i; init_revisions(&revs, NULL); setup_revisions(0, NULL, &revs, NULL); @@ -682,6 +673,9 @@ static void orphaned_commit_warning(struct commit *commit) 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)) @@ -689,8 +683,13 @@ static void orphaned_commit_warning(struct commit *commit) else describe_detached_head(_("Previous HEAD position was"), commit); - clear_commit_marks(commit, -1); - for_each_ref(clear_commit_marks_from_one_ref, NULL); + for (i = 0; i < refs.nr; i++) { + struct object *o = refs.objects[i].item; + struct commit *c = lookup_commit_reference_gently(o->sha1, 1); + if (c) + clear_commit_marks(c, ALL_REV_FLAGS); + } + free(refs.objects); } static int switch_branches(struct checkout_opts *opts, struct branch_info *new) -- cgit v1.2.3 From 86a0a408b900eecc9d0d4a1eb8ae223181e96679 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 1 Oct 2011 18:16:08 +0200 Subject: commit: factor out clear_commit_marks_for_object_array Factor out the code to clear the commit marks for a whole struct object_array from builtin/checkout.c into its own exported function clear_commit_marks_for_object_array and use it in bisect and bundle as well. It handles tags and commits and ignores objects of any other type. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- bisect.c | 7 ++----- builtin/checkout.c | 8 +------- bundle.c | 3 +-- commit.c | 14 ++++++++++++++ commit.h | 1 + 5 files changed, 19 insertions(+), 14 deletions(-) (limited to 'builtin/checkout.c') diff --git a/bisect.c b/bisect.c index 63cf166a6a..54674fc248 100644 --- a/bisect.c +++ b/bisect.c @@ -818,7 +818,7 @@ static int check_ancestors(const char *prefix) { struct rev_info revs; struct object_array pending_copy; - int i, res; + int res; bisect_rev_setup(&revs, prefix, "^%s", "%s", 0); @@ -835,10 +835,7 @@ static int check_ancestors(const char *prefix) res = (revs.commits != NULL); /* Clean up objects used, as they will be reused. */ - for (i = 0; i < pending_copy.nr; i++) { - struct object *o = pending_copy.objects[i].item; - clear_commit_marks((struct commit *)o, ALL_REV_FLAGS); - } + clear_commit_marks_for_object_array(&pending_copy, ALL_REV_FLAGS); free(pending_copy.objects); return res; diff --git a/builtin/checkout.c b/builtin/checkout.c index 2e8402fe04..cefa51d515 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -663,7 +663,6 @@ static void orphaned_commit_warning(struct commit *commit) struct rev_info revs; struct object *object = &commit->object; struct object_array refs; - unsigned int i; init_revisions(&revs, NULL); setup_revisions(0, NULL, &revs, NULL); @@ -683,12 +682,7 @@ static void orphaned_commit_warning(struct commit *commit) else describe_detached_head(_("Previous HEAD position was"), commit); - for (i = 0; i < refs.nr; i++) { - struct object *o = refs.objects[i].item; - struct commit *c = lookup_commit_reference_gently(o->sha1, 1); - if (c) - clear_commit_marks(c, ALL_REV_FLAGS); - } + clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS); free(refs.objects); } diff --git a/bundle.c b/bundle.c index 26cc9ab507..a8ea918c08 100644 --- a/bundle.c +++ b/bundle.c @@ -141,8 +141,7 @@ int verify_bundle(struct bundle_header *header, int verbose) refs.objects[i].name); } - for (i = 0; i < refs.nr; i++) - clear_commit_marks((struct commit *)refs.objects[i].item, -1); + clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS); free(refs.objects); if (verbose) { diff --git a/commit.c b/commit.c index ac337c7d7d..4d80f2522c 100644 --- a/commit.c +++ b/commit.c @@ -440,6 +440,20 @@ void clear_commit_marks(struct commit *commit, unsigned int mark) } } +void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark) +{ + struct object *object; + struct commit *commit; + unsigned int i; + + for (i = 0; i < a->nr; i++) { + object = a->objects[i].item; + commit = lookup_commit_reference_gently(object->sha1, 1); + if (commit) + clear_commit_marks(commit, mark); + } +} + struct commit *pop_commit(struct commit_list **stack) { struct commit_list *top = *stack; diff --git a/commit.h b/commit.h index a2d571b974..641f70fb1e 100644 --- a/commit.h +++ b/commit.h @@ -126,6 +126,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list, struct commit *pop_commit(struct commit_list **stack); void clear_commit_marks(struct commit *commit, unsigned int mark); +void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark); /* * Performs an in-place topological sort of list supplied. -- cgit v1.2.3