Skip to content

Commit 86a0a40

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1062141 commit 86a0a40

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

bisect.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ static int check_ancestors(const char *prefix)
818818
{
819819
struct rev_info revs;
820820
struct object_array pending_copy;
821-
int i, res;
821+
int res;
822822

823823
bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
824824

@@ -835,10 +835,7 @@ static int check_ancestors(const char *prefix)
835835
res = (revs.commits != NULL);
836836

837837
/* 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);
842839
free(pending_copy.objects);
843840

844841
return res;

builtin/checkout.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ static void orphaned_commit_warning(struct commit *commit)
663663
struct rev_info revs;
664664
struct object *object = &commit->object;
665665
struct object_array refs;
666-
unsigned int i;
667666

668667
init_revisions(&revs, NULL);
669668
setup_revisions(0, NULL, &revs, NULL);
@@ -683,12 +682,7 @@ static void orphaned_commit_warning(struct commit *commit)
683682
else
684683
describe_detached_head(_("Previous HEAD position was"), commit);
685684

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);
692686
free(refs.objects);
693687
}
694688

bundle.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
141141
refs.objects[i].name);
142142
}
143143

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);
146145
free(refs.objects);
147146

148147
if (verbose) {

commit.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,20 @@ void clear_commit_marks(struct commit *commit, unsigned int mark)
440440
}
441441
}
442442

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+
443457
struct commit *pop_commit(struct commit_list **stack)
444458
{
445459
struct commit_list *top = *stack;

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
126126
struct commit *pop_commit(struct commit_list **stack);
127127

128128
void clear_commit_marks(struct commit *commit, unsigned int mark);
129+
void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
129130

130131
/*
131132
* Performs an in-place topological sort of list supplied.

0 commit comments

Comments
 (0)