for_each_alternate_ref: pass name/oid instead of ref struct
Breaking down the fields in the interface makes it easier to change the backend of for_each_alternate_ref to something that doesn't use "struct ref" internally. The only field that callers actually look at is the oid, anyway. The refname is kept in the interface as a plausible thing for future code to want. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 8, 2017 at 15:52 UTC
2429d63a46b141bb5006b8c1ea82e2d0163ab626
4 files changed
+14
-8
builtin/receive-pack.c
+4
-2
@@ -277,10 +277,12 @@ static int show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
277
return 0;
278
}
279
280
-static void collect_one_alternate_ref(const struct ref *ref, void *data)
280
+static void collect_one_alternate_ref(const char *refname,
281
+ const struct object_id *oid,
282
+ void *data)
283
{
284
struct sha1_array *sa = data;
283
- sha1_array_append(sa, ref->old_oid.hash);
285
+ sha1_array_append(sa, oid->hash);
286
}
287
288
static void write_head_info(void)
fetch-pack.c
+8
-4
@@ -253,9 +253,11 @@ static void send_request(struct fetch_pack_args *args,
253
write_or_die(fd, buf->buf, buf->len);
254
}
255
256
-static void insert_one_alternate_ref(const struct ref *ref, void *unused)
256
+static void insert_one_alternate_ref(const char *refname,
257
+ const struct object_id *oid,
258
+ void *unused)
259
{
258
- rev_list_insert_ref(NULL, ref->old_oid.hash);
260
+ rev_list_insert_ref(NULL, oid->hash);
261
}
262
263
#define INITIAL_FLUSH 16
@@ -619,9 +621,11 @@ static void filter_refs(struct fetch_pack_args *args,
621
*refs = newlist;
622
}
623
622
-static void mark_alternate_complete(const struct ref *ref, void *unused)
624
+static void mark_alternate_complete(const char *refname,
625
+ const struct object_id *oid,
626
+ void *unused)
627
{
624
- mark_complete(ref->old_oid.hash);
628
+ mark_complete(oid->hash);
629
}
630
631
static int everything_local(struct fetch_pack_args *args,
transport.c
+1
-1
@@ -1238,7 +1238,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
1238
for (extra = transport_get_remote_refs(transport);
1239
extra;
1240
extra = extra->next)
1241
- cb->fn(extra, cb->data);
1241
+ cb->fn(extra->name, &extra->old_oid, cb->data);
1242
transport_disconnect(transport);
1243
out:
1244
strbuf_release(&path);
transport.h
+1
-1
@@ -255,6 +255,6 @@ int transport_refs_pushed(struct ref *ref);
255
void transport_print_push_status(const char *dest, struct ref *refs,
256
int verbose, int porcelain, unsigned int *reject_reasons);
257
258
-typedef void alternate_ref_fn(const struct ref *, void *);
258
+typedef void alternate_ref_fn(const char *refname, const struct object_id *oid, void *);
259
extern void for_each_alternate_ref(alternate_ref_fn, void *);
260
#endif