]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: implement commit_list_contains()
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 8 Dec 2020 22:04:13 +0000 (17:04 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Dec 2020 22:48:16 +0000 (14:48 -0800)
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>
commit.c
commit.h

index fe1fa3dc41fe787883752671e5954b75616fe9ac..9a785bf9062f0f42aac52f548809a6ec02fc4051 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -544,6 +544,17 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
        return new_list;
 }
 
+int commit_list_contains(struct commit *item, struct commit_list *list)
+{
+       while (list) {
+               if (list->item == item)
+                       return 1;
+               list = list->next;
+       }
+
+       return 0;
+}
+
 unsigned commit_list_count(const struct commit_list *l)
 {
        unsigned c = 0;
index 5467786c7be332299e54a954eb9af55b64d58848..742a6de460a73a814ad534c9c138a569ae2732f8 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -167,6 +167,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
 
 struct commit_list *commit_list_insert(struct commit *item,
                                        struct commit_list **list);
+int commit_list_contains(struct commit *item,
+                        struct commit_list *list);
 struct commit_list **commit_list_append(struct commit *commit,
                                        struct commit_list **next);
 unsigned commit_list_count(const struct commit_list *l);