From 2b2a5be394bc67bed86bc009195c664dca740bd6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:28 +0000 Subject: each_ref_fn: change to take an object_id parameter Change typedef each_ref_fn to take a "const struct object_id *oid" parameter instead of "const unsigned char *sha1". To aid this transition, implement an adapter that can be used to wrap old-style functions matching the old typedef, which is now called "each_ref_sha1_fn"), and make such functions callable via the new interface. This requires the old function and its cb_data to be wrapped in a "struct each_ref_fn_sha1_adapter", and that object to be used as the cb_data for an adapter function, each_ref_fn_adapter(). This is an enormous diff, but most of it consists of simple, mechanical changes to the sites that call any of the "for_each_ref" family of functions. Subsequent to this change, the call sites can be rewritten one by one to use the new interface. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- upload-pack.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 745fda8515..52fab239ac 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -761,18 +761,26 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag, static void upload_pack(void) { struct string_list symref = STRING_LIST_INIT_DUP; + struct each_ref_fn_sha1_adapter wrapped_find_symref = + {find_symref, &symref}; - head_ref_namespaced(find_symref, &symref); + head_ref_namespaced(each_ref_fn_adapter, &wrapped_find_symref); if (advertise_refs || !stateless_rpc) { + struct each_ref_fn_sha1_adapter wrapped_send_ref = + {send_ref, &symref}; + reset_timeout(); - head_ref_namespaced(send_ref, &symref); - for_each_namespaced_ref(send_ref, &symref); + head_ref_namespaced(each_ref_fn_adapter, &wrapped_send_ref); + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_send_ref); advertise_shallow_grafts(1); packet_flush(1); } else { - head_ref_namespaced(check_ref, NULL); - for_each_namespaced_ref(check_ref, NULL); + struct each_ref_fn_sha1_adapter wrapped_check_ref = + {check_ref, NULL}; + + head_ref_namespaced(each_ref_fn_adapter, &wrapped_check_ref); + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_check_ref); } string_list_clear(&symref, 1); if (advertise_refs) -- cgit v1.2.3 From 7dabd05634154687f99b41c917a0d119e530814e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:10 +0000 Subject: find_symref(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- upload-pack.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 52fab239ac..96dbedc710 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -741,8 +741,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo return 0; } -static int find_symref(const char *refname, const unsigned char *sha1, int flag, - void *cb_data) +static int find_symref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { const char *symref_target; struct string_list_item *item; @@ -761,10 +761,8 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag, static void upload_pack(void) { struct string_list symref = STRING_LIST_INIT_DUP; - struct each_ref_fn_sha1_adapter wrapped_find_symref = - {find_symref, &symref}; - head_ref_namespaced(each_ref_fn_adapter, &wrapped_find_symref); + head_ref_namespaced(find_symref, &symref); if (advertise_refs || !stateless_rpc) { struct each_ref_fn_sha1_adapter wrapped_send_ref = -- cgit v1.2.3 From e45a4949a28ef26fb3f27dc8ad2ad676269a5ea5 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:11 +0000 Subject: find_symref(): convert local variable "unused" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- upload-pack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 96dbedc710..82680378b2 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -746,11 +746,11 @@ static int find_symref(const char *refname, const struct object_id *oid, { const char *symref_target; struct string_list_item *item; - unsigned char unused[20]; + struct object_id unused; if ((flag & REF_ISSYMREF) == 0) return 0; - symref_target = resolve_ref_unsafe(refname, 0, unused, &flag); + symref_target = resolve_ref_unsafe(refname, 0, unused.hash, &flag); if (!symref_target || (flag & REF_ISSYMREF) == 0) die("'%s' is a symref but it is not?", refname); item = string_list_append(cb_data, refname); -- cgit v1.2.3 From 363e98bfc27d810a0e41684b7744cc587c15c330 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:12 +0000 Subject: upload-pack: rewrite functions to take object_id arguments Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- upload-pack.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 82680378b2..929284f050 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -681,9 +681,9 @@ static void receive_needs(void) } /* return non-zero if the ref is hidden, otherwise 0 */ -static int mark_our_ref(const char *refname, const unsigned char *sha1) +static int mark_our_ref(const char *refname, const struct object_id *oid) { - struct object *o = lookup_unknown_object(sha1); + struct object *o = lookup_unknown_object(oid->hash); if (ref_is_hidden(refname)) { o->flags |= HIDDEN_REF; @@ -693,9 +693,10 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1) return 0; } -static int check_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int check_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { - mark_our_ref(refname, sha1); + mark_our_ref(refname, oid); return 0; } @@ -709,7 +710,8 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref) strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); } -static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int send_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { static const char *capabilities = "multi_ack thin-pack side-band" " side-band-64k ofs-delta shallow no-progress" @@ -717,7 +719,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo const char *refname_nons = strip_namespace(refname); unsigned char peeled[20]; - if (mark_our_ref(refname, sha1)) + if (mark_our_ref(refname, oid)) return 0; if (capabilities) { @@ -725,7 +727,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo format_symref_info(&symref_info, cb_data); packet_write(1, "%s %s%c%s%s%s%s agent=%s\n", - sha1_to_hex(sha1), refname_nons, + oid_to_hex(oid), refname_nons, 0, capabilities, allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "", stateless_rpc ? " no-done" : "", @@ -733,7 +735,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo git_user_agent_sanitized()); strbuf_release(&symref_info); } else { - packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons); + packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; if (!peel_ref(refname, peeled)) @@ -765,20 +767,14 @@ static void upload_pack(void) head_ref_namespaced(find_symref, &symref); if (advertise_refs || !stateless_rpc) { - struct each_ref_fn_sha1_adapter wrapped_send_ref = - {send_ref, &symref}; - reset_timeout(); - head_ref_namespaced(each_ref_fn_adapter, &wrapped_send_ref); - for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_send_ref); + head_ref_namespaced(send_ref, &symref); + for_each_namespaced_ref(send_ref, &symref); advertise_shallow_grafts(1); packet_flush(1); } else { - struct each_ref_fn_sha1_adapter wrapped_check_ref = - {check_ref, NULL}; - - head_ref_namespaced(each_ref_fn_adapter, &wrapped_check_ref); - for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_check_ref); + head_ref_namespaced(check_ref, NULL); + for_each_namespaced_ref(check_ref, NULL); } string_list_clear(&symref, 1); if (advertise_refs) -- cgit v1.2.3 From 21758affae79a23e402c46cb375a0fd0407050c9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:13 +0000 Subject: send_ref(): convert local variable "peeled" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- upload-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 929284f050..1cb9a948aa 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -717,7 +717,7 @@ static int send_ref(const char *refname, const struct object_id *oid, " side-band-64k ofs-delta shallow no-progress" " include-tag multi_ack_detailed"; const char *refname_nons = strip_namespace(refname); - unsigned char peeled[20]; + struct object_id peeled; if (mark_our_ref(refname, oid)) return 0; @@ -738,8 +738,8 @@ static int send_ref(const char *refname, const struct object_id *oid, packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; - if (!peel_ref(refname, peeled)) - packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons); + if (!peel_ref(refname, peeled.hash)) + packet_write(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); return 0; } -- cgit v1.2.3