Comments
Patch
@@ -26,34 +26,46 @@
char *comm[] = {"import", "-", NULL};
char buff[BUFF_SIZE];
int exitcode = 0;
- int fd, ns;
+ int exit = 0;
+ int fd, n, length;
+ hg_header *header;
fd = open(import_patch, O_RDONLY);
if (fd < 0) {
printf("The '%s' file couldn't be open\n", import_patch);
return 1;
}
+
hg_rawcommand(handle, comm);
- hg_header *head;
- while (head = hg_read_header(handle), head != NULL &&
- head->channel != r) {
- if (head->channel == o) {
- if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) {
+ while (!exit) {
+ header = hg_read_header(handle);
+ switch (header->channel) {
+ case o:
+ case e:
+ while (n = hg_rawread(handle, buff, BUFF_SIZE), n > 0)
printf("%s", buff);
- }
- } else if (head->channel == e) {
- if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) {
- printf("error data: %s", buff);
- }
- } else if (head->channel == L || head->channel == I) {
- int length = read(fd, buff, head->length);
+ break;
+ case I:
+ case L:
+ /* length = 0 sent by the client
+ * is interpreted as EOF by the server.
+ * So this case works also to end
+ * the input session.
+ */
+ length = read(fd, buff, header->length);
hg_rawwrite(handle, buff, length);
+ break;
+ case r:
+ exitcode = hg_exitcode(handle);
+ printf("exitcode = %d \n", exitcode);
+ exit = 1;
+ break;
+ case unknown_channel:
+ break;
}
}
- exitcode = hg_exitcode(handle);
- printf("exitcode = %d \n", exitcode);
return exitcode;
}