Skip to content

Commit d9af228

Browse files
committed
Merge branch 'mh/ref-api-less-extra-refs'
* mh/ref-api-less-extra-refs: write_head_info(): handle "extra refs" locally show_ref(): remove unused "flag" and "cb_data" arguments receive-pack: move more work into write_head_info()
2 parents 242ff87 + 85f2510 commit d9af228

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

builtin/receive-pack.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
115115
return git_default_config(var, value, cb);
116116
}
117117

118-
static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
118+
static void show_ref(const char *path, const unsigned char *sha1)
119119
{
120120
if (sent_capabilities)
121121
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
@@ -125,10 +125,9 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void
125125
" report-status delete-refs side-band-64k",
126126
prefer_ofs_delta ? " ofs-delta" : "");
127127
sent_capabilities = 1;
128-
return 0;
129128
}
130129

131-
static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *cb_data)
130+
static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)
132131
{
133132
path = strip_namespace(path);
134133
/*
@@ -141,15 +140,33 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo
141140
*/
142141
if (!path)
143142
path = ".have";
144-
return show_ref(path, sha1, flag, cb_data);
143+
show_ref(path, sha1);
144+
return 0;
145+
}
146+
147+
static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
148+
{
149+
show_ref(".have", sha1);
150+
}
151+
152+
static void collect_one_alternate_ref(const struct ref *ref, void *data)
153+
{
154+
struct sha1_array *sa = data;
155+
sha1_array_append(sa, ref->old_sha1);
145156
}
146157

147158
static void write_head_info(void)
148159
{
160+
struct sha1_array sa = SHA1_ARRAY_INIT;
161+
for_each_alternate_ref(collect_one_alternate_ref, &sa);
162+
sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
163+
sha1_array_clear(&sa);
149164
for_each_ref(show_ref_cb, NULL);
150165
if (!sent_capabilities)
151-
show_ref("capabilities^{}", null_sha1, 0, NULL);
166+
show_ref("capabilities^{}", null_sha1);
152167

168+
/* EOF */
169+
packet_flush(1);
153170
}
154171

155172
struct command {
@@ -869,25 +886,6 @@ static int delete_only(struct command *commands)
869886
return 1;
870887
}
871888

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

939937
if (advertise_refs || !stateless_rpc) {
940-
add_alternate_refs();
941938
write_head_info();
942-
clear_extra_refs();
943-
944-
/* EOF */
945-
packet_flush(1);
946939
}
947940
if (advertise_refs)
948941
return 0;

0 commit comments

Comments
 (0)