Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2023-04-17 19:21:39 +0300
committerJunio C Hamano <gitster@pobox.com>2023-04-18 00:39:04 +0300
commitd975fe1fa57d57cfd21a97f96f4a94b99f50f2f4 (patch)
tree67bcfd01f1d9300f1840f601a10ca5efd5de28e8 /pack-revindex.c
parent0d30feef3c55f63f8db1dc1e52071090d16dfaaf (diff)
fsck: check rev-index checksums
The previous change added calls to verify_pack_revindex() in builtin/fsck.c, but the implementation of the method was left empty. Add the first and most-obvious check to this method: checksum verification. While here, create a helper method in the test script that makes it easy to adjust the .rev file and check that 'git fsck' reports the correct error message. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-revindex.c')
-rw-r--r--pack-revindex.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/pack-revindex.c b/pack-revindex.c
index c3f2aaa3fe..007a806994 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -5,6 +5,7 @@
#include "packfile.h"
#include "config.h"
#include "midx.h"
+#include "csum-file.h"
struct revindex_entry {
off_t offset;
@@ -309,6 +310,15 @@ int load_pack_revindex(struct repository *r, struct packed_git *p)
*/
int verify_pack_revindex(struct packed_git *p)
{
+ /* Do not bother checking if not initialized. */
+ if (!p->revindex_map)
+ return 0;
+
+ if (!hashfile_checksum_valid((const unsigned char *)p->revindex_map, p->revindex_size)) {
+ error(_("invalid checksum"));
+ return -1;
+ }
+
return 0;
}