From: git@jeffhostetler.com
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net,
Jeff Hostetler <jeffhost@microsoft.com>
Subject: [PATCH v4 2/4] fsck: force core.checksumindex=1
Date: Mon, 3 Apr 2017 18:53:04 +0000 [thread overview]
Message-ID: <20170403185306.36164-3-git@jeffhostetler.com> (raw)
In-Reply-To: <20170403185306.36164-1-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>
Teach fsck to override core.checksumindex and always verify
the index checksum when reading the index.
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
builtin/fsck.c | 1 +
cache.h | 7 +++++++
read-cache.c | 20 +++++++++++++-------
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 1a5cacc..6913233 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -771,6 +771,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
}
if (keep_cache_objects) {
+ force_core_checksum_index = 1;
read_cache();
for (i = 0; i < active_nr; i++) {
unsigned int mode;
diff --git a/cache.h b/cache.h
index 80b6372..3ebda0a 100644
--- a/cache.h
+++ b/cache.h
@@ -685,6 +685,13 @@ extern void update_index_if_able(struct index_state *, struct lock_file *);
extern int hold_locked_index(struct lock_file *, int);
extern void set_alternate_index_output(const char *);
+/*
+ * Override "core.checksumindex" config settings. Allows commands
+ * like "fsck" to force it without altering on-disk settings in case
+ * routines call die() before it can be reset.
+ */
+extern int force_core_checksum_index;
+
/* Environment bits from configuration mechanism */
extern int trust_executable_bit;
extern int trust_ctime;
diff --git a/read-cache.c b/read-cache.c
index dd64cde..36fdc2a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1371,6 +1371,8 @@ struct ondisk_cache_entry_extended {
ondisk_cache_entry_extended_size(ce_namelen(ce)) : \
ondisk_cache_entry_size(ce_namelen(ce)))
+int force_core_checksum_index;
+
static int verify_hdr(struct cache_header *hdr, unsigned long size)
{
git_SHA_CTX c;
@@ -1384,13 +1386,17 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
if (hdr_version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < hdr_version)
return error("bad index version %d", hdr_version);
- /*
- * Since we run very early in command startup, git_config()
- * may not have been called yet and the various "core_*"
- * global variables haven't been set. So look it up
- * explicitly.
- */
- git_config_get_bool("core.checksumindex", &do_checksum);
+ if (force_core_checksum_index)
+ do_checksum = 1;
+ else {
+ /*
+ * Since we run very early in command startup, git_config()
+ * may not have been called yet and the various "core_*"
+ * global variables haven't been set. So look it up
+ * explicitly.
+ */
+ git_config_get_bool("core.checksumindex", &do_checksum);
+ }
if (!do_checksum)
return 0;
--
2.9.3
next prev parent reply other threads:[~2017-04-03 18:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-03 18:53 [PATCH v4 0/4] read-cache: call verify_hdr() in a background thread git
2017-04-03 18:53 ` [PATCH v4 1/4] read-cache: core.checksumindex git
2017-04-03 18:53 ` git [this message]
2017-04-03 20:31 ` [PATCH v4 2/4] fsck: force core.checksumindex=1 Ævar Arnfjörð Bjarmason
2017-04-04 2:29 ` Jeff King
2017-04-04 8:23 ` Ævar Arnfjörð Bjarmason
2017-04-04 8:27 ` Jeff King
2017-04-04 13:13 ` Jeff Hostetler
2017-04-04 20:18 ` Jeff King
2017-04-03 18:53 ` [PATCH v4 3/4] t1450-fsck: test core.checksumindex git
2017-04-03 18:53 ` [PATCH v4 4/4] p0002-read-cache: " git
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170403185306.36164-3-git@jeffhostetler.com \
--to=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).