From: Michael Haggerty <mhagger@xxxxxxxxxxxx> 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 <mhagger@xxxxxxxxxxxx> --- builtin/receive-pack.c | 42 ++++++++++++++++++------------------------ 1 files changed, 18 insertions(+), 24 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d2dcb7e..08df17e 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -144,12 +144,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 { @@ -869,25 +887,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; @@ -937,12 +936,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; -- 1.7.8.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html