Skip to content

Commit 92315e5

Browse files
bk2204gitster
authored andcommitted
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>
1 parent b8615c3 commit 92315e5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

connect.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,19 @@ static void annotate_refs_with_symref_info(struct ref *ref)
204204
string_list_clear(&symref, 0);
205205
}
206206

207-
static void process_capabilities(const char *line, int *len)
207+
static void process_capabilities(struct packet_reader *reader, int *linelen)
208208
{
209+
const char *line = reader->line;
209210
int nul_location = strlen(line);
210-
if (nul_location == *len)
211+
if (nul_location == *linelen)
211212
return;
212213
server_capabilities_v1 = xstrdup(line + nul_location + 1);
213-
*len = nul_location;
214+
*linelen = nul_location;
214215
}
215216

216-
static int process_dummy_ref(const char *line)
217+
static int process_dummy_ref(const struct packet_reader *reader)
217218
{
219+
const char *line = reader->line;
218220
struct object_id oid;
219221
const char *name;
220222

@@ -234,9 +236,11 @@ static void check_no_capabilities(const char *line, int len)
234236
line + strlen(line));
235237
}
236238

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)
239242
{
243+
const char *line = reader->line;
240244
struct object_id old_oid;
241245
const char *name;
242246

@@ -260,9 +264,10 @@ static int process_ref(const char *line, int len, struct ref ***list,
260264
return 1;
261265
}
262266

263-
static int process_shallow(const char *line, int len,
267+
static int process_shallow(const struct packet_reader *reader, int len,
264268
struct oid_array *shallow_points)
265269
{
270+
const char *line = reader->line;
266271
const char *arg;
267272
struct object_id old_oid;
268273

@@ -315,20 +320,20 @@ struct ref **get_remote_heads(struct packet_reader *reader,
315320

316321
switch (state) {
317322
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)) {
320325
state = EXPECTING_SHALLOW;
321326
break;
322327
}
323328
state = EXPECTING_REF;
324329
/* fallthrough */
325330
case EXPECTING_REF:
326-
if (process_ref(reader->line, len, &list, flags, extra_have))
331+
if (process_ref(reader, len, &list, flags, extra_have))
327332
break;
328333
state = EXPECTING_SHALLOW;
329334
/* fallthrough */
330335
case EXPECTING_SHALLOW:
331-
if (process_shallow(reader->line, len, shallow_points))
336+
if (process_shallow(reader, len, shallow_points))
332337
break;
333338
die(_("protocol error: unexpected '%s'"), reader->line);
334339
case EXPECTING_DONE:

0 commit comments

Comments
 (0)