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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Sep 12, 2018 at 08:47 UTC 8708ca09a67aeccab1d6852382cfd9267a8a395e
4 files changed +9 -19
fetch-object.c
+5 -11
@@ -23,21 +23,15 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
23 fetch_if_missing = original_fetch_if_missing;
24 }
25
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)
28 {
29 struct ref *ref = NULL;
30 int i;
31
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]);
35 new_ref->next = ref;
36 ref = new_ref;
37 }
fetch-object.h
+2 -6
@@ -1,11 +1,7 @@
1 #ifndef FETCH_OBJECT_H
2 #define FETCH_OBJECT_H
3
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);
6
7 #endif
sha1-file.c
+1 -1
@@ -1317,7 +1317,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
1317 * TODO Pass a repository struct through fetch_object,
1318 * such that arbitrary repositories work.
1319 */
1320 - fetch_object(repository_format_partial_clone, real->hash);
1320 + fetch_objects(repository_format_partial_clone, real, 1);
1321 already_retried = 1;
1322 continue;
1323 }
unpack-trees.c
+1 -1
@@ -392,7 +392,7 @@ static int check_updates(struct unpack_trees_options *o)
392 }
393 if (to_fetch.nr)
394 fetch_objects(repository_format_partial_clone,
395 - &to_fetch);
395 + to_fetch.oid, to_fetch.nr);
396 fetch_if_missing = fetch_if_missing_store;
397 oid_array_clear(&to_fetch);
398 }