From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/2] worktree: demonstrate a half-working workaround for auto-gc
Date: Wed, 8 Feb 2017 13:18:04 +0100 (CET) [thread overview]
Message-ID: <da25bfcebccdeb5ccdbf1f98027859f894fe5c25.1486556262.git.johannes.schindelin@gmx.de> (raw)
In-Reply-To: <cover.1486556262.git.johannes.schindelin@gmx.de>
While worktrees are marked "experimental", there is really no alternative
to using them when trying to work on multiple patch series in parallel.
Sadly, there is still a bug that causes irretrievable data loss caused by
worktree's incomplete handling of reflogs (and of the multiple indices of
the various worktrees), as this developer can testify a dozen times over.
In the --auto case, we can install a hook that runs before-hand,
accumulates all the worktree-specific refs and reflogs and installs them
into a very special reflog in the common refs namespace. The only
purpose of this stunt is to let gc pick up on those refs and reflogs, of
course, and *not* ignore them.
Unfortunately, this still does not address the "git gc" case, but
hopefully a real fix will be here some time soon.
Also, if there are simply too many loose objects for Git's liking, it will
kick off auto-gc (including the hook, which takes a couple of seconds to
run) that subsequently only says that it won't do anything, so the next
Git operation will kick off another auto-gc (including the multi-second
hook run).
Needless to say: this patch is not actually intended for inclusion, but
instead tries to demonstrate the pain and the dear need for a real bug fix
(and not another 8 months of buggy Git).
So here is hoping to a timely fix. Cheers.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
t/t6500-gc.sh | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index e24a4fb611..2f1e52825d 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -67,6 +67,30 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre
test_line_count = 2 new # There is one new pack and its .idx
'
+test_expect_success 'install pre-auto-gc hook for worktrees' '
+ mkdir -p .git/hooks &&
+ write_script .git/hooks/pre-auto-gc <<-\EOF
+ echo "Preserving refs/reflogs of worktrees" >&2 &&
+ dir="$(git rev-parse --git-common-dir)" &&
+ refsdir="$dir/logs/refs" &&
+ rm -f "$refsdir"/preserve &&
+ ident="$(GIT_COMMITTER_DATE= git var GIT_COMMITTER_IDENT)" &&
+ (
+ find "$dir"/logs "$dir"/worktrees/*/logs \
+ -type f -exec cat {} \; |
+ cut -d" " -f1
+ find "$dir"/HEAD "$dir"/worktrees/*/HEAD "$dir"/refs \
+ "$dir"/worktrees/*/refs -type f -exec cat {} \; |
+ grep -v "^ref:"
+ ) 2>/dev/null |
+ sort |
+ uniq |
+ sed "s/.*/& & $ident dummy/" >"$dir"/preserve &&
+ mkdir -p "$refsdir" &&
+ mv "$dir"/preserve "$refsdir"/
+ EOF
+'
+
trigger_auto_gc () {
# This is unfortunately very, very ugly
gdir="$(git rev-parse --git-common-dir)" &&
@@ -76,7 +100,7 @@ trigger_auto_gc () {
git -c gc.auto=1 -c gc.pruneexpire=now -c gc.autodetach=0 gc --auto
}
-test_expect_failure 'gc respects refs/reflogs in all worktrees' '
+test_expect_success 'gc respects refs/reflogs in all worktrees' '
test_commit something &&
git worktree add worktree &&
(
--
2.11.1.windows.1
next prev parent reply other threads:[~2017-02-08 12:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-08 12:17 [PATCH 0/2] Demonstrate a critical worktree/gc bug Johannes Schindelin
2017-02-08 12:17 ` [PATCH 1/2] worktree: demonstrate data lost to auto-gc Johannes Schindelin
2017-02-08 12:18 ` Johannes Schindelin [this message]
2017-02-08 12:28 ` [PATCH 0/2] Demonstrate a critical worktree/gc bug Duy Nguyen
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=da25bfcebccdeb5ccdbf1f98027859f894fe5c25.1486556262.git.johannes.schindelin@gmx.de \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/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).