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

[PATCH 4/8] midx: drop redundant `struct repository` parameter

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 29, 2025, 14:12 UTC
Message-ID
<20250729-b4-pks-midx-deduplicate-source-info-v1-4-748db2eda3b5@pks.im>
In-Reply-To
<20250729-b4-pks-midx-deduplicate-source-info-v1-0-748db2eda3b5@pks.im>

There are a couple of functions that take both a `struct repository` and a `struct multi_pack_index`. This provides redundant information though without much benefit given that the multi-pack index already has a pointer to its owning repository.

Drop the `struct repository` parameter from such functions. While at it, reorder the list of parameters of `fill_midx_entry()` so that the MIDX comes first to better align with our coding guidelines.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/pack-objects.c    |  2 +-
 midx-write.c              | 16 +++++++---------
 midx.c                    | 18 +++++++++---------
 midx.h                    |  6 +++---
 pack-bitmap.c             |  4 ++--
 packfile.c                |  4 ++--
 t/helper/test-read-midx.c |  4 ++--
 7 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 3dd84495b8..b9fd685b8f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1733,7 +1733,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
 		struct multi_pack_index *m = get_multi_pack_index(source);
 		struct pack_entry e;
 
-		if (m && fill_midx_entry(the_repository, oid, &e, m)) {
+		if (m && fill_midx_entry(m, oid, &e)) {
 			want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
 			if (want != -1)
 				return want;
diff --git a/midx-write.c b/midx-write.c
index 40580d8c73..37a0b1682f 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -944,8 +944,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
 			 */
 			if (flags & MIDX_WRITE_REV_INDEX ||
 			    preferred_pack_name) {
-				if (prepare_midx_pack(ctx->repo, m,
-						      m->num_packs_in_base + i)) {
+				if (prepare_midx_pack(m, m->num_packs_in_base + i)) {
 					error(_("could not load pack"));
 					return 1;
 				}
@@ -1568,7 +1567,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
 		if (count[i])
 			continue;
 
-		if (prepare_midx_pack(r, m, i))
+		if (prepare_midx_pack(m, i))
 			continue;
 
 		if (m->packs[i]->pack_keep || m->packs[i]->is_cruft)
@@ -1614,13 +1613,12 @@ static int compare_by_mtime(const void *a_, const void *b_)
 	return 0;
 }
 
-static int want_included_pack(struct repository *r,
-			      struct multi_pack_index *m,
+static int want_included_pack(struct multi_pack_index *m,
 			      int pack_kept_objects,
 			      uint32_t pack_int_id)
 {
 	struct packed_git *p;
-	if (prepare_midx_pack(r, m, pack_int_id))
+	if (prepare_midx_pack(m, pack_int_id))
 		return 0;
 	p = m->packs[pack_int_id];
 	if (!pack_kept_objects && p->pack_keep)
@@ -1642,7 +1640,7 @@ static void fill_included_packs_all(struct repository *r,
 	repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
 
 	for (i = 0; i < m->num_packs; i++) {
-		if (!want_included_pack(r, m, pack_kept_objects, i))
+		if (!want_included_pack(m, pack_kept_objects, i))
 			continue;
 
 		include_pack[i] = 1;
@@ -1666,7 +1664,7 @@ static void fill_included_packs_batch(struct repository *r,
 	for (i = 0; i < m->num_packs; i++) {
 		pack_info[i].pack_int_id = i;
 
-		if (prepare_midx_pack(r, m, i))
+		if (prepare_midx_pack(m, i))
 			continue;
 
 		pack_info[i].mtime = m->packs[i]->mtime;
@@ -1685,7 +1683,7 @@ static void fill_included_packs_batch(struct repository *r,
 		struct packed_git *p = m->packs[pack_int_id];
 		uint64_t expected_size;
 
-		if (!want_included_pack(r, m, pack_kept_objects, pack_int_id))
+		if (!want_included_pack(m, pack_kept_objects, pack_int_id))
 			continue;
 
 		/*
diff --git a/midx.c b/midx.c
index b9ca0915a6..8459dda8c9 100644
--- a/midx.c
+++ b/midx.c
@@ -450,9 +450,10 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
 	return pack_int_id - m->num_packs_in_base;
 }
 
-int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
+int prepare_midx_pack(struct multi_pack_index *m,
 		      uint32_t pack_int_id)
 {
+	struct repository *r = m->repo;
 	struct strbuf pack_name = STRBUF_INIT;
 	struct strbuf key = STRBUF_INIT;
 	struct packed_git *p;
@@ -507,7 +508,7 @@ struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
 
 #define MIDX_CHUNK_BITMAPPED_PACKS_WIDTH (2 * sizeof(uint32_t))
 
-int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
+int nth_bitmapped_pack(struct multi_pack_index *m,
 		       struct bitmapped_pack *bp, uint32_t pack_int_id)
 {
 	uint32_t local_pack_int_id = midx_for_pack(&m, pack_int_id);
@@ -515,7 +516,7 @@ int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
 	if (!m->chunk_bitmapped_packs)
 		return error(_("MIDX does not contain the BTMP chunk"));
 
-	if (prepare_midx_pack(r, m, pack_int_id))
+	if (prepare_midx_pack(m, pack_int_id))
 		return error(_("could not load bitmapped pack %"PRIu32), pack_int_id);
 
 	bp->p = m->packs[local_pack_int_id];
@@ -600,10 +601,9 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
 					       (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
 }
 
-int fill_midx_entry(struct repository *r,
+int fill_midx_entry(struct multi_pack_index *m,
 		    const struct object_id *oid,
-		    struct pack_entry *e,
-		    struct multi_pack_index *m)
+		    struct pack_entry *e)
 {
 	uint32_t pos;
 	uint32_t pack_int_id;
@@ -615,7 +615,7 @@ int fill_midx_entry(struct repository *r,
 	midx_for_object(&m, pos);
 	pack_int_id = nth_midxed_pack_int_id(m, pos);
 
-	if (prepare_midx_pack(r, m, pack_int_id))
+	if (prepare_midx_pack(m, pack_int_id))
 		return 0;
 	p = m->packs[pack_int_id - m->num_packs_in_base];
 
@@ -912,7 +912,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
 						  _("Looking for referenced packfiles"),
 						  m->num_packs + m->num_packs_in_base);
 	for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
-		if (prepare_midx_pack(r, m, i))
+		if (prepare_midx_pack(m, i))
 			midx_report("failed to load pack in position %d", i);
 
 		display_progress(progress, i + 1);
@@ -989,7 +989,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
 
 		nth_midxed_object_oid(&oid, m, pairs[i].pos);
 
-		if (!fill_midx_entry(r, &oid, &e, m)) {
+		if (!fill_midx_entry(m, &oid, &e)) {
 			midx_report(_("failed to load pack entry for oid[%d] = %s"),
 				    pairs[i].pos, oid_to_hex(&oid));
 			continue;
diff --git a/midx.h b/midx.h
index 28c426a823..f7e07083e1 100644
--- a/midx.h
+++ b/midx.h
@@ -103,10 +103,10 @@ void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
 struct multi_pack_index *load_multi_pack_index(struct repository *r,
 					       const char *object_dir,
 					       int local);
-int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
+int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
 struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
 				   uint32_t pack_int_id);
-int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
+int nth_bitmapped_pack(struct multi_pack_index *m,
 		       struct bitmapped_pack *bp, uint32_t pack_int_id);
 int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
 		     uint32_t *result);
@@ -118,7 +118,7 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos);
 struct object_id *nth_midxed_object_oid(struct object_id *oid,
 					struct multi_pack_index *m,
 					uint32_t n);
-int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
+int fill_midx_entry(struct multi_pack_index *m, const struct object_id *oid, struct pack_entry *e);
 int midx_contains_pack(struct multi_pack_index *m,
 		       const char *idx_or_pack_name);
 int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
diff --git a/pack-bitmap.c b/pack-bitmap.c
index d14421ee20..fb0b11ca07 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -493,7 +493,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
 	}
 
 	for (i = 0; i < bitmap_git->midx->num_packs + bitmap_git->midx->num_packs_in_base; i++) {
-		if (prepare_midx_pack(bitmap_repo(bitmap_git), bitmap_git->midx, i)) {
+		if (prepare_midx_pack(bitmap_git->midx, i)) {
 			warning(_("could not open pack %s"),
 				bitmap_git->midx->pack_names[i]);
 			goto cleanup;
@@ -2466,7 +2466,7 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
 		struct multi_pack_index *m = bitmap_git->midx;
 		for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
 			struct bitmapped_pack pack;
-			if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
+			if (nth_bitmapped_pack(bitmap_git->midx, &pack, i) < 0) {
 				warning(_("unable to load pack: '%s', disabling pack-reuse"),
 					bitmap_git->midx->pack_names[i]);
 				free(packs);
diff --git a/packfile.c b/packfile.c
index a38544b87b..acb680966d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1091,7 +1091,7 @@ struct packed_git *get_all_packs(struct repository *r)
 		if (!m)
 			continue;
 		for (uint32_t i = 0; i < m->num_packs + m->num_packs_in_base; i++)
-			prepare_midx_pack(r, m, i);
+			prepare_midx_pack(m, i);
 	}
 
 	return r->objects->packed_git;
@@ -2077,7 +2077,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
 	prepare_packed_git(r);
 
 	for (struct odb_source *source = r->objects->sources; source; source = source->next)
-		if (source->midx && fill_midx_entry(r, oid, e, source->midx))
+		if (source->midx && fill_midx_entry(source->midx, oid, e))
 			return 1;
 
 	if (!r->objects->packed_git)
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index da2aa036b5..e430aa247c 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -65,7 +65,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
 		for (i = 0; i < m->num_objects; i++) {
 			nth_midxed_object_oid(&oid, m,
 					      i + m->num_objects_in_base);
-			fill_midx_entry(the_repository, &oid, &e, m);
+			fill_midx_entry(m, &oid, &e);
 
 			printf("%s %"PRIu64"\t%s\n",
 			       oid_to_hex(&oid), e.offset, e.p->pack_name);
@@ -126,7 +126,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)
 		return 1;
 
 	for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) {
-		if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) {
+		if (nth_bitmapped_pack(midx, &pack, i) < 0) {
 			close_midx(midx);
 			return 1;
 		}
-- 
2.50.1.619.g074bbf1d35.dirty
Previous: Karthik NayakNext: Patrick Steinhardt
Message 11 of 56 in “midx: stop deduplicating info redundant with their sources”
  1. 0/8 midx: stop deduplicating info redundant with their sourcesPatrick Steinhardt, Jul 29, 2025
  2. 1/8 odb: store locality in object database sourcesPatrick Steinhardt, Jul 29, 2025
  3. Toon ClaesAug 6, 2025
  4. Patrick SteinhardtAug 7, 2025
  5. Karthik NayakAug 7, 2025
  6. 2/8 odb: allow `odb_find_source()` to failPatrick Steinhardt, Jul 29, 2025
  7. 3/8 odb: return newly created in-memory sourcesPatrick Steinhardt, Jul 29, 2025
  8. Toon ClaesAug 6, 2025
  9. Patrick SteinhardtAug 7, 2025
  10. Karthik NayakAug 7, 2025
  11. 4/8 midx: drop redundant `struct repository` parameterPatrick Steinhardt, Jul 29, 2025
  12. 5/8 midx: load multi-pack indices via their sourcePatrick Steinhardt, Jul 29, 2025
  13. Karthik NayakAug 7, 2025
  14. Karthik NayakAug 7, 2025
  15. 6/8 midx: write multi-pack indices via their sourcePatrick Steinhardt, Jul 29, 2025
  16. Karthik NayakAug 7, 2025
  17. 7/8 midx: stop duplicating info redundant with its owning sourcePatrick Steinhardt, Jul 29, 2025
  18. 8/8 midx: compute paths via their sourcePatrick Steinhardt, Jul 29, 2025
  19. Junio C HamanoJul 29, 2025
  20. Patrick SteinhardtJul 30, 2025
  21. 0/9 midx: stop duplicating info redundant with their sourcesPatrick Steinhardt, Aug 7, 2025
  22. 1/9 odb: store locality in object database sourcesPatrick Steinhardt, Aug 7, 2025
  23. Taylor BlauAug 7, 2025
  24. 2/9 odb: allow `odb_find_source()` to failPatrick Steinhardt, Aug 7, 2025
  25. Taylor BlauAug 7, 2025
  26. Patrick SteinhardtAug 11, 2025
  27. 3/9 odb: return newly created in-memory sourcesPatrick Steinhardt, Aug 7, 2025
  28. Taylor BlauAug 7, 2025
  29. Patrick SteinhardtAug 11, 2025
  30. 4/9 odb: simplify calling `link_alt_odb_entry()`Patrick Steinhardt, Aug 7, 2025
  31. Taylor BlauAug 7, 2025
  32. 5/9 midx: drop redundant `struct repository` parameterPatrick Steinhardt, Aug 7, 2025
  33. 6/9 midx: load multi-pack indices via their sourcePatrick Steinhardt, Aug 7, 2025
  34. Taylor BlauAug 7, 2025
  35. 7/9 midx: write multi-pack indices via their sourcePatrick Steinhardt, Aug 7, 2025
  36. Taylor BlauAug 7, 2025
  37. 8/9 midx: stop duplicating info redundant with its owning sourcePatrick Steinhardt, Aug 7, 2025
  38. 9/9 midx: compute paths via their sourcePatrick Steinhardt, Aug 7, 2025
  39. Taylor BlauAug 7, 2025
  40. Patrick SteinhardtAug 11, 2025
  41. Karthik NayakAug 7, 2025
  42. 00/10 midx: stop duplicating info redundant with their sourcesPatrick Steinhardt, Aug 11, 2025
  43. 01/10 odb: store locality in object database sourcesPatrick Steinhardt, Aug 11, 2025
  44. 02/10 odb: allow `odb_find_source()` to failPatrick Steinhardt, Aug 11, 2025
  45. 03/10 odb: consistently use "dir" to refer to alternate's directoryPatrick Steinhardt, Aug 11, 2025
  46. 04/10 odb: return newly created in-memory sourcesPatrick Steinhardt, Aug 11, 2025
  47. 05/10 odb: simplify calling `link_alt_odb_entry()`Patrick Steinhardt, Aug 11, 2025
  48. 06/10 midx: drop redundant `struct repository` parameterPatrick Steinhardt, Aug 11, 2025
  49. 07/10 midx: load multi-pack indices via their sourcePatrick Steinhardt, Aug 11, 2025
  50. 08/10 midx: write multi-pack indices via their sourcePatrick Steinhardt, Aug 11, 2025
  51. 09/10 midx: stop duplicating info redundant with its owning sourcePatrick Steinhardt, Aug 11, 2025
  52. 10/10 midx: compute paths via their sourcePatrick Steinhardt, Aug 11, 2025
  53. Junio C HamanoAug 28, 2025
  54. Taylor BlauAug 29, 2025
  55. Derrick StoleeAug 30, 2025
  56. Patrick SteinhardtSep 2, 2025

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.