got-read-patch: rename `ok' variable and simplify the parsing a bit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/libexec/got-read-patch/got-read-patch.c b/libexec/got-read-patch/got-read-patch.c
index f4119fe..f52ad65 100644
--- a/libexec/got-read-patch/got-read-patch.c
+++ b/libexec/got-read-patch/got-read-patch.c
@@ -219,13 +219,12 @@ strtolnum(char **str, long *n)
}
static const struct got_error *
-parse_hdr(char *s, int *ok, struct got_imsg_patch_hunk *hdr)
+parse_hdr(char *s, int *done, struct got_imsg_patch_hunk *hdr)
{
static const struct got_error *err = NULL;
- *ok = 1;
if (strncmp(s, "@@ -", 4)) {
- *ok = 0;
+ *done = 1;
return NULL;
}
@@ -333,7 +332,7 @@ peek_special_line(FILE *fp)
}
static const struct got_error *
-parse_hunk(FILE *fp, int *ok)
+parse_hunk(FILE *fp, int *done)
{
static const struct got_error *err = NULL;
struct got_imsg_patch_hunk hdr;
@@ -344,14 +343,14 @@ parse_hunk(FILE *fp, int *ok)
linelen = getline(&line, &linesize, fp);
if (linelen == -1) {
- *ok = 0;
+ *done = 1;
goto done;
}
- err = parse_hdr(line, ok, &hdr);
+ err = parse_hdr(line, done, &hdr);
if (err)
goto done;
- if (!*ok) {
+ if (*done) {
if (fseek(fp, linelen * -1, SEEK_CUR) == -1)
err = got_error_from_errno("fseek");
goto done;
@@ -370,7 +369,7 @@ parse_hunk(FILE *fp, int *ok)
/* trailing newlines may be chopped */
if (leftold < 3 && leftnew < 3) {
- *ok = 0;
+ *done = 1;
break;
}
@@ -440,25 +439,23 @@ read_patch(struct imsgbuf *ibuf, int fd)
}
while (!feof(fp)) {
- int empty = 0, ok = 1;
+ int done = 0;
- err = find_patch(&empty, fp);
+ err = find_patch(&done, fp);
if (err)
goto done;
patch_found = 1;
- for (;;) {
- if (!empty)
- err = parse_hunk(fp, &ok);
+
+ while (!done) {
+ err = parse_hunk(fp, &done);
if (err)
goto done;
- if (!ok || empty) {
- err = send_patch_done();
- if (err)
- goto done;
- break;
- }
}
+
+ err = send_patch_done();
+ if (err)
+ goto done;
}
done: