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

[PATCH v2 6/9] bundle: avoid using the rev_info flag leak_pending

From
René Scharfe <l.s.r@web.de>
Date
Dec 25, 2017, 17:46 UTC
Message-ID
<5fe3b4c8-e48c-1922-f564-e75c5a354cef@web.de>
In-Reply-To
<ac4c77a1-6403-ca20-2021-50c99201915a@web.de>

The leak_pending flag is so awkward to use that multiple comments had to be added around each occurrence. We use it for remembering the prerequisites for the bundle. That is easy, though: We have the ref_list named "prerequisites" in the header for just that purpose.

Use this original list of prerequisites to check if all of them are present and to clear their commit marks afterward. The two new loops are intentionally kept similar to the first one in the function. Calling parse_object() a second time is expected be quick and successful in each case -- any errors should have been handled in the first round.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 bundle.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/bundle.c b/bundle.c
index 93290962c9..efe547e25f 100644
--- a/bundle.c
+++ b/bundle.c
@@ -128,83 +128,80 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
 int verify_bundle(struct bundle_header *header, int verbose)
 {
 	/*
 	 * Do fast check, then if any prereqs are missing then go line by line
 	 * to be verbose about the errors
 	 */
 	struct ref_list *p = &header->prerequisites;
 	struct rev_info revs;
 	const char *argv[] = {NULL, "--all", NULL};
-	struct object_array refs;
 	struct commit *commit;
 	int i, ret = 0, req_nr;
 	const char *message = _("Repository lacks these prerequisite commits:");
 
 	init_revisions(&revs, NULL);
 	for (i = 0; i < p->nr; i++) {
 		struct ref_list_entry *e = p->list + i;
 		struct object *o = parse_object(&e->oid);
 		if (o) {
 			o->flags |= PREREQ_MARK;
 			add_pending_object(&revs, o, e->name);
 			continue;
 		}
 		if (++ret == 1)
 			error("%s", message);
 		error("%s %s", oid_to_hex(&e->oid), e->name);
 	}
 	if (revs.pending.nr != p->nr)
 		return ret;
 	req_nr = revs.pending.nr;
 	setup_revisions(2, argv, &revs, NULL);
 
-	/* Save pending objects, so they can be cleaned up later. */
-	refs = revs.pending;
-	revs.leak_pending = 1;
-
-	/*
-	 * prepare_revision_walk (together with .leak_pending = 1) makes us
-	 * the sole owner of the list of pending objects.
-	 */
 	if (prepare_revision_walk(&revs))
 		die(_("revision walk setup failed"));
 
 	i = req_nr;
 	while (i && (commit = get_revision(&revs)))
 		if (commit->object.flags & PREREQ_MARK)
 			i--;
 
-	for (i = 0; i < req_nr; i++)
-		if (!(refs.objects[i].item->flags & SHOWN)) {
-			if (++ret == 1)
-				error("%s", message);
-			error("%s %s", oid_to_hex(&refs.objects[i].item->oid),
-				refs.objects[i].name);
-		}
+	for (i = 0; i < p->nr; i++) {
+		struct ref_list_entry *e = p->list + i;
+		struct object *o = parse_object(&e->oid);
+		assert(o); /* otherwise we'd have returned early */
+		if (o->flags & SHOWN)
+			continue;
+		if (++ret == 1)
+			error("%s", message);
+		error("%s %s", oid_to_hex(&e->oid), e->name);
+	}
 
 	/* Clean up objects used, as they will be reused. */
-	clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
-
-	object_array_clear(&refs);
+	for (i = 0; i < p->nr; i++) {
+		struct ref_list_entry *e = p->list + i;
+		commit = lookup_commit_reference_gently(&e->oid, 1);
+		if (commit)
+			clear_commit_marks(commit, ALL_REV_FLAGS);
+	}
 
 	if (verbose) {
 		struct ref_list *r;
 
 		r = &header->references;
 		printf_ln(Q_("The bundle contains this ref:",
 			     "The bundle contains these %d refs:",
 			     r->nr),
 			  r->nr);
 		list_refs(r, 0, NULL);
 		r = &header->prerequisites;
 		if (!r->nr) {
 			printf_ln(_("The bundle records a complete history."));
 		} else {
 			printf_ln(Q_("The bundle requires this ref:",
 				     "The bundle requires these %d refs:",
 				     r->nr),
 				  r->nr);
 			list_refs(r, 0, NULL);
 		}
 	}
 	return ret;
 }
-- 
2.15.1
Previous: Jeff KingNext: Junio C Hamano
Message 24 of 32 in “revision: introduce prepare_revision_walk_extended()”
  1. revision: introduce prepare_revision_walk_extended()René Scharfe, Dec 16, 2017
  2. Martin ÅgrenDec 17, 2017
  3. Jeff KingDec 18, 2017
  4. René ScharfeDec 18, 2017
  5. Jeff KingDec 19, 2017
  6. Junio C HamanoDec 19, 2017
  7. Jeff KingDec 20, 2017
  8. René ScharfeDec 21, 2017
  9. Jeff KingDec 24, 2017
  10. René ScharfeDec 25, 2017
  11. 0/9 revision: get rid of the flag leak_pendingRené Scharfe, Dec 25, 2017
  12. 1/9 commit: avoid allocation in clear_commit_marks_many()René Scharfe, Dec 25, 2017
  13. Jeff KingJan 10, 2018
  14. 2/9 commit: use clear_commit_marks_many() in remove_redundant()René Scharfe, Dec 25, 2017
  15. 3/9 ref-filter: use clear_commit_marks_many() in do_merge_filter()René Scharfe, Dec 25, 2017
  16. 4/9 object: add clear_commit_marks_all()René Scharfe, Dec 25, 2017
  17. Jeff KingJan 10, 2018
  18. René ScharfeJan 11, 2018
  19. Jeff KingJan 12, 2018
  20. 5/9 bisect: avoid using the rev_info flag leak_pendingRené Scharfe, Dec 25, 2017
  21. Jeff KingJan 10, 2018
  22. René ScharfeJan 11, 2018
  23. Jeff KingJan 12, 2018
  24. 6/9 bundle: avoid using the rev_info flag leak_pendingRené Scharfe, Dec 25, 2017
  25. Junio C HamanoDec 28, 2017
  26. Jeff KingJan 10, 2018
  27. 7/9 checkout: avoid using the rev_info flag leak_pendingRené Scharfe, Dec 25, 2017
  28. Junio C HamanoDec 28, 2017
  29. 8/9 revision: remove the unused flag leak_pendingRené Scharfe, Dec 25, 2017
  30. 9/9 commit: remove unused function clear_commit_marks_for_object_array()René Scharfe, Dec 25, 2017
  31. Junio C HamanoDec 28, 2017
  32. Jeff KingJan 10, 2018

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.