git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: John KeepingNext: John Keeping
Message 2 of 22 in “merge-base: add --merge-child option”
  1. 0/2 merge-base: add --merge-child optionJohn Keeping, May 11, 2013
  2. 1/2 commit: add commit_list_contains functionJohn Keeping, May 11, 2013
  3. 2/2 merge-base: add --merge-child optionJohn Keeping, May 11, 2013
  4. Junio C HamanoMay 11, 2013
  5. John KeepingMay 11, 2013
  6. Kevin BraceyMay 12, 2013
  7. John KeepingMay 12, 2013
  8. John KeepingMay 12, 2013
  9. Kevin BraceyMay 12, 2013
  10. Junio C HamanoMay 12, 2013
  11. Kevin BraceyMay 13, 2013
  12. Michael J GruberMay 13, 2013
  13. log --cherry and merges (was [RFC/PATCH 0/2] merge-base: add --merge-child option)John Keeping, May 19, 2013
  14. Jonathan NiederMay 20, 2013
  15. 0/2 Make --ancestry-path A...B workKevin Bracey, May 13, 2013
  16. 1/2 t6019: demonstrate --ancestry-path A...B breakageKevin Bracey, May 13, 2013
  17. 2/2 revision.c: treat A...B merge bases as if manually specifiedKevin Bracey, May 13, 2013
  18. Junio C HamanoMay 13, 2013
  19. John KeepingMay 12, 2013
  20. Kevin BraceyMay 12, 2013
  21. Junio C HamanoMay 13, 2013
  22. John KeepingMay 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.