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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 1, 2011 at 18:16 UTC
86a0a408b900eecc9d0d4a1eb8ae223181e96679
5 files changed
+19
-14
bisect.c
+2
-5
@@ -818,7 +818,7 @@ static int check_ancestors(const char *prefix)
818
{
819
struct rev_info revs;
820
struct object_array pending_copy;
821
- int i, res;
821
+ int res;
822
823
bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
824
@@ -835,10 +835,7 @@ static int check_ancestors(const char *prefix)
835
res = (revs.commits != NULL);
836
837
/* Clean up objects used, as they will be reused. */
838
- for (i = 0; i < pending_copy.nr; i++) {
839
- struct object *o = pending_copy.objects[i].item;
840
- clear_commit_marks((struct commit *)o, ALL_REV_FLAGS);
841
- }
838
+ clear_commit_marks_for_object_array(&pending_copy, ALL_REV_FLAGS);
839
free(pending_copy.objects);
840
841
return res;
builtin/checkout.c
+1
-7
@@ -663,7 +663,6 @@ static void orphaned_commit_warning(struct commit *commit)
663
struct rev_info revs;
664
struct object *object = &commit->object;
665
struct object_array refs;
666
- unsigned int i;
666
667
init_revisions(&revs, NULL);
668
setup_revisions(0, NULL, &revs, NULL);
@@ -683,12 +682,7 @@ static void orphaned_commit_warning(struct commit *commit)
682
else
683
describe_detached_head(_("Previous HEAD position was"), commit);
684
686
- for (i = 0; i < refs.nr; i++) {
687
- struct object *o = refs.objects[i].item;
688
- struct commit *c = lookup_commit_reference_gently(o->sha1, 1);
689
- if (c)
690
- clear_commit_marks(c, ALL_REV_FLAGS);
691
- }
685
+ clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
686
free(refs.objects);
687
}
688
bundle.c
+1
-2
@@ -141,8 +141,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
141
refs.objects[i].name);
142
}
143
144
- for (i = 0; i < refs.nr; i++)
145
- clear_commit_marks((struct commit *)refs.objects[i].item, -1);
144
+ clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
145
free(refs.objects);
146
147
if (verbose) {
commit.c
+14
@@ -440,6 +440,20 @@ void clear_commit_marks(struct commit *commit, unsigned int mark)
440
}
441
}
442
443
+void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
444
+{
445
+ struct object *object;
446
+ struct commit *commit;
447
+ unsigned int i;
448
+
449
+ for (i = 0; i < a->nr; i++) {
450
+ object = a->objects[i].item;
451
+ commit = lookup_commit_reference_gently(object->sha1, 1);
452
+ if (commit)
453
+ clear_commit_marks(commit, mark);
454
+ }
455
+}
456
+
457
struct commit *pop_commit(struct commit_list **stack)
458
{
459
struct commit_list *top = *stack;
commit.h
+1
@@ -126,6 +126,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
126
struct commit *pop_commit(struct commit_list **stack);
127
128
void clear_commit_marks(struct commit *commit, unsigned int mark);
129
+void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
130
131
/*
132
* Performs an in-place topological sort of list supplied.