From: Alban Gruin Date: Fri, 01 Mar 2019 17:50:22 GMT Subject: [RFC PATCH 2/4] commit-list: add a function to check if a commit is in a list Message-ID: <20190301175024.17337-3-alban.gruin@gmail.com> In-Reply-To: <20190301175024.17337-1-alban.gruin@gmail.com> To avoid naming some commits, name_rev() will need to check if a commit is part of a commit list. Signed-off-by: Alban Gruin --- commit.c | 12 ++++++++++++ commit.h | 1 + 2 files changed, 13 insertions(+) diff --git a/commit.c b/commit.c index a5333c7ac6..fcb3e9245f 100644 --- a/commit.c +++ b/commit.c @@ -524,6 +524,18 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list * return new_list; } +int commit_list_contains(const struct commit_list *l, struct commit *commit) +{ + const struct commit_list *item; + + for (item = l; item != NULL; item = item->next) { + if (oideq(&item->item->object.oid, &commit->object.oid)) + return 1; + } + + return 0; +} + unsigned commit_list_count(const struct commit_list *l) { unsigned c = 0; diff --git a/commit.h b/commit.h index 42728c2906..c9df613b0e 100644 --- a/commit.h +++ b/commit.h @@ -165,6 +165,7 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list); struct commit_list **commit_list_append(struct commit *commit, struct commit_list **next); +int commit_list_contains(const struct commit_list *l, struct commit *commit); unsigned commit_list_count(const struct commit_list *l); struct commit_list *commit_list_insert_by_date(struct commit *item, struct commit_list **list); -- 2.20.1