Skip to content

Commit 597b2c3

Browse files
derrickstoleegitster
authored andcommitted
commit: implement commit_list_contains()
It can be helpful to check if a commit_list contains a commit. Use pointer equality, assuming lookup_commit() was used. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed03a58 commit 597b2c3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

commit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
544544
return new_list;
545545
}
546546

547+
int commit_list_contains(struct commit *item, struct commit_list *list)
548+
{
549+
while (list) {
550+
if (list->item == item)
551+
return 1;
552+
list = list->next;
553+
}
554+
555+
return 0;
556+
}
557+
547558
unsigned commit_list_count(const struct commit_list *l)
548559
{
549560
unsigned c = 0;

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
167167

168168
struct commit_list *commit_list_insert(struct commit *item,
169169
struct commit_list **list);
170+
int commit_list_contains(struct commit *item,
171+
struct commit_list *list);
170172
struct commit_list **commit_list_append(struct commit *commit,
171173
struct commit_list **next);
172174
unsigned commit_list_count(const struct commit_list *l);

0 commit comments

Comments
 (0)