Skip to content

Commit 63d903f

Browse files
blanetgitster
authored andcommitted
unbundle: extend object verification for fetches
The existing fetch.fsckObjects and transfer.fsckObjects configurations were not fully applied to bundle-involved fetches, including direct bundle fetches and bundle-uri enabled fetches. Furthermore, there was no object verification support for unbundle. This commit extends object verification support in `bundle.c:unbundle` by adding the `VERIFY_BUNDLE_FSCK` option to `verify_bundle_flags`. When this option is enabled, we append the `--fsck-objects` flag to `git-index-pack`. The `VERIFY_BUNDLE_FSCK` option is now used by bundle-involved fetches, where we use `fetch-pack.c:fetch_pack_fsck_objects` to determine whether to enable this option for `bundle.c:unbundle`, specifically in: - `transport.c:fetch_refs_from_bundle` for direct bundle fetches. - `bundle-uri.c:unbundle_from_file` for bundle-uri enabled fetches. This addition ensures a consistent logic for object verification during fetches. Tests have been added to confirm functionality in the scenarios mentioned above. Reviewed-by: Patrick Steinhardt <[email protected]> Signed-off-by: Xing Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0cbc75 commit 63d903f

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

bundle-uri.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "hashmap.h"
1010
#include "pkt-line.h"
1111
#include "config.h"
12+
#include "fetch-pack.h"
1213
#include "remote.h"
1314

1415
static struct {
@@ -373,7 +374,7 @@ static int unbundle_from_file(struct repository *r, const char *file)
373374
* the prerequisite commits.
374375
*/
375376
if ((result = unbundle(r, &header, bundle_fd, NULL,
376-
VERIFY_BUNDLE_QUIET)))
377+
VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0))))
377378
return 1;
378379

379380
/*

bundle.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ int unbundle(struct repository *r, struct bundle_header *header,
625625
if (header->filter.choice)
626626
strvec_push(&ip.args, "--promisor=from-bundle");
627627

628+
if (flags & VERIFY_BUNDLE_FSCK)
629+
strvec_push(&ip.args, "--fsck-objects");
630+
628631
if (extra_index_pack_args) {
629632
strvec_pushv(&ip.args, extra_index_pack_args->v);
630633
strvec_clear(extra_index_pack_args);

bundle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int create_bundle(struct repository *r, const char *path,
3333
enum verify_bundle_flags {
3434
VERIFY_BUNDLE_VERBOSE = (1 << 0),
3535
VERIFY_BUNDLE_QUIET = (1 << 1),
36+
VERIFY_BUNDLE_FSCK = (1 << 2),
3637
};
3738

3839
int verify_bundle(struct repository *r, struct bundle_header *header,

t/t5558-clone-bundle-uri.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,22 @@ test_expect_success 'create bundle' '
3636
sed -e "/^$/q" -e "s/$commit_a /$commit_b /" \
3737
<A.bundle >bad-header.bundle &&
3838
convert_bundle_to_pack \
39-
<A.bundle >>bad-header.bundle
39+
<A.bundle >>bad-header.bundle &&
40+
41+
tree_b=$(git rev-parse B^{tree}) &&
42+
cat >data <<-EOF &&
43+
tree $tree_b
44+
parent $commit_b
45+
author A U Thor
46+
committer A U Thor
47+
48+
commit: this is a commit with bad emails
49+
50+
EOF
51+
bad_commit=$(git hash-object --literally -t commit -w --stdin <data) &&
52+
git branch bad $bad_commit &&
53+
git bundle create bad-object.bundle bad &&
54+
git update-ref -d refs/heads/bad
4055
)
4156
'
4257

@@ -58,6 +73,23 @@ test_expect_success 'clone with bundle that has bad header' '
5873
test_grep ! "refs/bundles/" refs
5974
'
6075

76+
test_expect_success 'clone with bundle that has bad object' '
77+
# Unbundle succeeds if no fsckObjects configured.
78+
git clone --bundle-uri="clone-from/bad-object.bundle" \
79+
clone-from clone-bad-object-no-fsck &&
80+
git -C clone-bad-object-no-fsck for-each-ref --format="%(refname)" >refs &&
81+
grep "refs/bundles/" refs >actual &&
82+
test_write_lines refs/bundles/bad >expect &&
83+
test_cmp expect actual &&
84+
85+
# Unbundle fails with fsckObjects set true, but clone can still proceed.
86+
git -c fetch.fsckObjects=true clone --bundle-uri="clone-from/bad-object.bundle" \
87+
clone-from clone-bad-object-fsck 2>err &&
88+
test_grep "missingEmail" err &&
89+
git -C clone-bad-object-fsck for-each-ref --format="%(refname)" >refs &&
90+
test_grep ! "refs/bundles/" refs
91+
'
92+
6193
test_expect_success 'clone with path bundle and non-default hash' '
6294
test_when_finished "rm -rf clone-path-non-default-hash" &&
6395
GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="clone-from/B.bundle" \

t/t5607-clone-bundle.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ test_expect_success 'fetch SHA-1 from bundle' '
138138
git fetch --no-tags foo/tip.bundle "$(cat hash)"
139139
'
140140

141+
test_expect_success 'clone bundle with different fsckObjects configurations' '
142+
test_create_repo bundle-fsck &&
143+
(
144+
cd bundle-fsck &&
145+
test_commit A &&
146+
commit_a=$(git rev-parse A) &&
147+
tree_a=$(git rev-parse A^{tree}) &&
148+
cat >data <<-EOF &&
149+
tree $tree_a
150+
parent $commit_a
151+
author A U Thor
152+
committer A U Thor
153+
154+
commit: this is a commit with bad emails
155+
156+
EOF
157+
bad_commit=$(git hash-object --literally -t commit -w --stdin <data) &&
158+
git branch bad $bad_commit &&
159+
git bundle create bad.bundle bad
160+
) &&
161+
162+
git clone bundle-fsck/bad.bundle bundle-no-fsck &&
163+
164+
git -c fetch.fsckObjects=false -c transfer.fsckObjects=true \
165+
clone bundle-fsck/bad.bundle bundle-fetch-no-fsck &&
166+
167+
test_must_fail git -c fetch.fsckObjects=true \
168+
clone bundle-fsck/bad.bundle bundle-fetch-fsck 2>err &&
169+
test_grep "missingEmail" err &&
170+
171+
test_must_fail git -c transfer.fsckObjects=true \
172+
clone bundle-fsck/bad.bundle bundle-transfer-fsck 2>err &&
173+
test_grep "missingEmail" err
174+
'
175+
141176
test_expect_success 'git bundle uses expected default format' '
142177
git bundle create bundle HEAD^.. &&
143178
cat >expect <<-EOF &&

transport.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
184184
if (!data->get_refs_from_bundle_called)
185185
get_refs_from_bundle_inner(transport);
186186
ret = unbundle(the_repository, &data->header, data->fd,
187-
&extra_index_pack_args, 0);
187+
&extra_index_pack_args,
188+
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
188189
transport->hash_algo = data->header.hash_algo;
189190
return ret;
190191
}

0 commit comments

Comments
 (0)