Skip to content

Commit bdccf5e

Browse files
committed
Merge branch 'jt/fetch-pack-loosen-validation-with-packfile-uri'
Bugfix for "git fetch" when the packfile URI capability is in use. * jt/fetch-pack-loosen-validation-with-packfile-uri: fetch-pack: make packfile URIs work with transfer.fsckobjects fetch-pack: document only_packfile in get_pack() (various): document from_promisor parameter
2 parents 3cbff01 + 0bd96be commit bdccf5e

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

fetch-pack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ static void write_promisor_file(const char *keep_name,
794794
strbuf_release(&promisor_name);
795795
}
796796

797+
/*
798+
* Pass 1 as "only_packfile" if the pack received is the only pack in this
799+
* fetch request (that is, if there were no packfile URIs provided).
800+
*/
797801
static int get_pack(struct fetch_pack_args *args,
798802
int xd[2], struct string_list *pack_lockfiles,
799803
int only_packfile,
@@ -895,7 +899,7 @@ static int get_pack(struct fetch_pack_args *args,
895899
: transfer_fsck_objects >= 0
896900
? transfer_fsck_objects
897901
: 0) {
898-
if (args->from_promisor)
902+
if (args->from_promisor || !only_packfile)
899903
/*
900904
* We cannot use --strict in index-pack because it
901905
* checks both broken objects and links, but we only

fetch-pack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ struct fetch_pack_args {
4040
unsigned cloning:1;
4141
unsigned update_shallow:1;
4242
unsigned deepen:1;
43+
44+
/*
45+
* Indicate that the remote of this request is a promisor remote. The
46+
* pack received does not need all referred-to objects to be present in
47+
* the local object store, and fetch-pack will store the pack received
48+
* together with a ".promisor" file indicating that the aforementioned
49+
* pack is a promisor pack.
50+
*/
4351
unsigned from_promisor:1;
4452

4553
/*

remote-curl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ struct options {
3939
/* One of the SEND_PACK_PUSH_CERT_* constants. */
4040
push_cert : 2,
4141
deepen_relative : 1,
42+
43+
/* see documentation of corresponding flag in fetch-pack.h */
4244
from_promisor : 1,
45+
4346
no_dependents : 1,
4447
atomic : 1,
4548
object_format : 1;

t/t5702-protocol-v2.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,59 @@ test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
883883
test_i18ngrep "pack downloaded from.*does not match expected hash" err
884884
'
885885

886+
test_expect_success 'packfile-uri with transfer.fsckobjects' '
887+
P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
888+
rm -rf "$P" http_child log &&
889+
890+
git init "$P" &&
891+
git -C "$P" config "uploadpack.allowsidebandall" "true" &&
892+
893+
echo my-blob >"$P/my-blob" &&
894+
git -C "$P" add my-blob &&
895+
git -C "$P" commit -m x &&
896+
897+
configure_exclusion "$P" my-blob >h &&
898+
899+
sane_unset GIT_TEST_SIDEBAND_ALL &&
900+
git -c protocol.version=2 -c transfer.fsckobjects=1 \
901+
-c fetch.uriprotocols=http,https \
902+
clone "$HTTPD_URL/smart/http_parent" http_child &&
903+
904+
# Ensure that there are exactly 4 files (2 .pack and 2 .idx).
905+
ls http_child/.git/objects/pack/* >filelist &&
906+
test_line_count = 4 filelist
907+
'
908+
909+
test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' '
910+
P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
911+
rm -rf "$P" http_child log &&
912+
913+
git init "$P" &&
914+
git -C "$P" config "uploadpack.allowsidebandall" "true" &&
915+
916+
cat >bogus-commit <<-EOF &&
917+
tree $EMPTY_TREE
918+
author Bugs Bunny 1234567890 +0000
919+
committer Bugs Bunny <[email protected]> 1234567890 +0000
920+
921+
This commit object intentionally broken
922+
EOF
923+
BOGUS=$(git -C "$P" hash-object -t commit -w --stdin <bogus-commit) &&
924+
git -C "$P" branch bogus-branch "$BOGUS" &&
925+
926+
echo my-blob >"$P/my-blob" &&
927+
git -C "$P" add my-blob &&
928+
git -C "$P" commit -m x &&
929+
930+
configure_exclusion "$P" my-blob >h &&
931+
932+
sane_unset GIT_TEST_SIDEBAND_ALL &&
933+
test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
934+
-c fetch.uriprotocols=http,https \
935+
clone "$HTTPD_URL/smart/http_parent" http_child 2>error &&
936+
test_i18ngrep "invalid author/committer line - missing email" error
937+
'
938+
886939
# DO NOT add non-httpd-specific tests here, because the last part of this
887940
# test script is only executed when httpd is available and enabled.
888941

transport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ struct git_transport_options {
1515
unsigned self_contained_and_connected : 1;
1616
unsigned update_shallow : 1;
1717
unsigned deepen_relative : 1;
18+
19+
/* see documentation of corresponding flag in fetch-pack.h */
1820
unsigned from_promisor : 1;
21+
1922
unsigned no_dependents : 1;
2023

2124
/*

0 commit comments

Comments
 (0)