Skip to content

Commit 6b59f51

Browse files
npitregitster
authored andcommitted
give priority to progress messages
In theory it is possible for sideband channel #2 to be delayed if pack data is quick to come up for sideband channel #1. And because data for channel #2 is read only 128 bytes at a time while pack data is read 8192 bytes at a time, it is possible for many pack blocks to be sent to the client before the progress message fifo is emptied, making the situation even worse. This would result in totally garbled progress display on the client's console as local progress gets mixed with partial remote progress lines. Let's prevent such situations by giving transmission priority to progress messages over pack data at all times. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b19fa4 commit 6b59f51

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

builtin-upload-archive.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
132132

133133
while (1) {
134134
struct pollfd pfd[2];
135-
ssize_t processed[2] = { 0, 0 };
136135
int status;
137136

138137
pfd[0].fd = fd1[0];
@@ -147,15 +146,14 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
147146
}
148147
continue;
149148
}
150-
if (pfd[0].revents & POLLIN)
151-
/* Data stream ready */
152-
processed[0] = process_input(pfd[0].fd, 1);
153149
if (pfd[1].revents & POLLIN)
154150
/* Status stream ready */
155-
processed[1] = process_input(pfd[1].fd, 2);
156-
/* Always finish to read data when available */
157-
if (processed[0] || processed[1])
158-
continue;
151+
if (process_input(pfd[1].fd, 2))
152+
continue;
153+
if (pfd[0].revents & POLLIN)
154+
/* Data stream ready */
155+
if (process_input(pfd[0].fd, 1))
156+
continue;
159157

160158
if (waitpid(writer, &status, 0) < 0)
161159
error_clnt("%s", lostchild);

upload-pack.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,23 @@ static void create_pack_file(void)
218218
}
219219
continue;
220220
}
221+
if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
222+
/* Status ready; we ship that in the side-band
223+
* or dump to the standard error.
224+
*/
225+
sz = xread(pack_objects.err, progress,
226+
sizeof(progress));
227+
if (0 < sz)
228+
send_client_data(2, progress, sz);
229+
else if (sz == 0) {
230+
close(pack_objects.err);
231+
pack_objects.err = -1;
232+
}
233+
else
234+
goto fail;
235+
/* give priority to status messages */
236+
continue;
237+
}
221238
if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
222239
/* Data ready; we keep the last byte to ourselves
223240
* in case we detect broken rev-list, so that we
@@ -255,21 +272,6 @@ static void create_pack_file(void)
255272
if (sz < 0)
256273
goto fail;
257274
}
258-
if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
259-
/* Status ready; we ship that in the side-band
260-
* or dump to the standard error.
261-
*/
262-
sz = xread(pack_objects.err, progress,
263-
sizeof(progress));
264-
if (0 < sz)
265-
send_client_data(2, progress, sz);
266-
else if (sz == 0) {
267-
close(pack_objects.err);
268-
pack_objects.err = -1;
269-
}
270-
else
271-
goto fail;
272-
}
273275
}
274276

275277
if (finish_command(&pack_objects)) {

0 commit comments

Comments
 (0)