From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Luc Van Oostenryck" <luc.vanoostenryck@gmail.com>,
git@vger.kernel.org, "Kevin Willford" <kewillf@microsoft.com>
Subject: Re: [BUG] index corruption with git commit -p
Date: Sun, 2 Sep 2018 09:12:04 +0200 [thread overview]
Message-ID: <20180902071204.GA2868@duynguyen.home> (raw)
In-Reply-To: <20180902050803.GA21324@sigill.intra.peff.net>
On Sun, Sep 02, 2018 at 01:08:03AM -0400, Jeff King wrote:
> On Sun, Sep 02, 2018 at 12:17:53AM +0200, Ævar Arnfjörð Bjarmason wrote:
>
> > > Here are the steps to reproduce it:
> > > $ git clone git://github.com/lucvoo/sparse-dev.git <somedir>
> > > $ cd <somedir>
> > > $ git co index-corruption
> > > $ git rm -r validation/ Documentation/
> > > $ git commit -m <some message> -p
> > > $ git status
> > > error: index uses $?+? extension, which we do not understand
> > > fatal: index file corrupt
> > >
> > > The 'extension' pattern '$?+?', can vary a bit, sometimes
> > > it's just '????', but always seems 4 chars.
> > > If the commit command doesn't use the '-p' flag, there is no
> > > problem. The repository itself is not corrupted, it's only
> > > the index. It happends with git 2.18.0 and 2.17.0
> >
> > Yeah this is a bug, I didn't dig much but testing with this script down
> > to 2.8.0:
> > [...]
> > I found that the first bad commit was: 680ee550d7 ("commit: skip
> > discarding the index if there is no pre-commit hook", 2017-08-14)
>
> I think it's much older than that. I set up my test repo like this:
>
> git clone git://github.com/lucvoo/sparse-dev.git
> cd sparse-dev
> git checkout --detach
>
> and then bisected with this script:
>
> cd /path/to/sparse-dev
> rm .git/index
> git reset --hard index-corruption &&
> git rm -q -r validation/ Documentation/ &&
> git commit -qm foo -p &&
> git status
>
> Since a33fc72fe9 (read-cache: force_verify_index_checksum, 2017-04-14),
> that produces the corrupt extension error. But before that, I
> consistently get:
>
> error: bad index file sha1 signature
> fatal: index file corrupt
>
> from git-commit. And that bisects back to 9c4d6c0297 (cache-tree: Write
> updated cache-tree after commit, 2014-07-13).
>
> If I revert that commit (which takes some untangling, see below), then
> the problem seems to go away. Here's the patch I tried on top of the
> current master, though I think it is actually the first hunk that is
> making the difference.
>
> ---
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 0d9828e29e..779c5e2cb5 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -359,13 +359,6 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
>
> discard_cache();
> read_cache_from(get_lock_file_path(&index_lock));
> - if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
> - if (reopen_lock_file(&index_lock) < 0)
> - die(_("unable to write index file"));
> - if (write_locked_index(&the_index, &index_lock, 0))
> - die(_("unable to update temporary index"));
> - } else
> - warning(_("Failed to update main cache tree"));
>
Narrowing down to this does help. This patch seems to fix it to me. I
guess we have some leftover from the interactive add that should not
be there after we have written the new index.
diff --git a/builtin/commit.c b/builtin/commit.c
index 2be7bdb331..60f30b3780 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -432,6 +432,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
if (reopen_lock_file(&index_lock) < 0)
die(_("unable to write index file"));
+ ftruncate(index_lock.tempfile->fd, 0);
if (write_locked_index(&the_index, &index_lock, 0))
die(_("unable to update temporary index"));
} else
--
Duy
next prev parent reply other threads:[~2018-09-02 7:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-01 21:41 [BUG] index corruption with git commit -p Luc Van Oostenryck
2018-09-01 22:17 ` Ævar Arnfjörð Bjarmason
2018-09-02 5:08 ` Jeff King
2018-09-02 7:12 ` Duy Nguyen [this message]
2018-09-02 7:24 ` Jeff King
2018-09-02 7:53 ` Luc Van Oostenryck
2018-09-02 8:02 ` Jeff King
2018-09-04 15:57 ` Junio C Hamano
2018-09-04 16:13 ` Duy Nguyen
2018-09-04 16:38 ` Jeff King
2018-09-04 23:36 ` [PATCH] reopen_tempfile(): truncate opened file Jeff King
2018-09-05 15:27 ` Duy Nguyen
2018-09-05 15:35 ` Jeff King
2018-09-05 15:39 ` Duy Nguyen
2018-09-05 15:48 ` Jeff King
2018-09-05 16:54 ` Junio C Hamano
2018-09-05 16:56 ` Jeff King
2018-09-05 17:01 ` Junio C Hamano
2018-09-05 18:48 ` Luc Van Oostenryck
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180902071204.GA2868@duynguyen.home \
--to=pclouds@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=kewillf@microsoft.com \
--cc=luc.vanoostenryck@gmail.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.
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 NNTP newsgroup(s).