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

[PATCH v2 1/4] commit.c: add clear_commit_marks_many()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 5, 2013, 22:47 UTC
Message-ID
<1362523639-30566-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1362523639-30566-1-git-send-email-gitster@pobox.com>

clear_commit_marks(struct commit *, unsigned) only can clear flag bits starting from a single commit; introduce an API to allow feeding an array of commits, so that flag bits can be cleared from commits reachable from any of them with a single traversal.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 commit.c | 19 +++++++++++++------
 commit.h |  1 +
 2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/commit.c b/commit.c
index e8eb0ae..4757e50 100644
--- a/commit.c
+++ b/commit.c
@@ -463,14 +463,23 @@ static void clear_commit_marks_1(struct commit_list **plist,
 	}
 }
 
-void clear_commit_marks(struct commit *commit, unsigned int mark)
+void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark)
 {
 	struct commit_list *list = NULL;
-	commit_list_insert(commit, &list);
+
+	while (nr--) {
+		commit_list_insert(*commit, &list);
+		commit++;
+	}
 	while (list)
 		clear_commit_marks_1(&list, pop_commit(&list), mark);
 }
 
+void clear_commit_marks(struct commit *commit, unsigned int mark)
+{
+	clear_commit_marks_many(1, &commit, mark);
+}
+
 void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
 {
 	struct object *object;
@@ -797,8 +806,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
 	if (!result || !result->next) {
 		if (cleanup) {
 			clear_commit_marks(one, all_flags);
-			for (i = 0; i < n; i++)
-				clear_commit_marks(twos[i], all_flags);
+			clear_commit_marks_many(n, twos, all_flags);
 		}
 		return result;
 	}
@@ -816,8 +824,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
 	free_commit_list(result);
 
 	clear_commit_marks(one, all_flags);
-	for (i = 0; i < n; i++)
-		clear_commit_marks(twos[i], all_flags);
+	clear_commit_marks_many(n, twos, all_flags);
 
 	cnt = remove_redundant(rslt, cnt);
 	result = NULL;
diff --git a/commit.h b/commit.h
index b6ad8f3..b997eea 100644
--- a/commit.h
+++ b/commit.h
@@ -134,6 +134,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 struct commit *pop_commit(struct commit_list **stack);
 
 void clear_commit_marks(struct commit *commit, unsigned int mark);
+void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
 void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
 
 /*
-- 
1.8.2-rc2-194-g549a9ef
Previous: Junio C HamanoNext: Jeff King
Message 2 of 9 in “push --follow-tags”
  1. 0/4 push --follow-tagsJunio C Hamano, Mar 5, 2013
  2. 1/4 commit.c: add clear_commit_marks_many()Junio C Hamano, Mar 5, 2013
  3. Jeff KingMar 6, 2013
  4. Junio C HamanoMar 6, 2013
  5. 2/4 commit.c: add in_merge_bases_many()Junio C Hamano, Mar 5, 2013
  6. 3/4 commit.c: use clear_commit_marks_many() in in_merge_bases_many()Junio C Hamano, Mar 5, 2013
  7. 4/4 push: --follow-tagsJunio C Hamano, Mar 5, 2013
  8. Jeff KingMar 6, 2013
  9. Junio C HamanoMar 6, 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.