From: Michael Haggerty Date: Fri, 6 Jan 2012 14:12:31 +0000 (+0100) Subject: receive-pack: move more work into write_head_info() X-Git-Tag: v1.7.9-rc1~10^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b7a025d921e416a708eb2d664d9ff51b303edd97;p=git.git receive-pack: move more work into write_head_info() Move some more code from the calling site into write_head_info(), and inline add_alternate_refs() there. (Some more simplification is coming, and it is easier if all this code is in the same place.) Move some helper functions to avoid the need for forward declarations. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index b6d957cb0..43d161f81 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -143,12 +143,30 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo return show_ref(path, sha1, flag, cb_data); } +static void add_one_alternate_sha1(const unsigned char sha1[20], void *unused) +{ + add_extra_ref(".have", sha1, 0); +} + +static void collect_one_alternate_ref(const struct ref *ref, void *data) +{ + struct sha1_array *sa = data; + sha1_array_append(sa, ref->old_sha1); +} + static void write_head_info(void) { + struct sha1_array sa = SHA1_ARRAY_INIT; + for_each_alternate_ref(collect_one_alternate_ref, &sa); + sha1_array_for_each_unique(&sa, add_one_alternate_sha1, NULL); + sha1_array_clear(&sa); for_each_ref(show_ref_cb, NULL); if (!sent_capabilities) show_ref("capabilities^{}", null_sha1, 0, NULL); + clear_extra_refs(); + /* EOF */ + packet_flush(1); } struct command { @@ -870,25 +888,6 @@ static int delete_only(struct command *commands) return 1; } -static void add_one_alternate_sha1(const unsigned char sha1[20], void *unused) -{ - add_extra_ref(".have", sha1, 0); -} - -static void collect_one_alternate_ref(const struct ref *ref, void *data) -{ - struct sha1_array *sa = data; - sha1_array_append(sa, ref->old_sha1); -} - -static void add_alternate_refs(void) -{ - struct sha1_array sa = SHA1_ARRAY_INIT; - for_each_alternate_ref(collect_one_alternate_ref, &sa); - sha1_array_for_each_unique(&sa, add_one_alternate_sha1, NULL); - sha1_array_clear(&sa); -} - int cmd_receive_pack(int argc, const char **argv, const char *prefix) { int advertise_refs = 0; @@ -938,12 +937,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) unpack_limit = receive_unpack_limit; if (advertise_refs || !stateless_rpc) { - add_alternate_refs(); write_head_info(); - clear_extra_refs(); - - /* EOF */ - packet_flush(1); } if (advertise_refs) return 0;