The only difference is the send function pointer. This duplicated code should be unified. Additionally, the function has too many responsibilities (serialization dispatch + per-file sending + incremental logic).
Suggested Fix: Extract a shared helper function for per-file sending that accepts the send function as a parameter, eliminating the duplicated loop structure.
Severity: low
In src/client/client_send.c:128-181, the send_chunk function has three separate code paths with near-identical loops for sending individual files:
1. **Path A (chunk serialization, lines 129-144)**: Compresses/serializes the entire chunk and sends as one block
2. **Path B (sendfile, lines 145-161)**: Iterates over files using file_send_sendfile, with incremental check option
3. **Path C (single calls, lines 162-179)**: Iterates over files using file_send_single_calls, with incremental check option
Paths B and C have identical structure:
```c
for (int i = 0; i < chunk->element_count; i++) {
if (config->use_incremental) {
int rc = send_file_incremental(client, chunk->items[i], config, send_fn);
if (rc == 1) continue;
if (rc < 0) return -1;
} else {
if (!send_status(client->file_descriptor, STATUS_NEXT))
return -1;
if (!send_fn(...))
return -1;
}
}
```
The only difference is the send function pointer. This duplicated code should be unified. Additionally, the function has too many responsibilities (serialization dispatch + per-file sending + incremental logic).
Suggested Fix: Extract a shared helper function for per-file sending that accepts the send function as a parameter, eliminating the duplicated loop structure.
Severity: low
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
In src/client/client_send.c:128-181, the send_chunk function has three separate code paths with near-identical loops for sending individual files:
Paths B and C have identical structure:
The only difference is the send function pointer. This duplicated code should be unified. Additionally, the function has too many responsibilities (serialization dispatch + per-file sending + incremental logic).
Suggested Fix: Extract a shared helper function for per-file sending that accepts the send function as a parameter, eliminating the duplicated loop structure.
Severity: low