Skip to content

Commit b7a025d

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd73ecd commit b7a025d

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

builtin/receive-pack.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,30 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo
143143
return show_ref(path, sha1, flag, cb_data);
144144
}
145145

146+
static void add_one_alternate_sha1(const unsigned char sha1[20], void *unused)
147+
{
148+
add_extra_ref(".have", sha1, 0);
149+
}
150+
151+
static void collect_one_alternate_ref(const struct ref *ref, void *data)
152+
{
153+
struct sha1_array *sa = data;
154+
sha1_array_append(sa, ref->old_sha1);
155+
}
156+
146157
static void write_head_info(void)
147158
{
159+
struct sha1_array sa = SHA1_ARRAY_INIT;
160+
for_each_alternate_ref(collect_one_alternate_ref, &sa);
161+
sha1_array_for_each_unique(&sa, add_one_alternate_sha1, NULL);
162+
sha1_array_clear(&sa);
148163
for_each_ref(show_ref_cb, NULL);
149164
if (!sent_capabilities)
150165
show_ref("capabilities^{}", null_sha1, 0, NULL);
166+
clear_extra_refs();
151167

168+
/* EOF */
169+
packet_flush(1);
152170
}
153171

154172
struct command {
@@ -870,25 +888,6 @@ static int delete_only(struct command *commands)
870888
return 1;
871889
}
872890

873-
static void add_one_alternate_sha1(const unsigned char sha1[20], void *unused)
874-
{
875-
add_extra_ref(".have", sha1, 0);
876-
}
877-
878-
static void collect_one_alternate_ref(const struct ref *ref, void *data)
879-
{
880-
struct sha1_array *sa = data;
881-
sha1_array_append(sa, ref->old_sha1);
882-
}
883-
884-
static void add_alternate_refs(void)
885-
{
886-
struct sha1_array sa = SHA1_ARRAY_INIT;
887-
for_each_alternate_ref(collect_one_alternate_ref, &sa);
888-
sha1_array_for_each_unique(&sa, add_one_alternate_sha1, NULL);
889-
sha1_array_clear(&sa);
890-
}
891-
892891
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
893892
{
894893
int advertise_refs = 0;
@@ -938,12 +937,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
938937
unpack_limit = receive_unpack_limit;
939938

940939
if (advertise_refs || !stateless_rpc) {
941-
add_alternate_refs();
942940
write_head_info();
943-
clear_extra_refs();
944-
945-
/* EOF */
946-
packet_flush(1);
947941
}
948942
if (advertise_refs)
949943
return 0;

0 commit comments

Comments
 (0)