Skip to content

Commit 8708ca0

Browse files
jonathantanmygitster
authored andcommitted
fetch-object: unify fetch_object[s] functions
There are fetch_object() and fetch_objects() helpers in fetch-object.h; as the latter takes "struct oid_array", the former cannot be made into a thin wrapper around the latter without an extra allocation and set-up cost. Update fetch_objects() to take an array of "struct object_id" and number of elements in it as separate parameters, remove fetch_object(), and adjust all existing callers of these functions to use the new fetch_objects(). Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d4361b commit 8708ca0

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

fetch-object.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,15 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
2323
fetch_if_missing = original_fetch_if_missing;
2424
}
2525

26-
void fetch_object(const char *remote_name, const unsigned char *sha1)
27-
{
28-
struct ref *ref = alloc_ref(sha1_to_hex(sha1));
29-
hashcpy(ref->old_oid.hash, sha1);
30-
fetch_refs(remote_name, ref);
31-
}
32-
33-
void fetch_objects(const char *remote_name, const struct oid_array *to_fetch)
26+
void fetch_objects(const char *remote_name, const struct object_id *oids,
27+
int oid_nr)
3428
{
3529
struct ref *ref = NULL;
3630
int i;
3731

38-
for (i = 0; i < to_fetch->nr; i++) {
39-
struct ref *new_ref = alloc_ref(oid_to_hex(&to_fetch->oid[i]));
40-
oidcpy(&new_ref->old_oid, &to_fetch->oid[i]);
32+
for (i = 0; i < oid_nr; i++) {
33+
struct ref *new_ref = alloc_ref(oid_to_hex(&oids[i]));
34+
oidcpy(&new_ref->old_oid, &oids[i]);
4135
new_ref->next = ref;
4236
ref = new_ref;
4337
}

fetch-object.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#ifndef FETCH_OBJECT_H
22
#define FETCH_OBJECT_H
33

4-
#include "sha1-array.h"
5-
6-
extern void fetch_object(const char *remote_name, const unsigned char *sha1);
7-
8-
extern void fetch_objects(const char *remote_name,
9-
const struct oid_array *to_fetch);
4+
void fetch_objects(const char *remote_name, const struct object_id *oids,
5+
int oid_nr);
106

117
#endif

sha1-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
13171317
* TODO Pass a repository struct through fetch_object,
13181318
* such that arbitrary repositories work.
13191319
*/
1320-
fetch_object(repository_format_partial_clone, real->hash);
1320+
fetch_objects(repository_format_partial_clone, real, 1);
13211321
already_retried = 1;
13221322
continue;
13231323
}

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int check_updates(struct unpack_trees_options *o)
392392
}
393393
if (to_fetch.nr)
394394
fetch_objects(repository_format_partial_clone,
395-
&to_fetch);
395+
to_fetch.oid, to_fetch.nr);
396396
fetch_if_missing = fetch_if_missing_store;
397397
oid_array_clear(&to_fetch);
398398
}

0 commit comments

Comments
 (0)