@matheusbsbs / matheus-bagliano / commits / db7ed7418b
Fork 0

promisor-remote: accept 0 as oid_nr in function

There are 3 callers to promisor_remote_get_direct() that first check if the number of objects to be fetched is equal to 0. Fold that check into promisor_remote_get_direct(), and in doing so, be explicit as to what promisor_remote_get_direct() does if oid_nr is 0 (it returns 0, success, immediately). Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Apr 2, 2020 at 12:19 UTC db7ed7418b3702ab2b2df755764c3f452917a890
5 files changed +20 -12
builtin/index-pack.c
+2 -3
@@ -1368,9 +1368,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
1368 continue;
1369 oid_array_append(&to_fetch, &d->oid);
1370 }
1371 - if (to_fetch.nr)
1372 - promisor_remote_get_direct(the_repository,
1373 - to_fetch.oid, to_fetch.nr);
1371 + promisor_remote_get_direct(the_repository,
1372 + to_fetch.oid, to_fetch.nr);
1373 oid_array_clear(&to_fetch);
1374 }
1375
diff.c
+5 -6
@@ -6517,12 +6517,11 @@ void diffcore_std(struct diff_options *options)
6517 add_if_missing(options->repo, &to_fetch, p->one);
6518 add_if_missing(options->repo, &to_fetch, p->two);
6519 }
6520 - if (to_fetch.nr)
6521 - /*
6522 - * NEEDSWORK: Consider deduplicating the OIDs sent.
6523 - */
6524 - promisor_remote_get_direct(options->repo,
6525 - to_fetch.oid, to_fetch.nr);
6520 + /*
6521 + * NEEDSWORK: Consider deduplicating the OIDs sent.
6522 + */
6523 + promisor_remote_get_direct(options->repo,
6524 + to_fetch.oid, to_fetch.nr);
6525 oid_array_clear(&to_fetch);
6526 }
6527
promisor-remote.c
+3
@@ -241,6 +241,9 @@ int promisor_remote_get_direct(struct repository *repo,
241 int to_free = 0;
242 int res = -1;
243
244 + if (oid_nr == 0)
245 + return 0;
246 +
247 promisor_remote_init();
248
249 for (r = promisors; r; r = r->next) {
promisor-remote.h
+8
@@ -20,6 +20,14 @@ struct promisor_remote {
20 void promisor_remote_reinit(void);
21 struct promisor_remote *promisor_remote_find(const char *remote_name);
22 int has_promisor_remote(void);
23 +
24 +/*
25 + * Fetches all requested objects from all promisor remotes, trying them one at
26 + * a time until all objects are fetched. Returns 0 upon success, and non-zero
27 + * otherwise.
28 + *
29 + * If oid_nr is 0, this function returns 0 (success) immediately.
30 + */
31 int promisor_remote_get_direct(struct repository *repo,
32 const struct object_id *oids,
33 int oid_nr);
unpack-trees.c
+2 -3
@@ -422,9 +422,8 @@ static int check_updates(struct unpack_trees_options *o)
422 continue;
423 oid_array_append(&to_fetch, &ce->oid);
424 }
425 - if (to_fetch.nr)
426 - promisor_remote_get_direct(the_repository,
427 - to_fetch.oid, to_fetch.nr);
425 + promisor_remote_get_direct(the_repository,
426 + to_fetch.oid, to_fetch.nr);
427 oid_array_clear(&to_fetch);
428 }
429 for (i = 0; i < index->cache_nr; i++) {