@matheusbsbs / matheus-bagliano / commits / ebf8ebcc56
Fork 0

upload-pack: use 'struct upload_pack_data' in upload_pack()

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's use 'struct upload_pack_data' in upload_pack(). This will make it possible in followup commits to remove a lot of static variables and local variables that have the same name and purpose as fields in 'struct upload_pack_data'. This will also make upload_pack() work in a more similar way as upload_pack_v2(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 15, 2020 at 12:04 UTC ebf8ebcc56d5f47c531bce0e6238244752d91888
1 file changed +17 -15
upload-pack.c
+17 -15
@@ -1144,18 +1144,17 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
1144 void upload_pack(struct upload_pack_options *options)
1145 {
1146 struct string_list symref = STRING_LIST_INIT_DUP;
1147 - struct object_array want_obj = OBJECT_ARRAY_INIT;
1147 struct packet_reader reader;
1149 - struct list_objects_filter_options filter_options;
1148 + struct upload_pack_data data;
1149
1150 stateless_rpc = options->stateless_rpc;
1151 timeout = options->timeout;
1152 daemon_mode = options->daemon_mode;
1153
1155 - memset(&filter_options, 0, sizeof(filter_options));
1156 -
1154 git_config(upload_pack_config, NULL);
1155
1156 + upload_pack_data_init(&data);
1157 +
1158 head_ref_namespaced(find_symref, &symref);
1159
1160 if (options->advertise_refs || !stateless_rpc) {
@@ -1169,21 +1168,24 @@ void upload_pack(struct upload_pack_options *options)
1168 for_each_namespaced_ref(check_ref, NULL);
1169 }
1170 string_list_clear(&symref, 1);
1172 - if (options->advertise_refs)
1173 - return;
1171
1175 - packet_reader_init(&reader, 0, NULL, 0,
1176 - PACKET_READ_CHOMP_NEWLINE |
1177 - PACKET_READ_DIE_ON_ERR_PACKET);
1172 + if (!options->advertise_refs) {
1173 + packet_reader_init(&reader, 0, NULL, 0,
1174 + PACKET_READ_CHOMP_NEWLINE |
1175 + PACKET_READ_DIE_ON_ERR_PACKET);
1176
1179 - receive_needs(&reader, &want_obj, &filter_options);
1180 - if (want_obj.nr) {
1181 - struct object_array have_obj = OBJECT_ARRAY_INIT;
1182 - get_common_commits(&reader, &have_obj, &want_obj);
1183 - create_pack_file(&have_obj, &want_obj, &filter_options);
1177 + receive_needs(&reader, &data.want_obj, &data.filter_options);
1178 + if (data.want_obj.nr) {
1179 + get_common_commits(&reader,
1180 + &data.have_obj,
1181 + &data.want_obj);
1182 + create_pack_file(&data.have_obj,
1183 + &data.want_obj,
1184 + &data.filter_options);
1185 + }
1186 }
1187
1186 - list_objects_filter_release(&filter_options);
1188 + upload_pack_data_clear(&data);
1189 }
1190
1191 static int parse_want(struct packet_writer *writer, const char *line,