Skip to content

Commit a2e618c

Browse files
committed
Merge branch 'jt/promisor-remote-fetch-tweak'
Remove error detection from a function that fetches from promisor remotes, and make it die when such a fetch fails to bring all the requested objects, to give an early failure to various operations. * jt/promisor-remote-fetch-tweak: promisor-remote: die upon failing fetch promisor-remote: remove a return value
2 parents 2790ba8 + 301f1e3 commit a2e618c

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

object-file.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,10 +1599,6 @@ static int do_oid_object_info_extended(struct repository *r,
15991599
if (fetch_if_missing && repo_has_promisor_remote(r) &&
16001600
!already_retried &&
16011601
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
1602-
/*
1603-
* TODO Investigate checking promisor_remote_get_direct()
1604-
* TODO return value and stopping on error here.
1605-
*/
16061602
promisor_remote_get_direct(r, real, 1);
16071603
already_retried = 1;
16081604
continue;

promisor-remote.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "config.h"
55
#include "transport.h"
66
#include "strvec.h"
7+
#include "packfile.h"
78

89
struct promisor_remote_config {
910
struct promisor_remote *promisors;
@@ -230,18 +231,18 @@ static int remove_fetched_oids(struct repository *repo,
230231
return remaining_nr;
231232
}
232233

233-
int promisor_remote_get_direct(struct repository *repo,
234-
const struct object_id *oids,
235-
int oid_nr)
234+
void promisor_remote_get_direct(struct repository *repo,
235+
const struct object_id *oids,
236+
int oid_nr)
236237
{
237238
struct promisor_remote *r;
238239
struct object_id *remaining_oids = (struct object_id *)oids;
239240
int remaining_nr = oid_nr;
240241
int to_free = 0;
241-
int res = -1;
242+
int i;
242243

243244
if (oid_nr == 0)
244-
return 0;
245+
return;
245246

246247
promisor_remote_init(repo);
247248

@@ -256,12 +257,16 @@ int promisor_remote_get_direct(struct repository *repo,
256257
continue;
257258
}
258259
}
259-
res = 0;
260-
break;
260+
goto all_fetched;
261261
}
262262

263+
for (i = 0; i < remaining_nr; i++) {
264+
if (is_promisor_object(&remaining_oids[i]))
265+
die(_("could not fetch %s from promisor remote"),
266+
oid_to_hex(&remaining_oids[i]));
267+
}
268+
269+
all_fetched:
263270
if (to_free)
264271
free(remaining_oids);
265-
266-
return res;
267272
}

promisor-remote.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ static inline int has_promisor_remote(void)
3939

4040
/*
4141
* Fetches all requested objects from all promisor remotes, trying them one at
42-
* a time until all objects are fetched. Returns 0 upon success, and non-zero
43-
* otherwise.
42+
* a time until all objects are fetched.
4443
*
45-
* If oid_nr is 0, this function returns 0 (success) immediately.
44+
* If oid_nr is 0, this function returns immediately.
4645
*/
47-
int promisor_remote_get_direct(struct repository *repo,
48-
const struct object_id *oids,
49-
int oid_nr);
46+
void promisor_remote_get_direct(struct repository *repo,
47+
const struct object_id *oids,
48+
int oid_nr);
5049

5150
#endif /* PROMISOR_REMOTE_H */

t/t0410-partial-clone.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ test_expect_success 'fetching of missing objects' '
215215
grep "$HASH" out
216216
'
217217

218+
test_expect_success 'fetching of a promised object that promisor remote no longer has' '
219+
rm -f err &&
220+
test_create_repo unreliable-server &&
221+
git -C unreliable-server config uploadpack.allowanysha1inwant 1 &&
222+
git -C unreliable-server config uploadpack.allowfilter 1 &&
223+
test_commit -C unreliable-server foo &&
224+
225+
git clone --filter=blob:none --no-checkout "file://$(pwd)/unreliable-server" unreliable-client &&
226+
227+
rm -rf unreliable-server/.git/objects/* &&
228+
test_must_fail git -C unreliable-client checkout HEAD 2>err &&
229+
grep "could not fetch.*from promisor remote" err
230+
'
231+
218232
test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
219233
# ref-in-want requires protocol version 2
220234
git -C server config protocol.version 2 &&

0 commit comments

Comments
 (0)