bundle-uri: quiet failed unbundlings

When downloading a list of bundles in "all" mode, Git has no understanding of the dependencies between the bundles. Git attempts to unbundle the bundles in some order, but some may not pass the verify_bundle() step because of missing prerequisites. This is passed as error messages to the user, even when they eventually succeed in later attempts after their dependent bundles are unbundled. Add a new VERIFY_BUNDLE_QUIET flag to verify_bundle() that avoids the error messages from the missing prerequisite commits. The method still returns the number of missing prerequisit commits, allowing callers to unbundle() to notice that the bundle failed to apply. Use this flag in bundle-uri.c and test that the messages go away for 'git clone --bundle-uri' commands. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Oct 12, 2022 at 12:52 UTC 70334fc3ebf1c6199014d82bbbf0595b64a8fa90
5 files changed +32 -9
builtin/bundle.c
+1 -1
@@ -120,7 +120,7 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
120 }
121 close(bundle_fd);
122 if (verify_bundle(the_repository, &header,
123 - quiet ? 0 : VERIFY_BUNDLE_VERBOSE)) {
123 + quiet ? VERIFY_BUNDLE_QUIET : VERIFY_BUNDLE_VERBOSE)) {
124 ret = 1;
125 goto cleanup;
126 }
bundle-uri.c
+2 -1
@@ -308,7 +308,8 @@ static int unbundle_from_file(struct repository *r, const char *file)
308 * a reachable ref pointing to the new tips, which will reach
309 * the prerequisite commits.
310 */
311 - if ((result = unbundle(r, &header, bundle_fd, NULL, 0)))
311 + if ((result = unbundle(r, &header, bundle_fd, NULL,
312 + VERIFY_BUNDLE_QUIET)))
313 return 1;
314
315 /*
bundle.c
+8 -2
@@ -216,7 +216,10 @@ int verify_bundle(struct repository *r,
216 add_pending_object(&revs, o, name);
217 continue;
218 }
219 - if (++ret == 1)
219 + ret++;
220 + if (flags & VERIFY_BUNDLE_QUIET)
221 + continue;
222 + if (ret == 1)
223 error("%s", message);
224 error("%s %s", oid_to_hex(oid), name);
225 }
@@ -243,7 +246,10 @@ int verify_bundle(struct repository *r,
246 assert(o); /* otherwise we'd have returned early */
247 if (o->flags & SHOWN)
248 continue;
246 - if (++ret == 1)
249 + ret++;
250 + if (flags & VERIFY_BUNDLE_QUIET)
251 + continue;
252 + if (ret == 1)
253 error("%s", message);
254 error("%s %s", oid_to_hex(oid), name);
255 }
bundle.h
+1
@@ -32,6 +32,7 @@ int create_bundle(struct repository *r, const char *path,
32
33 enum verify_bundle_flags {
34 VERIFY_BUNDLE_VERBOSE = (1 << 0),
35 + VERIFY_BUNDLE_QUIET = (1 << 1),
36 };
37
38 int verify_bundle(struct repository *r, struct bundle_header *header,
t/t5558-clone-bundle-uri.sh
+20 -5
@@ -99,7 +99,10 @@ test_expect_success 'clone bundle list (file, no heuristic)' '
99 uri = file://$(pwd)/clone-from/bundle-4.bundle
100 EOF
101
102 - git clone --bundle-uri="file://$(pwd)/bundle-list" clone-from clone-list-file &&
102 + git clone --bundle-uri="file://$(pwd)/bundle-list" \
103 + clone-from clone-list-file 2>err &&
104 + ! grep "Repository lacks these prerequisite commits" err &&
105 +
106 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
107 git -C clone-list-file cat-file --batch-check <oids &&
108
@@ -141,7 +144,10 @@ test_expect_success 'clone bundle list (file, all mode, some failures)' '
144 EOF
145
146 GIT_TRACE2_PERF=1 \
144 - git clone --bundle-uri="file://$(pwd)/bundle-list" clone-from clone-all-some &&
147 + git clone --bundle-uri="file://$(pwd)/bundle-list" \
148 + clone-from clone-all-some 2>err &&
149 + ! grep "Repository lacks these prerequisite commits" err &&
150 +
151 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
152 git -C clone-all-some cat-file --batch-check <oids &&
153
@@ -169,7 +175,10 @@ test_expect_success 'clone bundle list (file, all mode, all failures)' '
175 uri = file://$(pwd)/clone-from/bundle-5.bundle
176 EOF
177
172 - git clone --bundle-uri="file://$(pwd)/bundle-list" clone-from clone-all-fail &&
178 + git clone --bundle-uri="file://$(pwd)/bundle-list" \
179 + clone-from clone-all-fail 2>err &&
180 + ! grep "Repository lacks these prerequisite commits" err &&
181 +
182 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
183 git -C clone-all-fail cat-file --batch-check <oids &&
184
@@ -195,7 +204,10 @@ test_expect_success 'clone bundle list (file, any mode)' '
204 uri = file://$(pwd)/clone-from/bundle-5.bundle
205 EOF
206
198 - git clone --bundle-uri="file://$(pwd)/bundle-list" clone-from clone-any-file &&
207 + git clone --bundle-uri="file://$(pwd)/bundle-list" \
208 + clone-from clone-any-file 2>err &&
209 + ! grep "Repository lacks these prerequisite commits" err &&
210 +
211 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
212 git -C clone-any-file cat-file --batch-check <oids &&
213
@@ -284,7 +296,10 @@ test_expect_success 'clone bundle list (HTTP, no heuristic)' '
296 uri = $HTTPD_URL/bundle-4.bundle
297 EOF
298
287 - git clone --bundle-uri="$HTTPD_URL/bundle-list" clone-from clone-list-http &&
299 + git clone --bundle-uri="$HTTPD_URL/bundle-list" \
300 + clone-from clone-list-http 2>err &&
301 + ! grep "Repository lacks these prerequisite commits" err &&
302 +
303 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
304 git -C clone-list-http cat-file --batch-check <oids
305 '