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 <dstolee@microsoft.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Dec 8, 2020 at 17:04 UTC
597b2c39af9ee65496591448715588b711e91947
2 files changed
+13
commit.c
+11
@@ -544,6 +544,17 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
544
return new_list;
545
}
546
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
+
558
unsigned commit_list_count(const struct commit_list *l)
559
{
560
unsigned c = 0;
commit.h
+2
@@ -167,6 +167,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
167
168
struct commit_list *commit_list_insert(struct commit *item,
169
struct commit_list **list);
170
+int commit_list_contains(struct commit *item,
171
+ struct commit_list *list);
172
struct commit_list **commit_list_append(struct commit *commit,
173
struct commit_list **next);
174
unsigned commit_list_count(const struct commit_list *l);