connect: have ref processing code take struct packet_reader
In a future patch, we'll want to access multiple members from struct packet_reader when parsing references. Therefore, have the ref parsing code take pointers to struct reader instead of having to pass multiple arguments to each function. Rename the len variable to "linelen" to make it clearer what the variable does in light of the variable change. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 25, 2020 at 19:58 UTC
92315e50b275deee8e84d28ee1ff1ad555a5de36
1 file changed
+16
-11
connect.c
+16
-11
@@ -204,17 +204,19 @@ static void annotate_refs_with_symref_info(struct ref *ref)
204
string_list_clear(&symref, 0);
205
}
206
207
-static void process_capabilities(const char *line, int *len)
207
+static void process_capabilities(struct packet_reader *reader, int *linelen)
208
{
209
+ const char *line = reader->line;
210
int nul_location = strlen(line);
210
- if (nul_location == *len)
211
+ if (nul_location == *linelen)
212
return;
213
server_capabilities_v1 = xstrdup(line + nul_location + 1);
213
- *len = nul_location;
214
+ *linelen = nul_location;
215
}
216
216
-static int process_dummy_ref(const char *line)
217
+static int process_dummy_ref(const struct packet_reader *reader)
218
{
219
+ const char *line = reader->line;
220
struct object_id oid;
221
const char *name;
222
@@ -234,9 +236,11 @@ static void check_no_capabilities(const char *line, int len)
236
line + strlen(line));
237
}
238
237
-static int process_ref(const char *line, int len, struct ref ***list,
238
- unsigned int flags, struct oid_array *extra_have)
239
+static int process_ref(const struct packet_reader *reader, int len,
240
+ struct ref ***list, unsigned int flags,
241
+ struct oid_array *extra_have)
242
{
243
+ const char *line = reader->line;
244
struct object_id old_oid;
245
const char *name;
246
@@ -260,9 +264,10 @@ static int process_ref(const char *line, int len, struct ref ***list,
264
return 1;
265
}
266
263
-static int process_shallow(const char *line, int len,
267
+static int process_shallow(const struct packet_reader *reader, int len,
268
struct oid_array *shallow_points)
269
{
270
+ const char *line = reader->line;
271
const char *arg;
272
struct object_id old_oid;
273
@@ -315,20 +320,20 @@ struct ref **get_remote_heads(struct packet_reader *reader,
320
321
switch (state) {
322
case EXPECTING_FIRST_REF:
318
- process_capabilities(reader->line, &len);
319
- if (process_dummy_ref(reader->line)) {
323
+ process_capabilities(reader, &len);
324
+ if (process_dummy_ref(reader)) {
325
state = EXPECTING_SHALLOW;
326
break;
327
}
328
state = EXPECTING_REF;
329
/* fallthrough */
330
case EXPECTING_REF:
326
- if (process_ref(reader->line, len, &list, flags, extra_have))
331
+ if (process_ref(reader, len, &list, flags, extra_have))
332
break;
333
state = EXPECTING_SHALLOW;
334
/* fallthrough */
335
case EXPECTING_SHALLOW:
331
- if (process_shallow(reader->line, len, shallow_points))
336
+ if (process_shallow(reader, len, shallow_points))
337
break;
338
die(_("protocol error: unexpected '%s'"), reader->line);
339
case EXPECTING_DONE: