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

[PATCH 3/7] pack-revindex: make `load_pack_revindex` take a repository

From
Taylor Blau <me@ttaylorr.com>
Date
Apr 10, 2023, 22:53 UTC
Message-ID
<be4faf11011efcfab479e5785e6c2bbac95309bd.1681166596.git.me@ttaylorr.com>
In-Reply-To
<cover.1681166596.git.me@ttaylorr.com>

In a future commit, we will introduce a `pack.readReverseIndex` configuration, which forces Git to generate the reverse index from scratch instead of loading it from disk.

In order to avoid reading this configuration value more than once, we'll use the `repo_settings` struct to lazily load this value.

In order to access the `struct repo_settings`, add a repository argument to `load_pack_revindex`, and update all callers to pass the correct instance (in all cases, `the_repository`).

Signed-off-by: Taylor Blauy <me@ttaylorr.com>
---
 pack-bitmap.c   | 5 +++--
 pack-revindex.c | 4 ++--
 pack-revindex.h | 3 ++-
 packfile.c      | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b2e7d06d60..8e3bb00931 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -477,13 +477,14 @@ static int load_reverse_index(struct bitmap_index *bitmap_git)
 		 * since we will need to make use of them in pack-objects.
 		 */
 		for (i = 0; i < bitmap_git->midx->num_packs; i++) {
-			ret = load_pack_revindex(bitmap_git->midx->packs[i]);
+			ret = load_pack_revindex(the_repository,
+						 bitmap_git->midx->packs[i]);
 			if (ret)
 				return ret;
 		}
 		return 0;
 	}
-	return load_pack_revindex(bitmap_git->pack);
+	return load_pack_revindex(the_repository, bitmap_git->pack);
 }
 
 static int load_bitmap(struct bitmap_index *bitmap_git)
diff --git a/pack-revindex.c b/pack-revindex.c
index 03c7e81f9d..e3d69cc0f7 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -283,7 +283,7 @@ static int load_pack_revindex_from_disk(struct packed_git *p)
 	return ret;
 }
 
-int load_pack_revindex(struct packed_git *p)
+int load_pack_revindex(struct repository *r, struct packed_git *p)
 {
 	if (p->revindex || p->revindex_data)
 		return 0;
@@ -356,7 +356,7 @@ int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
 {
 	unsigned lo, hi;
 
-	if (load_pack_revindex(p) < 0)
+	if (load_pack_revindex(the_repository, p) < 0)
 		return -1;
 
 	lo = 0;
diff --git a/pack-revindex.h b/pack-revindex.h
index 4974e75eb4..3d1969ce8b 100644
--- a/pack-revindex.h
+++ b/pack-revindex.h
@@ -39,6 +39,7 @@
 
 struct packed_git;
 struct multi_pack_index;
+struct repository;
 
 /*
  * load_pack_revindex populates the revindex's internal data-structures for the
@@ -47,7 +48,7 @@ struct multi_pack_index;
  * If a '.rev' file is present it is mmap'd, and pointers are assigned into it
  * (instead of using the in-memory variant).
  */
-int load_pack_revindex(struct packed_git *p);
+int load_pack_revindex(struct repository *r, struct packed_git *p);
 
 /*
  * load_midx_revindex loads the '.rev' file corresponding to the given
diff --git a/packfile.c b/packfile.c
index b120405ccc..717fd685c9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -2151,7 +2151,7 @@ int for_each_object_in_pack(struct packed_git *p,
 	int r = 0;
 
 	if (flags & FOR_EACH_OBJECT_PACK_ORDER) {
-		if (load_pack_revindex(p))
+		if (load_pack_revindex(the_repository, p))
 			return -1;
 	}
 
-- 
2.40.0.323.g9c80379958
Previous: Taylor BlauNext: Derrick Stolee
Message 6 of 29 in “pack-revindex: enable on-disk reverse indexes by default”
  1. 0/7 pack-revindex: enable on-disk reverse indexes by defaultTaylor Blau, Apr 10, 2023
  2. 1/7 pack-write.c: plug a leak in stage_tmp_packfiles()Taylor Blau, Apr 10, 2023
  3. Derrick StoleeApr 11, 2023
  4. Taylor BlauApr 11, 2023
  5. 2/7 t5325: mark as leak-freeTaylor Blau, Apr 10, 2023
  6. 3/7 pack-revindex: make `load_pack_revindex` take a repositoryTaylor Blau, Apr 10, 2023
  7. Derrick StoleeApr 11, 2023
  8. Taylor BlauApr 11, 2023
  9. Derrick StoleeApr 12, 2023
  10. 4/7 pack-revindex: introduce GIT_TEST_REV_INDEX_DIE_ON_DISKTaylor Blau, Apr 10, 2023
  11. 5/7 pack-revindex: introduce `pack.readReverseIndex`Taylor Blau, Apr 10, 2023
  12. 6/7 config: enable `pack.writeReverseIndex` by defaultTaylor Blau, Apr 10, 2023
  13. Junio C HamanoApr 13, 2023
  14. 7/7 t: invert `GIT_TEST_WRITE_REV_INDEX`Taylor Blau, Apr 10, 2023
  15. Derrick StoleeApr 11, 2023
  16. Taylor BlauApr 11, 2023
  17. Derrick StoleeApr 12, 2023
  18. Derrick StoleeApr 11, 2023
  19. Taylor BlauApr 11, 2023
  20. Derrick StoleeApr 12, 2023
  21. 0/7 pack-revindex: enable on-disk reverse indexes by defaultTaylor Blau, Apr 12, 2023
  22. 1/7 pack-write.c: plug a leak in stage_tmp_packfiles()Taylor Blau, Apr 12, 2023
  23. 2/7 t5325: mark as leak-freeTaylor Blau, Apr 12, 2023
  24. 3/7 pack-revindex: make `load_pack_revindex` take a repositoryTaylor Blau, Apr 12, 2023
  25. 4/7 pack-revindex: introduce GIT_TEST_REV_INDEX_DIE_ON_DISKTaylor Blau, Apr 12, 2023
  26. 5/7 pack-revindex: introduce `pack.readReverseIndex`Taylor Blau, Apr 12, 2023
  27. 7/7 t: invert `GIT_TEST_WRITE_REV_INDEX`Taylor Blau, Apr 12, 2023
  28. 6/7 config: enable `pack.writeReverseIndex` by defaultTaylor Blau, Apr 12, 2023
  29. Derrick StoleeApr 13, 2023

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.