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

[PATCH] midx.c: clear auxiliary MIDX files first

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 25, 2022, 18:25 UTC
Message-ID
<bf36093cd6d7ac83b16241b0199b3a8c904e6774.1666722316.git.me@ttaylorr.com>

Since they were added in c528e17966 (pack-bitmap: write multi-pack bitmaps, 2021-08-31), the routine to remove MIDXs removed the multi-pack-index file itself before removing its associated .bitmap and .rev file(s), if any.

This creates a window where a MIDX's .bitmap file exists without its corresponding MIDX. If a reader tries to load a MIDX bitmap during that time, they will get a warning, and the MIDX bitmap code will gracefully degrade.

Remove this window entirely by removing the MIDX last, and removing its auxiliary files first.

The order here is important, too. We remove the MIDX's .bitmap file ahead of its .rev, since callers try and read the .bitmap first. The .rev file is no longer generated by modern versions of Git, but cleaning up old ones generated by previous versions of Git is still important to do.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 midx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/midx.c b/midx.c
index 3a8dcfe98e..994129aecd 100644
--- a/midx.c
+++ b/midx.c
@@ -1619,12 +1619,12 @@ void clear_midx_file(struct repository *r)
 		r->objects->multi_pack_index = NULL;
 	}
 
-	if (remove_path(midx.buf))
-		die(_("failed to clear multi-pack-index at %s"), midx.buf);
-
 	clear_midx_files_ext(r->objects->odb->path, ".bitmap", NULL);
 	clear_midx_files_ext(r->objects->odb->path, ".rev", NULL);
 
+	if (remove_path(midx.buf))
+		die(_("failed to clear multi-pack-index at %s"), midx.buf);
+
 	strbuf_release(&midx);
 }
 
-- 
2.38.0.16.g393fd4c6db
Next: Jeff King
Message 1 of 5 in “midx.c: clear auxiliary MIDX files first”
  1. midx.c: clear auxiliary MIDX files firstTaylor Blau, Oct 25, 2022
  2. Jeff KingOct 26, 2022
  3. Derrick StoleeOct 26, 2022
  4. Taylor BlauOct 26, 2022
  5. Jeff KingOct 27, 2022

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.