Skip to content

Commit db7ed74

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 274b9cc commit db7ed74

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
13681368
continue;
13691369
oid_array_append(&to_fetch, &d->oid);
13701370
}
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);
13741373
oid_array_clear(&to_fetch);
13751374
}
13761375

diff.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6517,12 +6517,11 @@ void diffcore_std(struct diff_options *options)
65176517
add_if_missing(options->repo, &to_fetch, p->one);
65186518
add_if_missing(options->repo, &to_fetch, p->two);
65196519
}
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);
65266525
oid_array_clear(&to_fetch);
65276526
}
65286527

promisor-remote.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ int promisor_remote_get_direct(struct repository *repo,
241241
int to_free = 0;
242242
int res = -1;
243243

244+
if (oid_nr == 0)
245+
return 0;
246+
244247
promisor_remote_init();
245248

246249
for (r = promisors; r; r = r->next) {

promisor-remote.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ struct promisor_remote {
2020
void promisor_remote_reinit(void);
2121
struct promisor_remote *promisor_remote_find(const char *remote_name);
2222
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+
*/
2331
int promisor_remote_get_direct(struct repository *repo,
2432
const struct object_id *oids,
2533
int oid_nr);

unpack-trees.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,8 @@ static int check_updates(struct unpack_trees_options *o)
422422
continue;
423423
oid_array_append(&to_fetch, &ce->oid);
424424
}
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);
428427
oid_array_clear(&to_fetch);
429428
}
430429
for (i = 0; i < index->cache_nr; i++) {

0 commit comments

Comments
 (0)