[RFC/PATCH 1/2] commit: add commit_list_contains function
- From
John Keeping <john@keeping.me.uk>
- Date
- May 11, 2013, 12:23 UTC
- Message-ID
- <f3e086bee6b59fead4f9866b3f616a916b932706.1368274689.git.john@keeping.me.uk>
- In-Reply-To
- <cover.1368274689.git.john@keeping.me.uk>
This is the same as the in_commit_list function already in builtin/tag.c so we also replace that by the new commit_list_contains function.
Signed-off-by: John Keeping <john@keeping.me.uk> --- builtin/tag.c | 10 +--------- commit.c | 8 ++++++++ commit.h | 1 + 3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c index af3af3f..1c24772 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -65,14 +65,6 @@ static const unsigned char *match_points_at(const char *refname, return NULL; } -static int in_commit_list(const struct commit_list *want, struct commit *c) -{ - for (; want; want = want->next) - if (!hashcmp(want->item->object.sha1, c->object.sha1)) - return 1; - return 0; -} - static int contains_recurse(struct commit *candidate, const struct commit_list *want) { @@ -85,7 +77,7 @@ static int contains_recurse(struct commit *candidate, if (candidate->object.flags & UNINTERESTING) return 0; /* or are we it? */ - if (in_commit_list(want, candidate)) + if (commit_list_contains(want, candidate)) return 1; if (parse_commit(candidate) < 0) diff --git a/commit.c b/commit.c index 888e02a..a8263c3 100644 --- a/commit.c +++ b/commit.c @@ -420,6 +420,14 @@ void commit_list_sort_by_date(struct commit_list **list) commit_list_compare_by_date); } +int commit_list_contains(const struct commit_list *list, const struct commit *item) +{ + for (; list; list = list->next) + if (!hashcmp(list->item->object.sha1, item->object.sha1)) + return 1; + return 0; +} + struct commit *pop_most_recent_commit(struct commit_list **list, unsigned int mark) { diff --git a/commit.h b/commit.h index 67bd509..d686ea8 100644 --- a/commit.h +++ b/commit.h @@ -60,6 +60,7 @@ unsigned commit_list_count(const struct commit_list *l); struct commit_list *commit_list_insert_by_date(struct commit *item, struct commit_list **list); void commit_list_sort_by_date(struct commit_list **list); +int commit_list_contains(const struct commit_list *list, const struct commit *item); void free_commit_list(struct commit_list *list);
-- 1.8.3.rc1.289.gcb3647f