Make sure quickfetch is not fooled with a previous, incomplete fetch.
This updates git-rev-list --objects to be a bit more careful
when listing a blob object to make sure the blob actually
exists, and uses it to make sure the quick-fetch optimization we
introduced earlier is not fooled by a previous incomplete fetch.
The quick-fetch optimization works by running this command:
git rev-list --objects <<commit-list>> --not --all
where <<commit-list>> is a list of commits that we are going to
fetch from the other side. If there is any object missing to
complete the <<commit-list>>, the rev-list would fail and die
(say, the commit was in our repository, but its tree wasn't --
then it will barf while trying to list the blobs the tree
contains because it cannot read that tree).
Usually we do not have the objects (otherwise why would we
fetching?), but in one important special case we do: when the
remote repository is used as an alternate object store
(i.e. pointed by .git/objects/info/alternates). We could check
.git/objects/info/alternates to see if the remote we are
interacting with is one of them (or is used as an alternate,
recursively, by one of them), but that check is more cumbersome
than it is worth.
The above check however did not catch missing blob, because
object listing code did not read nor check blob objects, knowing
that blobs do not contain any further references to other
objects. This commit fixes it with practically unmeasurable
overhead.
I've benched this with
git rev-list --objects --all >/dev/null
in the kernel repository, with three different implementations
of the "check-blob".
- Checking with has_sha1_file() has negligible (unmeasurable)
performance penalty.
- Checking with sha1_object_info() makes it somewhat slower,
perhaps by 5%.
- Checking with read_sha1_file() to cause a fully re-validation
is prohibitively expensive (about 4 times as much runtime).
In my original patch, I had this as a command line option, but
the overhead is small enough that it is not really worth it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-16 15:42:29 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='test quickfetch from local'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
test_tick &&
|
|
|
|
echo ichi >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m initial &&
|
|
|
|
|
|
|
|
cnt=$( (
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
test $cnt -eq 3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone without alternate' '
|
|
|
|
|
|
|
|
(
|
|
|
|
mkdir cloned &&
|
|
|
|
cd cloned &&
|
|
|
|
git init-db &&
|
|
|
|
git remote add -f origin ..
|
|
|
|
) &&
|
|
|
|
cnt=$( (
|
|
|
|
cd cloned &&
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
test $cnt -eq 3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'further commits in the original' '
|
|
|
|
|
|
|
|
test_tick &&
|
|
|
|
echo ni >file &&
|
|
|
|
git commit -a -m second &&
|
|
|
|
|
|
|
|
cnt=$( (
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
test $cnt -eq 6
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'copy commit and tree but not blob by hand' '
|
|
|
|
|
|
|
|
git rev-list --objects HEAD |
|
|
|
|
git pack-objects --stdout |
|
|
|
|
(
|
|
|
|
cd cloned &&
|
|
|
|
git unpack-objects
|
|
|
|
) &&
|
|
|
|
|
|
|
|
cnt=$( (
|
|
|
|
cd cloned &&
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
2010-10-31 09:46:54 +08:00
|
|
|
test $cnt -eq 6 &&
|
Make sure quickfetch is not fooled with a previous, incomplete fetch.
This updates git-rev-list --objects to be a bit more careful
when listing a blob object to make sure the blob actually
exists, and uses it to make sure the quick-fetch optimization we
introduced earlier is not fooled by a previous incomplete fetch.
The quick-fetch optimization works by running this command:
git rev-list --objects <<commit-list>> --not --all
where <<commit-list>> is a list of commits that we are going to
fetch from the other side. If there is any object missing to
complete the <<commit-list>>, the rev-list would fail and die
(say, the commit was in our repository, but its tree wasn't --
then it will barf while trying to list the blobs the tree
contains because it cannot read that tree).
Usually we do not have the objects (otherwise why would we
fetching?), but in one important special case we do: when the
remote repository is used as an alternate object store
(i.e. pointed by .git/objects/info/alternates). We could check
.git/objects/info/alternates to see if the remote we are
interacting with is one of them (or is used as an alternate,
recursively, by one of them), but that check is more cumbersome
than it is worth.
The above check however did not catch missing blob, because
object listing code did not read nor check blob objects, knowing
that blobs do not contain any further references to other
objects. This commit fixes it with practically unmeasurable
overhead.
I've benched this with
git rev-list --objects --all >/dev/null
in the kernel repository, with three different implementations
of the "check-blob".
- Checking with has_sha1_file() has negligible (unmeasurable)
performance penalty.
- Checking with sha1_object_info() makes it somewhat slower,
perhaps by 5%.
- Checking with read_sha1_file() to cause a fully re-validation
is prohibitively expensive (about 4 times as much runtime).
In my original patch, I had this as a command line option, but
the overhead is small enough that it is not really worth it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-16 15:42:29 +08:00
|
|
|
|
|
|
|
blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") &&
|
|
|
|
test -f "cloned/.git/objects/$blob" &&
|
|
|
|
rm -f "cloned/.git/objects/$blob" &&
|
|
|
|
|
|
|
|
cnt=$( (
|
|
|
|
cd cloned &&
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
test $cnt -eq 5
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'quickfetch should not leave a corrupted repository' '
|
|
|
|
|
|
|
|
(
|
|
|
|
cd cloned &&
|
|
|
|
git fetch
|
|
|
|
) &&
|
|
|
|
|
|
|
|
cnt=$( (
|
|
|
|
cd cloned &&
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
test $cnt -eq 6
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-11 15:29:47 +08:00
|
|
|
test_expect_success 'quickfetch should not copy from alternate' '
|
|
|
|
|
|
|
|
(
|
|
|
|
mkdir quickclone &&
|
|
|
|
cd quickclone &&
|
|
|
|
git init-db &&
|
|
|
|
(cd ../.git/objects && pwd) >.git/objects/info/alternates &&
|
|
|
|
git remote add origin .. &&
|
|
|
|
git fetch -k -k
|
|
|
|
) &&
|
|
|
|
obj_cnt=$( (
|
|
|
|
cd quickclone &&
|
|
|
|
git count-objects | sed -e "s/ *objects,.*//"
|
|
|
|
) ) &&
|
|
|
|
pck_cnt=$( (
|
|
|
|
cd quickclone &&
|
|
|
|
git count-objects -v | sed -n -e "/packs:/{
|
|
|
|
s/packs://
|
|
|
|
p
|
|
|
|
q
|
|
|
|
}"
|
|
|
|
) ) &&
|
|
|
|
origin_master=$( (
|
|
|
|
cd quickclone &&
|
|
|
|
git rev-parse origin/master
|
|
|
|
) ) &&
|
|
|
|
echo "loose objects: $obj_cnt, packfiles: $pck_cnt" &&
|
|
|
|
test $obj_cnt -eq 0 &&
|
|
|
|
test $pck_cnt -eq 0 &&
|
|
|
|
test z$origin_master = z$(git rev-parse master)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
quickfetch(): Prevent overflow of the rev-list command line
quickfetch() calls rev-list to check whether the objects we are about to
fetch are already present in the repo (if so, we can skip the object fetch).
However, when there are many (~1000) refs to be fetched, the rev-list
command line grows larger than the maximum command line size on some systems
(32K in Windows). This causes rev-list to fail, making quickfetch() return
non-zero, which unnecessarily triggers the transport machinery. This somehow
causes fetch to fail with an exit code.
By using the --stdin option to rev-list (and feeding the object list to its
standard input), we prevent the overflow of the rev-list command line,
which causes quickfetch(), and subsequently the overall fetch, to succeed.
However, using rev-list --stdin is not entirely straightforward: rev-list
terminates immediately when encountering an unknown object, which can
trigger SIGPIPE if we are still writing object's to its standard input.
We therefore temporarily ignore SIGPIPE so that the fetch process is not
terminated.
The patch also contains a testcase to verify the fix (note that before
the patch, the testcase would only fail on msysGit).
Signed-off-by: Johan Herland <johan@herland.net>
Improved-by: Johannes Sixt <j6t@kdbg.org>
Improved-by: Alex Riesen <raa.lkml@gmail.com>
Tested-by: Peter Krefting <peter@softwolves.pp.se>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-07-10 07:52:30 +08:00
|
|
|
test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
|
|
|
|
|
|
|
|
git gc &&
|
|
|
|
head=$(git rev-parse HEAD) &&
|
|
|
|
branchprefix="$head refs/heads/branch" &&
|
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9; do
|
|
|
|
for j in 0 1 2 3 4 5 6 7 8 9; do
|
|
|
|
for k in 0 1 2 3 4 5 6 7 8 9; do
|
|
|
|
echo "$branchprefix$i$j$k" >> .git/packed-refs
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done &&
|
|
|
|
(
|
|
|
|
cd cloned &&
|
|
|
|
git fetch &&
|
|
|
|
git fetch
|
|
|
|
)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
Make sure quickfetch is not fooled with a previous, incomplete fetch.
This updates git-rev-list --objects to be a bit more careful
when listing a blob object to make sure the blob actually
exists, and uses it to make sure the quick-fetch optimization we
introduced earlier is not fooled by a previous incomplete fetch.
The quick-fetch optimization works by running this command:
git rev-list --objects <<commit-list>> --not --all
where <<commit-list>> is a list of commits that we are going to
fetch from the other side. If there is any object missing to
complete the <<commit-list>>, the rev-list would fail and die
(say, the commit was in our repository, but its tree wasn't --
then it will barf while trying to list the blobs the tree
contains because it cannot read that tree).
Usually we do not have the objects (otherwise why would we
fetching?), but in one important special case we do: when the
remote repository is used as an alternate object store
(i.e. pointed by .git/objects/info/alternates). We could check
.git/objects/info/alternates to see if the remote we are
interacting with is one of them (or is used as an alternate,
recursively, by one of them), but that check is more cumbersome
than it is worth.
The above check however did not catch missing blob, because
object listing code did not read nor check blob objects, knowing
that blobs do not contain any further references to other
objects. This commit fixes it with practically unmeasurable
overhead.
I've benched this with
git rev-list --objects --all >/dev/null
in the kernel repository, with three different implementations
of the "check-blob".
- Checking with has_sha1_file() has negligible (unmeasurable)
performance penalty.
- Checking with sha1_object_info() makes it somewhat slower,
perhaps by 5%.
- Checking with read_sha1_file() to cause a fully re-validation
is prohibitively expensive (about 4 times as much runtime).
In my original patch, I had this as a command line option, but
the overhead is small enough that it is not really worth it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-16 15:42:29 +08:00
|
|
|
test_done
|