mbox series

[v2,0/2] fsck: verify .bitmap checksums, cleanup

Message ID pull.1526.v2.git.1683034042.gitgitgadget@gmail.com (mailing list archive)
Headers show
Series fsck: verify .bitmap checksums, cleanup | expand

Message

Jean-Noël Avila via GitGitGadget May 2, 2023, 1:27 p.m. UTC
Similar to the recent work on rev-indexes [1], add checks for .bitmap files
to 'git fsck'.

Patch 1 includes the full details for .bitmap files.

Patch 2 includes a cleanup of ds/fsck-pack-revindex that I noticed while
preparing this series.


Updates since v2
================

 * The code for verify_bitmap_file() added checks for a negative file
   descriptor, as well as some other cleanup.
 * The test in t5326 is expanded to include the "both are corrupt" case, as
   well as a reorganization because the test was not confined to an inner
   repo.

Thanks, Stolee

[1]
https://lore.kernel.org/git/pull.1512.git.1681748502.gitgitgadget@gmail.com/

Derrick Stolee (2):
  fsck: verify checksums of all .bitmap files
  fsck: use local repository

 builtin/fsck.c                | 10 +++++---
 pack-bitmap.c                 | 45 +++++++++++++++++++++++++++++++++++
 pack-bitmap.h                 |  2 ++
 t/t5326-multi-pack-bitmaps.sh | 44 ++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 3 deletions(-)


base-commit: 48d89b51b3bb8a60580c36731b96a7206ce1e5b9
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1526%2Fderrickstolee%2Ffsck-bitmap-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1526/derrickstolee/fsck-bitmap-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1526

Range-diff vs v1:

 1:  d608d2faa86 ! 1:  5d6d6658633 fsck: verify checksums of all .bitmap files
     @@ pack-bitmap.c: int bitmap_is_preferred_refname(struct repository *r, const char
      +	int fd = git_open(name);
      +	int res = 0;
      +
     -+	/* A non-existent file is valid. */
     -+	if (fstat(fd, &st)) {
     -+		close(fd);
     ++	/* It is OK to not have the file. */
     ++	if (fd < 0 || fstat(fd, &st)) {
     ++		if (fd >= 0)
     ++			close(fd);
      +		return 0;
      +	}
      +
     @@ t/t5326-multi-pack-bitmaps.sh: test_expect_success 'tagged commits are selected
      +	cp "$packbitmap.bak" "$packbitmap" &&
      +
      +	# fsck works at first
     -+	git fsck &&
     ++	git fsck 2>err &&
     ++	test_must_be_empty err &&
      +
      +	corrupt_file "$packbitmap" &&
      +	test_must_fail git fsck 2>err &&
     @@ t/t5326-multi-pack-bitmaps.sh: test_expect_success 'tagged commits are selected
      +	cp "$packbitmap.bak" "$packbitmap" &&
      +	corrupt_file "$midxbitmap" &&
      +	test_must_fail git fsck 2>err &&
     -+	grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err
     ++	grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
     ++
     ++	corrupt_file "$packbitmap" &&
     ++	test_must_fail git fsck 2>err &&
     ++	grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
     ++	grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err
      +'
      +
       test_done
 2:  2162a352a46 = 2:  00789bbc558 fsck: use local repository